STE-Industries: utilities testing
Mutex.cpp
Go to the documentation of this file.
1 
14 # include "Graphic.h"
15 # include "SystemException.h"
16 # include "Mutex.h"
17 
18 namespace GraphicSpace
19 {
20 
30 
31 Mutex::Mutex(void) noexcept: Active(false), MutexData()
32  {
33  }
34 
45 
46 Mutex::~Mutex(void) noexcept(false)
47  {
48  if (Active)
49  Finalize();
50  }
51 
66 
67 void Mutex::Initialize(void) noexcept(false)
68  {
69  if (Active)
72  if (pthread_mutex_init(&MutexData, nullptr) != MUTEX_INIT_OK)
75  Active = true;
76  }
77 
92 
93 void Mutex::Finalize(void) noexcept(false)
94  {
95  if (not Active)
98  if (pthread_mutex_destroy(&MutexData) != MUTEX_DESTROY_OK)
101  Active = false;
102  }
103 
117 
118 void Mutex::Lock(void) noexcept(false)
119  {
120  if (not Active)
123  if (pthread_mutex_lock(&MutexData) != MUTEX_LOCK_OK)
125  }
126 
141 
142 void Mutex::Unlock(void) noexcept(false)
143  {
144  if (not Active)
147  if (pthread_mutex_unlock(&MutexData) != MUTEX_UNLOCK_OK)
149  }
150 
151 }
GraphicSpace::SystemException
Definition: SystemException.h:72
GraphicSpace::SystemExceptionType::MUTEX_LOCK_FAILED
@ MUTEX_LOCK_FAILED
GraphicSpace::SystemExceptionType::MUTEX_DESTROY_FAILED
@ MUTEX_DESTROY_FAILED
Graphic.h
GraphicSpace::SystemExceptionType::INVALID_MUTEX_OPERATION
@ INVALID_MUTEX_OPERATION
GraphicSpace::SystemExceptionType::MUTEX_UNLOCK_FAILED
@ MUTEX_UNLOCK_FAILED
GraphicSpace::Mutex::Unlock
void Unlock(void) noexcept(false)
Definition: Mutex.cpp:142
GraphicSpace::Mutex::~Mutex
~Mutex(void) noexcept(false)
Definition: Mutex.cpp:46
GraphicSpace::Mutex::Mutex
Mutex(void) noexcept
Definition: Mutex.cpp:31
GraphicSpace::Mutex::Initialize
void Initialize(void) noexcept(false)
Definition: Mutex.cpp:67
GraphicSpace::SystemExceptionType
SystemExceptionType
Definition: SystemException.h:34
Mutex.h
SystemException.h
GraphicSpace::Mutex::Lock
void Lock(void) noexcept(false)
Definition: Mutex.cpp:118
GraphicSpace
Definition: Bitmap.cpp:29
GraphicSpace::Mutex::Finalize
void Finalize(void) noexcept(false)
Definition: Mutex.cpp:93
GraphicSpace::SystemExceptionType::MUTEX_INITIALIZATION_FAILED
@ MUTEX_INITIALIZATION_FAILED