<commit_before>//
// Copyright (C) 2004-2006 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2004-2006 Pingtel Corp.  All rights reserved.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// Copyright (C) 2007 <NAME>
// Licensed under the LGPL license.
// $$
///////////////////////////////////////////////////////////////////////////////

#ifndef OsPtrLock_h__
#define OsPtrLock_h__

// SYSTEM INCLUDES
// APPLICATION INCLUDES
#include <os/OsSyncBase.h>

// DEFINES
// MACROS
// EXTERNAL FUNCTIONS
// CONSTANTS
// STRUCTS
// TYPEDEFS
// MACROS
// FORWARD DECLARATIONS

/**
 * OsPtrLock is a locking container of any pointer type. Doesn't delete the stored pointer.
 * T must inherit from OsSyncBase.
 */
template <class T>
class OsPtrLock
{
   /* //////////////////////////// PUBLIC //////////////////////////////////// */
public:
   /* ============================ CREATORS ================================== */
   // make friend with self, to allow access to private members of different templates of OsPtrLock
   friend class OsPtrLock;

   /**
    * Constructor accepting an optional default value.
    */
   OsPtrLock(T* pValue = NULL)
      : m_pValue(pValue)
   {
      superclassCheck();
      acquire();
   }

   /**
    * Destructor
    */
   virtual ~OsPtrLock()
   {
      release();
      m_pValue = NULL;
   }

   /**
    * Copy constructor for assigning instance of OsPtrLock. Copies the pointer
    * stored in OsPtrLock, and locks it again.
    */
   OsPtrLock(const OsPtrLock<T>& rhs)
   {
      superclassCheck();
      m_pValue = rhs.m_pValue;
      acquire();
   }

   /* ============================ MANIPULATORS ============================== */

   /** 
   * Assignment operator for assigning instance of OsPtrLock into OsPtrLock.
   * Locks the assigned object. Object will get unlocked during destruction or
   * another assignment.
   */
   template <class Y>
   OsPtrLock<T>& operator=(const OsPtrLock<Y>& rhs)
   {
      if ((void*)&rhs == (void*)this)
      {
         // when self assignment do not lock or unlock anything
         return *this;
      }
<commit_msg>Fixing problem with OsPtrLock being friend with itself.<commit_after>//
// Copyright (C) 2004-2006 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2004-2006 Pingtel Corp.  All rights reserved.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// Copyright (C) 2007 <NAME>
// Licensed under the LGPL license.
// $$
///////////////////////////////////////////////////////////////////////////////

#ifndef OsPtrLock_h__
#define OsPtrLock_h__

// SYSTEM INCLUDES
// APPLICATION INCLUDES
#include <os/OsSyncBase.h>

// DEFINES
// MACROS
// EXTERNAL FUNCTIONS
// CONSTANTS
// STRUCTS
// TYPEDEFS
// MACROS
// FORWARD DECLARATIONS

/**
 * OsPtrLock is a locking container of any pointer type. Doesn't delete the stored pointer.
 * T must inherit from OsSyncBase.
 */
template <class T>
class OsPtrLock
{
   /* //////////////////////////// PUBLIC //////////////////////////////////// */
public:
   /* ============================ CREATORS ================================== */

   /**
    * Constructor accepting an optional default value.
    */
   OsPtrLock(T* pValue = NULL)
      : m_pValue(pValue)
   {
      superclassCheck();
      acquire();
   }

   /**
    * Destructor
    */
   virtual ~OsPtrLock()
   {
      release();
      m_pValue = NULL;
   }

   /**
    * Copy constructor for assigning instance of OsPtrLock. Copies the pointer
    * stored in OsPtrLock, and locks it again.
    */
   OsPtrLock(const OsPtrLock<T>& rhs)
   {
      superclassCheck();
      m_pValue = rhs.m_pValue;
      acquire();
   }

   /* ============================ MANIPULATORS ============================== */

   /** 
   * Assignment operator for assigning instance of OsPtrLock into OsPtrLock.
   * Locks the assigned object. Object will get unlocked during destruction or
   * another assignment.
   */
   OsPtrLock<T>& operator=(const OsPtrLock<T>& rhs)
   {
      if ((void*)&rhs == (void*)this)
      {
         // when self assignment do not lock or unlock anything
         return *this;
      }

{'fraction_non_alphanumeric': 0.22139957009792213, 'fraction_numerical': 0.009553379508000955, 'mean_word_length': 2.1300448430493275, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4132751', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1178, 'n_words': 362}