logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

ost::Mutex - The Mutex class is used to protect a section of code so that at any given time only a single

Author

       Generated automatically by Doxygen for GNU CommonC++ from the source code.

GNU CommonC++                                    Sun Dec 27 2020                                   ost::Mutex(3)

Constructor & Destructor Documentation

ost::Mutex::Mutex(constchar*name=NULL)
       The mutex is always initialized as a recursive entity.

       Parametersname of mutex for optional deadlock detection

   virtualost::Mutex::~Mutex()[virtual]
       Destroying the mutex removes any system resources associated with it. If a mutex lock is currently in
       place, it is presumed to terminate when the Mutex is destroyed.

Detailed Description

       The Mutex class is used to protect a section of code so that at any given time only a single thread can
       perform the protected operation.

       The Mutex can be used as a base class to protect access in a derived class. When used in this manner, the
       ENTER_CRITICAL and LEAVE_CRITICAL macros can be used to specify when code written for the derived class
       needs to be protected by the default Mutex of the derived class, and hence is presumed to be 'thread
       safe' from multiple instance execution. One of the most basic Common C++ synchronization object is the
       Mutex class. A Mutex only allows one thread to continue execution at a given time over a specific section
       of code. Mutex's have a enter and leave method; only one thread can continue from the Enter until the
       Leave is called. The next thread waiting can then get through. Mutex's are also known as 'CRITICAL
       SECTIONS' in win32-speak.

       The Mutex is always recursive in that if the same thread invokes the same mutex lock multiple times, it
       must release it multiple times. This allows a function to call another function which also happens to use
       the same mutex lock when called directly. This was deemed essential because a mutex might be used to
       block individual file requests in say, a database, but the same mutex might be needed to block a whole
       series of database updates that compose a 'transaction' for one thread to complete together without
       having to write alternate non-locking member functions to invoke for each part of a transaction.

       Strangely enough, the original pthread draft standard does not directly support recursive mutexes. In
       fact this is the most common 'NP' extension for most pthread implementations. Common C++ emulates
       recursive mutex behavior when the target platform does not directly support it.

       In addition to the Mutex, Common C++ supports a rwlock class. This implements the X/Open recommended
       'rwlock'. On systems which do not support rwlock's, the behavior is emulated with a Mutex; however, the
       advantage of a rwlock over a mutex is then entirely lost. There has been some suggested clever hacks for
       'emulating' the behavior of a rwlock with a pair of mutexes and a semaphore, and one of these will be
       adapted for Common C++ in the future for platforms that do not support rwlock's directly.

       Author
           David Sugar dyfet@ostel.comMutex lock for protected access.

       Examplestcpservice.cpp, and tcpthread.cpp.

Member Function Documentation

voidost::Mutex::enter(void)[inline]
       Future abi will use enter/leave/test members.

   voidost::Mutex::enterMutex(void)
       Entering a Mutex locks the mutex for the current thread. This also can be done using the ENTER_CRITICAL
       macro or by using the ++ operator on a mutex.

       SeealsoleaveMutex

       Referenced by ost::SysTime::lock(), and ost::MutexLock::MutexLock().

   voidost::Mutex::leave(void)[inline]
       Future abi will use enter/leave/test members.

   voidost::Mutex::leaveMutex(void)
       Leaving a mutex frees that mutex for use by another thread. If the mutex has been entered (invoked)
       multiple times (recursivily) by the same thread, then it will need to be exited the same number of
       instances before it is free for re-use. This operation can also be done using the LEAVE_CRITICAL macro or
       by the -- operator on a mutex.

       SeealsoenterMutex

       Referenced by ost::SysTime::unlock(), and ost::MutexLock::~MutexLock().

   voidost::Mutex::nameMutex(constchar*name)[inline]
       Enable setting of mutex name for deadlock debug.

       Parametersname for mutex.

   staticvoidost::Mutex::setDebug(boolmode)[inline],[static]
       Enable or disable deadlock debugging.

       Parametersmode debug mode.

   boolost::Mutex::test(void)[inline]
       Future abi will use enter/leave/test members.

       Returns
           true if entered.

   boolost::Mutex::tryEnterMutex(void)
       Tries to lock the mutex for the current thread. Behaves like enterMutex , except that it doesn't block
       the calling thread if the mutex is already locked by another thread.

       Returns
           true if locking the mutex was succesful otherwise false

       SeealsoenterMutexleaveMutex

Name

       ost::Mutex - The Mutex class is used to protect a section of code so that at any given time only a single
       thread can perform the protected operation.

Synopsis

       #include <thread.h>

       Inherited by ost::MapTable, ost::MutexCounter, ost::RandomFile [protected], ost::Runlist,
       ost::SerialService [private], ost::SharedMemPager, ost::SocketService [private], and ost::ThreadQueue.

   PublicMemberFunctionsMutex (const char *name=NULL)
           The mutex is always initialized as a recursive entity.
       virtual ~Mutex ()
           Destroying the mutex removes any system resources associated with it.
       void nameMutex (const char *name)
           Enable setting of mutex name for deadlock debug.
       void enterMutex (void)
           Entering a Mutex locks the mutex for the current thread.
       void enter (void)
           Future abi will use enter/leave/test members.
       void leave (void)
           Future abi will use enter/leave/test members.
       bool test (void)
           Future abi will use enter/leave/test members.
       bool tryEnterMutex (void)
           Tries to lock the mutex for the current thread.
       void leaveMutex (void)
           Leaving a mutex frees that mutex for use by another thread.

   StaticPublicMemberFunctions
       static void setDebug (bool mode)
           Enable or disable deadlock debugging.

See Also