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

#include <Thread.h>

Public Member Functions

 Mutex ()
 ~Mutex ()
void lock ()
bool tryLock ()
void unlock ()

Detailed Description

Definition at line 263 of file Thread.h.

Constructor & Destructor Documentation

◆ Mutex()

Thread::Mutex::Mutex ( )

Definition at line 429 of file Thread.cpp.

430{
431#if __DCL_PTHREAD
432 __DCL_VERIFY(pthread_mutex_init(&__mutex, NULL) == 0);
433#elif __DCL_WINDOWS
434 InitializeCriticalSection(&__cs);
435#endif
436}
#define NULL
Definition Config.h:340
#define __DCL_VERIFY(expr)
Definition Object.h:373

◆ ~Mutex()

Thread::Mutex::~Mutex ( )

Definition at line 438 of file Thread.cpp.

439{
440#if __DCL_PTHREAD
441 __DCL_VERIFY(pthread_mutex_destroy(&__mutex) == 0);
442#elif __DCL_WINDOWS
443 DeleteCriticalSection(&__cs);
444#endif
445}

Member Function Documentation

◆ lock()

void Thread::Mutex::lock ( )

Definition at line 447 of file Thread.cpp.

448{
449#if __DCL_PTHREAD
450 __DCL_VERIFY(pthread_mutex_lock(&__mutex) == 0);
451#elif __DCL_WINDOWS
452 EnterCriticalSection(&__cs);
453#endif
454}

◆ tryLock()

bool Thread::Mutex::tryLock ( )

Definition at line 456 of file Thread.cpp.

457{
458#if __DCL_PTHREAD
459 int r = pthread_mutex_trylock(&__mutex);
460 __DCL_ASSERT(r != EINVAL);
461
462 __DCL_ASSERT(r == 0 || r == EBUSY);
463 return r == 0;
464#elif __DCL_WINDOWS
465 return TryEnterCriticalSection(&__cs) == TRUE;
466#endif
467}
#define TRUE
#define __DCL_ASSERT(expr)
Definition Object.h:371
ByteString r

◆ unlock()

void Thread::Mutex::unlock ( )

Definition at line 469 of file Thread.cpp.

470{
471#if __DCL_PTHREAD
472 __DCL_VERIFY(pthread_mutex_unlock(&__mutex) == 0);
473#elif __DCL_WINDOWS
474 LeaveCriticalSection(&__cs);
475#endif
476}

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