DCL 3.7.4
Loading...
Searching...
No Matches
Thread::Mutex Class Reference

#include <Thread.h>

Public Member Functions

 Mutex ()
 ~Mutex ()
void lock ()
bool tryLock ()
void unlock ()
thread_t locker () const

Detailed Description

Definition at line 271 of file Thread.h.

Constructor & Destructor Documentation

◆ Mutex()

Thread::Mutex::Mutex ( )

Definition at line 453 of file Thread.cpp.

454{
455 __locker = 0;
456#if __DCL_PTHREAD
457 __DCL_VERIFY(pthread_mutex_init(&__mutex, NULL) == 0);
458#elif defined(__WINNT__)
459 InitializeCriticalSection(&__cs);
460#endif
461}
#define NULL
Definition Config.h:312
#define __DCL_VERIFY(expr)
Definition Object.h:396

◆ ~Mutex()

Thread::Mutex::~Mutex ( )

Definition at line 463 of file Thread.cpp.

464{
465#if __DCL_PTHREAD
466 __DCL_VERIFY(pthread_mutex_destroy(&__mutex) == 0);
467#elif defined(__WINNT__)
468 DeleteCriticalSection(&__cs);
469#endif
470}

Member Function Documentation

◆ lock()

void Thread::Mutex::lock ( )

Definition at line 472 of file Thread.cpp.

473{
474#if __DCL_PTHREAD
475 __DCL_VERIFY(pthread_mutex_lock(&__mutex) == 0);
476#elif defined(__WINNT__)
477 EnterCriticalSection(&__cs);
478#endif
479 __locker = Thread::self();
480}
static thread_t self()
Definition Thread.cpp:175

◆ locker()

thread_t Thread::Mutex::locker ( ) const
inline

Definition at line 291 of file Thread.h.

291 {
292 return __locker;
293 }

◆ tryLock()

bool Thread::Mutex::tryLock ( )

Definition at line 482 of file Thread.cpp.

483{
484 bool r = false;
485#if __DCL_PTHREAD
486 int r_ = pthread_mutex_trylock(&__mutex);
487 __DCL_ASSERT(r_ != EINVAL);
488 __DCL_ASSERT(r_ == 0 || r_ == EBUSY);
489 r = r_ == 0;
490#elif defined(__WINNT__)
491 r = TryEnterCriticalSection(&__cs) == TRUE;
492#endif
493 if (r) {
494 __locker = Thread::self();
495 }
496 return r;
497}
#define TRUE
IOException *size_t r
Definition MediaInfo.cpp:82
#define __DCL_ASSERT(expr)
Definition Object.h:394

◆ unlock()

void Thread::Mutex::unlock ( )

Definition at line 499 of file Thread.cpp.

500{
501 __DCL_ASSERT(__locker == Thread::self());
502 __locker = 0;
503#if __DCL_PTHREAD
504 __DCL_VERIFY(pthread_mutex_unlock(&__mutex) == 0);
505#elif defined(__WINNT__)
506 LeaveCriticalSection(&__cs);
507#endif
508}

The documentation for this class was generated from the following files: