Go to the documentation of this file. 1 #ifndef _TIMED_MUTEX_HPP_
2 #define _TIMED_MUTEX_HPP_ "$Id: timed_mutex.hpp 454 2020-07-23 20:22:23Z geoff $"
13 #define OME_MUTEX_TYPE CRITICAL_SECTION
14 #define OME_CONDITION_TYPE HANDLE
17 #define OME_MUTEX_TYPE pthread_mutex_t
18 #define OME_CONDITION_TYPE pthread_cond_t
34 #define _TOKEN_TO_STRING(x) #x
36 #define _EXPAND_TOKEN_TO_STRING(x) _TOKEN_TO_STRING(x)
37 #define THIS_FILE_AND_LINE(f,l) f ":" _EXPAND_TOKEN_TO_STRING(l)
39 #ifndef HIDE_TIMED_MUTEX_STATISTICS
40 #if BLDFLAG_optimized == 1
42 #define HIDE_TIMED_MUTEX_STATISTICS 1
44 #define HIDE_TIMED_MUTEX_STATISTICS 0
57 #if HIDE_TIMED_MUTEX_STATISTICS == 0
101 bool recursive=
false);
111 explicit TimedMutex(
const char *lockName=
nullptr,
113 bool recursive=
false);
131 #if HIDE_TIMED_MUTEX_STATISTICS == 0
132 if ((
statistics !=
nullptr) && (place !=
nullptr)) {
146 EnterCriticalSection(&
mutex);
148 pthread_mutex_lock(&
mutex);
171 LeaveCriticalSection(&
mutex);
173 pthread_mutex_unlock(&
mutex);
190 #if HIDE_TIMED_MUTEX_STATISTICS == 0
195 return (
"TimedMutex");
204 #if HIDE_TIMED_MUTEX_STATISTICS == 0
221 #if HIDE_TIMED_MUTEX_STATISTICS == 0
349 #if HIDE_TIMED_MUTEX_STATISTICS == 0
354 return (
"TimedCondition");
409 #define LOCK_HERE() lock(THIS_FILE_AND_LINE(__FILE__,__LINE__))
414 #define WAIT_HERE() waitForCondition(THIS_FILE_AND_LINE(__FILE__,__LINE__))
419 #define WAIT_HERE_UNTIL(timeout) waitForConditionOrUntil(timeout, THIS_FILE_AND_LINE(__FILE__,__LINE__))
int clock_gettime_via_tick(struct timespec *result, bool force) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3")
Definition: tick_time.h:290
OME_MUTEX_TYPE mutex
Definition: timed_mutex.hpp:87
const char * getName(uint_fast32_t *retNameLen=nullptr) const OME_ALWAYS_INLINE
Get variable name.
Definition: shared_variable.hpp:135
uint64_t obtainedAt
Definition: timed_mutex.hpp:86
TimedMutex(const char *lockName, SharedMemoryVariableNode *parentNode, bool recursive=false)
Implements generic mutex with performance counters.
Definition: timed_mutex.cpp:55
int64_t lock(const char *place=nullptr) OME_ALWAYS_INLINE
Convenience routine to lock the associated mutex.
Definition: timed_mutex.hpp:366
int64_t untimedUnlock() OME_ALWAYS_INLINE
Unlock the mutex, but maintain neither usage nor timing statistics.
Definition: timed_mutex.hpp:169
int64_t unlock()
Release a previously locked mutex.
Definition: timed_mutex.cpp:156
int64_t waitForConditionOrUntil(const struct timespec *timeout, const char *waitingHere=nullptr) NONNULL_CLASS_PARAMETERS(2)
Wait for the condition to be posted or until a specified point in time.
Definition: timed_mutex.cpp:309
uint64_t getThreadIdOfCurrentOwner() const OME_ALWAYS_INLINE
Return thread id of thread holding lock.
Definition: timed_mutex.hpp:203
~TimedMutex()
Definition: timed_mutex.cpp:108
SMV_StandaloneNumeric< uint64_t > totalDelayTicks
Definition: timed_mutex.hpp:60
SharedMemoryVariableNode namingNode
Definition: timed_mutex.hpp:58
~TimedMutexStatistics()
Definition: timed_mutex.hpp:81
int64_t unlock() OME_ALWAYS_INLINE
Convenience routine to release previously locked mutex associated with the condition variable.
Definition: timed_mutex.hpp:385
TimedConditionStatistics * statistics
Definition: timed_mutex.hpp:248
Intermediate naming node for supporting variable naming hierarchies.
Definition: shared_variable.hpp:318
SMV_StandaloneNumeric< uint64_t > lockHeldBy
Definition: timed_mutex.hpp:63
#define NONNULL_CLASS_PARAMETERS(...)
Mark a function as never returning a null pointer.
Definition: compiler_hints.h:337
TimedCondition(TimedMutex *m, const char *conditionName, SharedMemoryVariableNode *parentNode) NONNULL_CLASS_PARAMETERS(2)
Implements generic condition variable with performance counters.
Definition: timed_mutex.cpp:218
SMV_StandaloneNumeric< int32_t > waitsCompleted
Definition: timed_mutex.hpp:228
int postCondition()
Notify any sleeping threads that the condition has occurred.
Definition: timed_mutex.cpp:358
const char * getMutexName() const NONNULL_RETURN
Return name of mutex.
Definition: timed_mutex.hpp:189
int64_t lock(const char *place=nullptr) OME_ALWAYS_INLINE
Lock the mutex.
Definition: timed_mutex.hpp:129
int64_t untimedLock() OME_ALWAYS_INLINE
Convenience routine to lock the associated mutex, but maintain neither usage nor timing statistics.
Definition: timed_mutex.hpp:375
SMV_StandaloneNumeric< uint64_t > totalHeldTicks
Definition: timed_mutex.hpp:62
int64_t acquireLock()
Definition: timed_mutex.cpp:118
TimedMutexStatistics(const char *name, SharedMemoryVariableNode *parentNode)
Definition: timed_mutex.cpp:12
SMV_StandaloneString< 128 > waitLocation
Definition: timed_mutex.hpp:229
uint64_t startedAt
Definition: timed_mutex.hpp:249
SMV_StandaloneNumeric< int32_t > waitsStarted
Definition: timed_mutex.hpp:227
const char srcID[]
Definition: catSym.c:17
TimedMutexStatistics * statistics
Definition: timed_mutex.hpp:85
SharedMemoryVariableManager DEFAULT_sharedMemoryVariableManager
Default shared memory variable manager.
TimedConditionStatistics(const char *name, SharedMemoryVariableNode *parentNode)
Definition: timed_mutex.cpp:180
Statistics for a TimedMutex object.
Definition: timed_mutex.hpp:55
#define OME_MUTEX_TYPE
Definition: timed_mutex.hpp:17
#define OME_EXPECT_TRUE(expr)
Annotation macro for conditional expression expected to be true.
Definition: compiler_hints.h:541
TimedMutex * getMutex() const OME_ALWAYS_INLINE NONNULL_RETURN
Return address of mutex object associated with the condition variable.
Definition: timed_mutex.hpp:285
bool active
Definition: timed_mutex.hpp:252
SMV_StandaloneNumeric< uint64_t > lockRequestedAt
Definition: timed_mutex.hpp:59
Generic mutex implementation that supports timing statistics.
Definition: timed_mutex.hpp:51
bool isSleeping() const OME_ALWAYS_INLINE
Return a Boolean indication of whether or not a thread is sleeping.
Definition: timed_mutex.hpp:338
#define NULL
Definition: tmp.o.cpp:327
#define OME_CONDITION_TYPE
Definition: timed_mutex.hpp:18
~TimedCondition()
Definition: timed_mutex.cpp:262
#define PTHREAD_MUTEX_RECURSIVE
Definition: tmp.o.cpp:437
Generic condition variable for use with the TimedMutex class.
Definition: timed_mutex.hpp:216
~TimedConditionStatistics()
Definition: timed_mutex.hpp:243
FARGOS Shared Memory Variable routines.
const char srcID[] OME_USED
Definition: tick_time.cpp:24
int64_t untimedLock() OME_ALWAYS_INLINE
Lock the mutex, but maintain neither usage nor timing statistics.
Definition: timed_mutex.hpp:144
SMV_StandaloneNumeric< int32_t > locksWanted
Definition: timed_mutex.hpp:64
int64_t untimedUnlock() OME_ALWAYS_INLINE
Convenience routine to unlock the mutex associated with the condition variable, but maintain neither ...
Definition: timed_mutex.hpp:394
Manager for collection of shared memory variables.
Definition: shared_variable.hpp:193
Compiler-specific macros to provide performance-related hints.
OME_MUTEX_TYPE * mutex_address() OME_ALWAYS_INLINE NONNULL_RETURN
Get address of underlying native mutex.
Definition: timed_mutex.hpp:180
#define OME_ALWAYS_INLINE
Tell the compiler to alway inline a function, regardless of optimization level.
Definition: compiler_hints.h:364
SMV_StandaloneNumeric< int32_t > locksObtained
Definition: timed_mutex.hpp:65
const char * getConditionName() const NONNULL_RETURN
Return name of condition variable.
Definition: timed_mutex.hpp:348
uint64_t get_CPU_ticks() OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3")
Return value of CPU tick register.
Definition: tick_time.h:141
TimedMutex * mutex
Definition: timed_mutex.hpp:250
FARGOS CPU tick routines.
OME_CONDITION_TYPE condition
Definition: timed_mutex.hpp:251
int64_t waitForCondition(const char *waitingHere=nullptr)
Wait indefinitely for the condition to be posted.
Definition: timed_mutex.cpp:272
SMV_StandaloneNumeric< uint64_t > totalPostEvents
Definition: timed_mutex.hpp:226
SMV_StandaloneString< 128 > lockLocation
Definition: timed_mutex.hpp:66
OME_MUTEX_TYPE * mutex_address() OME_ALWAYS_INLINE NONNULL_RETURN
Convenience routine to get address of underlying native mutex that is associated with the condition v...
Definition: timed_mutex.hpp:401
OME_CONDITION_TYPE * condition_address() OME_ALWAYS_INLINE NONNULL_RETURN
Get address of underlying native condition variable.
Definition: timed_mutex.hpp:291
SharedMemoryVariableNode namingNode
Definition: timed_mutex.hpp:222
SMV_StandaloneNumeric< uint64_t > waitStartedAt
Definition: timed_mutex.hpp:223
SMV_StandaloneNumeric< uint64_t > waitCompletedAt
Definition: timed_mutex.hpp:224
SMV_StandaloneNumeric< uint64_t > totalWaitTicks
Definition: timed_mutex.hpp:225
char NONNULL_RETURN
Definition: compiler_hints.h:745
SMV_StandaloneNumeric< uint64_t > lockObtainedAt
Definition: timed_mutex.hpp:61
Statistics for a TimedCondition object.
Definition: timed_mutex.hpp:219