mutex_w32.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Platform Check
00010 *****************************************************************************/
00011 
00012 #include <ecl/config/ecl.hpp>
00013 #if defined(ECL_IS_WIN32)
00014 
00015 /*****************************************************************************
00016 ** Includes
00017 *****************************************************************************/
00018 
00019 #include <ecl/exceptions/standard_exception.hpp>
00020 #include "../../include/ecl/threads/mutex_w32.hpp"
00021 
00022 /*****************************************************************************
00023 ** Namespaces
00024 *****************************************************************************/
00025 
00026 namespace ecl {
00027 
00028 /*****************************************************************************
00029 * Mutex Class Methods
00030 *****************************************************************************/
00031 
00032 Mutex::Mutex(const bool locked) : number_locks(0)  {
00033 
00034         InitializeCriticalSection(&mutex); // has no return value
00035         if ( locked ) {
00036                 this->lock();
00037         }
00038 };
00039 
00040 Mutex::~Mutex() {
00041         DeleteCriticalSection(&mutex); // has no return value
00042 }
00043 
00044 void Mutex::lock() {
00045     ++number_locks;
00046     EnterCriticalSection(&mutex); // has no return value
00047 };
00048 
00049 bool Mutex::trylock(Duration &duration) {
00050         return trylock();
00051 };
00052 
00053 bool Mutex::trylock() {
00054         int result = TryEnterCriticalSection(&mutex);
00055         if ( result == 0 ) {
00056                 return false;
00057         } else {
00058                 ++number_locks;
00059                 return true;
00060         }
00061 };
00062 
00063 
00064 void Mutex::unlock()
00065 {
00066     --number_locks;
00067     LeaveCriticalSection( &mutex );
00068 };
00069 
00070 }; // namespace ecl
00071 
00072 #endif /* ECL_IS_WIN32 */


ecl_threads
Author(s): Daniel Stonier (d.stonier@gmail.com)
autogenerated on Thu Jan 2 2014 11:12:47