1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
12 #include <anna/core/mt/Mutex.hpp>
13 #include <anna/config/defines.hpp>
17 Mutex::Mutex(const Mutex::Mode::_v mode) {
20 if(mode == Mode::Recursive) {
21 pthread_mutexattr_t mattr;
22 pthread_mutexattr_init(&mattr);
23 pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE_NP); // PTHREAD_MUTEX_RECURSIVE in Solaris
24 pthread_mutex_init(&a_id, &mattr);
25 pthread_mutexattr_destroy(&mattr);
27 pthread_mutex_init(&a_id, NULL);
34 pthread_mutex_destroy(&a_id);
43 if((errorCode = pthread_mutex_lock(&a_id)) != 0)
44 throw RuntimeException(std::string("pthread_mutex_lock"), errorCode, ANNA_FILE_LOCATION);
55 if((errorCode = pthread_mutex_unlock(&a_id)) != 0)
56 throw RuntimeException(std::string("pthread_mutex_unlock"), errorCode, ANNA_FILE_LOCATION);
57 } catch(Exception& ex) {
70 if((errorCode = pthread_mutex_trylock(&a_id)) != 0) {
71 if(errorCode == EBUSY)
74 throw RuntimeException(std::string("pthread_mutex_trylock"), errorCode, ANNA_FILE_LOCATION);
76 } catch(Exception& ex) {