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 //
9 #include <anna/core/mt/Guard.hpp>
10 #include <anna/core/mt/Safe.hpp>
11 #include <anna/core/functions.hpp>
12 #include <anna/core/tracing/Logger.hpp>
17 #define trace_local7(method,object,file,line) \
18 if (Logger::isActive (Logger::Local7)) { \
19 string msg = (method); \
20 msg += " | Reference: "; \
21 if (a_whatis == NULL) \
22 msg += functions::asHexString (anna_ptrnumber_cast ((object))); \
25 msg += functions::asHexString (anna_ptrnumber_cast ((object))); \
29 Logger::write (Logger::Local7, msg, (file), (line)); \
32 Guard::Guard(const Safe* object) noexcept(false) :
35 throw RuntimeException("Can not lock NULL object", ANNA_FILE_LOCATION);
37 lock(a_safeObject = const_cast <Safe*>(object), NULL);
40 Guard::Guard(const Safe* object, const char* whatis) noexcept(false) :
43 throw RuntimeException("Can not lock NULL object", ANNA_FILE_LOCATION);
45 lock(a_safeObject = const_cast <Safe*>(object), whatis);
48 void Guard::deactivate()
50 if(a_safeObject == NULL)
53 a_safeObject->unlock();
54 trace_local7("Guard::deactivate", a_safeObject, __FILE__, __LINE__);
58 //--------------------------------------------------------------------------------------------------------------
59 // Solo sacmos trazas cuando nos mandan un 'whatis', de otro quedamos un bucle infinito porque el
60 // Logger::writer tambien usa una Guard.
61 //--------------------------------------------------------------------------------------------------------------
62 void Guard::lock(Safe* safe, const char* whatis)
64 trace_local7("Guard::lock", safe, __FILE__, __LINE__);