/** * Copyright - See the COPYRIGHT that is included with this distribution. * pvAccessCPP is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. */ #ifndef REFERENCECOUNTINGLOCK_H #define REFERENCECOUNTINGLOCK_H #ifdef epicsExportSharedSymbols # define referenceCountingLockEpicsExportSharedSymbols # undef epicsExportSharedSymbols #endif #include #include #include #ifdef referenceCountingLockEpicsExportSharedSymbols # define epicsExportSharedSymbols # undef referenceCountingLockEpicsExportSharedSymbols #endif namespace epics { namespace pvAccess { /** * Reference counting mutex implementation w/ deadlock detection. * Synchronization helper class used (intended for use) for activation/deactivation synchronization. * This class enforces attempt method of acquiring the locks to prevent deadlocks. * Class also offers reference counting. * (NOTE: automatic lock counting was not implemented due to imperfect usage.) * */ class ReferenceCountingLock { public: POINTER_DEFINITIONS(ReferenceCountingLock); /** * Constructor of ReferenceCountingLock. * After construction lock is free and reference count equals 1. */ ReferenceCountingLock(); /** * Destructor of ReferenceCountingLock. */ virtual ~ReferenceCountingLock(); /** * Attempt to acquire lock. * * NOTE: Argument msecs is currently not supported due to * Darwin OS not supporting pthread_mutex_timedlock. May be changed in the future. * * @param msecs the number of milleseconds to wait. * An argument less than or equal to zero means not to wait at all. * * @return true if acquired, false otherwise. * NOTE: currently this routine always returns true. Look above for explanation. * */ bool acquire(epics::pvData::int64 msecs); /** * Release previously acquired lock. */ void release(); /** * Increment number of references. * * @return number of references. */ int increment(); /** * Decrement number of references. * * @return number of references. */ int decrement(); private: int _references; epics::pvData::Mutex _mutex; epics::pvData::Mutex _countMutex; }; }} #endif /* REFERENCECOUNTINGLOCK_H */