/* * adLoker.h * * Created on: 13. dec. 2012 * Author: Viacheslav Isaev */ #ifndef ADLOKER_H_ #define ADLOKER_H_ #include #define LOCK_ASYN_PORT(port) ad::Locker locker##__LINE__(port, __FILE__, __LINE__); #define UNLOCK_ASYN_PORT(port) ad::UnLocker unlocker##__LINE__(port, __FILE__, __LINE__); #define LOCK_MUTEX(mutex) ad::MutexLocker mlocker##__LINE__(mutex, __FILE__, __LINE__); namespace ad { /** Helper class which make sure that epicsMutex will be unlocked on exit from current scope (RAII). * * Constructor accepts mutex which will be locked immediately after the object is created. */ class MutexLocker { epicsMutex* _mutex; const std::string _file; int _line; public: /* Constructor * * @param mutex - instance of the epcisMutex to protect */ MutexLocker(epicsMutex* mutex); MutexLocker(epicsMutex* mutex, const std::string file, int line); ~MutexLocker(); }; /** Helper class which make sure that asynDriver will be unlocked on exit from current scope (RAII). * * Constructor accepts pointer on asynPortDriver which will be locked immediately after the object is created. */ class Locker { asynPortDriver *_obj; const std::string _file; int _line; public: /* Constructor * * @param obj - instance of the asynPortDriver to protect */ Locker( asynPortDriver *obj ); Locker( asynPortDriver *obj, const std::string file, int line); virtual ~Locker(); }; /** Helper class which make sure that asynDriver will be locked on exit from current scope (RAII). * * */ class UnLocker { asynPortDriver *_obj; const std::string _file; int _line; public: UnLocker( asynPortDriver *obj ); UnLocker( asynPortDriver *obj, const std::string file, int line); virtual ~UnLocker(); }; /* Helper class which make sure that callParamCallbacks are called after the exit from scope. * * Constructors accepts pointer on asynPortDriver */ class ParametersCallbackCaller { asynPortDriver* _obj; int _asynAddr; public: /* * * @param obj - instance of the asynPortDriver to protect * @param asynAddr - asynAddr to propogate changes * */ ParametersCallbackCaller(asynPortDriver* obj, int asynAddr): _obj(obj), _asynAddr(asynAddr) { } /* Destructor * */ ~ParametersCallbackCaller() { _obj->callParamCallbacks(_asynAddr); } }; } /* namespace ad */ #endif /* ADLOKER_H_ */