mutex_w32.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Platform Check
10 *****************************************************************************/
11 
12 #include <ecl/config/ecl.hpp>
13 #if defined(ECL_IS_WIN32)
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
20 #include "../../include/ecl/threads/mutex_w32.hpp"
21 
22 /*****************************************************************************
23 ** Namespaces
24 *****************************************************************************/
25 
26 namespace ecl {
27 
28 /*****************************************************************************
29 * Mutex Class Methods
30 *****************************************************************************/
31 
32 Mutex::Mutex(const bool locked) : number_locks(0) {
33  InitializeCriticalSection(&mutex); // has no return value
34  if ( locked ) {
35  this->lock();
36  }
37 }
38 
39 Mutex::~Mutex() {
40  DeleteCriticalSection(&mutex); // has no return value
41 }
42 
43 void Mutex::lock() {
44  InterlockedIncrement((long*)&number_locks);
45  EnterCriticalSection(&mutex); // has no return value
46 }
47 
48 bool Mutex::trylock(Duration &duration) {
49  return trylock();
50 }
51 
52 bool Mutex::trylock() {
53  if (number_locks > 0)
54  return false;
55  lock();
56  return true;
57 }
58 
59 void Mutex::unlock()
60 {
61  LeaveCriticalSection( &mutex );
62  InterlockedDecrement((long*)&number_locks);
63 }
64 
65 } // namespace ecl
66 
67 #endif /* ECL_IS_WIN32 */
mutex
ecl::Mutex mutex
Definition: examples/mutex.cpp:25
Duration
TimeStamp Duration
standard_exception.hpp
ecl
Embedded control libraries.


ecl_threads
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:43