EpcTools
An event based multi-threaded C++ development framework.
|
Go to the documentation of this file.
18 #ifndef __esynch_h_included
19 #define __esynch_h_included
24 #include <semaphore.h>
31 #define MAX_NOTIFYIDS 64
87 Void
init(Bool shared);
99 #if defined(NATIVE_IPC)
100 pthread_mutex_t &
mutex()
117 m_initialized =
False;
119 Bool enter(Bool wait =
True);
125 #if defined(NATIVE_IPC)
126 pthread_mutex_t m_mutex;
140 : m_acquire(
acquire), m_mtx(mtx)
158 m_acquire = m_mtx.enter(wait);
193 Void *
operator new(size_t, Void *where) {
return where; }
208 ~EMutexDataPublic() {}
210 Int &mutexId() {
return m_mutexId; }
213 EMutexDataPublic() {}
214 Int &nextIndex() {
return m_nextIndex; }
257 operator EMutexDataPublic &();
273 : m_initialized(
False),
283 : m_initialized(
False),
285 m_initCount(initcnt),
341 virtual Void
init(Long initcnt) = 0;
358 Bool &
shared() {
return getData().shared(); }
389 : m_data(initcnt,
False)
425 ESemaphoreDataPublic(Long initcnt=0)
429 ~ESemaphoreDataPublic()
433 Int &semIndex() {
return m_semIndex; }
436 Int &nextIndex() {
return m_nextIndex; }
531 pthread_rwlock_t m_rwlock;
542 : m_rwlock( rwlock ),
560 return m_locked = m_rwlock.enter( ERWLock::Read, wait );
581 : m_rwlock( rwlock ),
599 return m_locked = m_rwlock.enter( ERWLock::Write, wait );
621 EEvent(
bool state =
false );
633 Bool
wait(
int ms = -1 );
648 #endif // #define __esynch_h_included
Bool & shared()
Retrieves a reference indicating if this is a shared semaphore (public).
Definition: esynch.h:314
Void init(Bool shared)
Initializes the mutex data.
~ERDLock()
Class destructor.
Definition: esynch.h:549
#define DECLARE_ERROR(__e__)
Declares exception class derived from EError with no constructor parameters.
Definition: eerror.h:53
ESemaphoreBase()
Default constructor.
Definition: esynch.h:335
EMutexLock(EMutexData &mtx, Bool acquire=True)
Class constructor.
Definition: esynch.h:139
Defines base class for exceptions and declaration helper macros.
Contains the data associated with a public or private semaphore.
Definition: esynch.h:268
Bool acquire(Bool wait=true)
Acquires the lock.
Definition: esynch.h:597
Void init()
Initializes the semaphore data.
Definition: esynch.cpp:443
Void detach()
Detaches from the public mutex object.
Definition: esynch.cpp:432
Void destroy()
Destroys the semaphore data.
Definition: esynch.cpp:455
Bool acquire(Bool wait=true)
Acquires the lock.
Definition: esynch.h:558
An object that can be waited on to be set in another thread.
Definition: esynch.h:616
~EMutexPublic()
Class destructor.
Definition: esynch.h:235
Void destroy()
Destroys/releases the mutex object.
Definition: esynch.cpp:408
#define True
True.
Definition: ebase.h:25
ESemaphorePublic()
Default constructor.
Definition: esynch.h:451
EMutexPrivate(Bool bInit=True)
Class constructor.
Definition: esynch.h:180
Bool initialized()
Retrieves object initialization status.
Definition: esynch.h:93
Macros for various standard C library functions and standard includes.
ESemaphorePrivate(Long initcnt=0, Bool bInit=True)
Class constructor.
Definition: esynch.h:388
~EMutexLock()
Class destructor. Unlocks the mutex if locked.
Definition: esynch.h:146
~ESemaphoreBase()
Class desctructor.
Definition: esynch.h:337
~EMutexPrivate()
Class destructor.
Definition: esynch.h:187
Void attach(Int mutexid)
Associates this public mutex object with the mutex ID located in shared memory.
Definition: esynch.cpp:425
Void detach()
Detaches from the semaphore data.
Definition: esynch.cpp:569
A private mutex (the mutex data is allocated from either the heap or stack).
Definition: esynch.h:175
Void init(Long initcnt)
Initializes the data associated with the semaphore.
Definition: esynch.h:402
Void reset()
Resets the event state.
Definition: esynch.cpp:679
Bool initialized()
Retrieves the initialization status.
Definition: esynch.h:311
~ESemaphorePublic()
Class destructor.
Definition: esynch.h:465
Allows read or write access.
Void attach(Int semid)
Attaches this object to the semaphore data associated with the semaphore ID.
Definition: esynch.cpp:562
Bool isLocked()
Retrieves the lock status.
Definition: esynch.h:603
Bool Decrement(Bool wait=True)
Decrements the semaphore value.
Definition: esynch.h:348
Bool initialized()
Indicates the initialization status for this object.
Definition: esynch.h:355
Represents a public semaphore, the semaphore data is located in shared memory.
Definition: esynch.h:446
Encapsulates a read-write lock object.
Definition: esynch.h:507
A public mutex (the mutex data is located in shared memory).
Definition: esynch.h:223
Bool & shared()
Indicates if this object is to be shared between processes.
Definition: esynch.h:358
Int mutexId()
Retrieves the mutex ID associated with this public mutex.
Definition: esynch.h:253
Bool wait(int ms=-1)
Waits for the event to be set.
Definition: esynch.cpp:684
EEvent(bool state=false)
Class constructor.
Definition: esynch.cpp:652
#define False
False.
Definition: ebase.h:27
~EWRLock()
Class destructor.
Definition: esynch.h:588
Void destroy()
Destroys the data associated with the semaphore.
Definition: esynch.h:404
ESemaphoreData(Long initcnt, Bool shared)
Class constructor.
Definition: esynch.h:282
ERWLock()
Default constructor.
Definition: esynch.cpp:596
~ERWLock()
Class destructor.
Definition: esynch.cpp:615
~ESemaphoreData()
Class destructor.
Definition: esynch.h:290
Request a read lock for the specified read-write lock object.
Definition: esynch.h:535
Represents a private semaphore, the semaphore data is allocated from either the stack or heap.
Definition: esynch.h:382
#define DECLARE_ERROR_ADVANCED(__e__)
Declares exception class derived from EError with no constructor parameters and developer defined con...
Definition: eerror.h:59
Bool Increment()
Increments the semaphore value.
Definition: esynch.h:351
Bool Increment()
Increments teh semaphore.
Definition: esynch.cpp:494
Long & mutex()
Retrieves the underlying mutex object.
Definition: esynch.h:107
virtual Void destroy()=0
Destroys/releases the semaphore data. This method must be overloaded in a derived class.
Bool Decrement(Bool wait=True)
Decrements the semaphore.
Definition: esynch.cpp:469
ESemaphoreData()
Default constructor.
Definition: esynch.h:272
Request a write lock for the specified read-write lock object.
Definition: esynch.h:574
Void init()
Allocates and initializes the mutex object.
Definition: esynch.cpp:399
Long & initialCount()
Retrieves the initial count of the semaphore.
Definition: esynch.h:317
ERDLock(ERWLock &rwlock, Bool acq=true)
Class constructor.
Definition: esynch.h:541
virtual Void init(Long initcnt)=0
Initializes the semaphore data. This method must be overloaded in a derived class.
Void destroy()
Destroyes the mutex data.
Bool isSet()
Determines if the event has been set.
Definition: esynch.h:636
Bool acquire(Bool wait=True)
Manually acquires a lock on the mutex.
Definition: esynch.h:155
Void destroy()
Destroys the data associated with the semaphore.
Definition: esynch.cpp:534
Void set()
Sets the event.
Definition: esynch.cpp:671
EWRLock(ERWLock &rwlock, Bool acq=true)
Class constructor.
Definition: esynch.h:580
Bool isLocked()
Retrieves the lock status.
Definition: esynch.h:564
EMutexPublic(Bool bInit=True)
Default constructor.
Definition: esynch.h:228
DECLARE_ERROR_ADVANCED2(ERWLockError_LockAttrInitFailed)
Contains the base functionality for a semaphore.
Definition: esynch.h:331
Used internally by EpcTools for managing access to public (shared memory) objects.
Definition: esynch2.h:41
~ESemaphorePrivate()
Class destructor.
Definition: esynch.h:395
Encapsulates and extends a std::string object.
~EEvent()
Class destructor.
Definition: esynch.cpp:666
Int & semIndex()
Retrieves the semaphore data index.
Definition: esynch.cpp:555
Void init()
Definition: esynch.h:195
Acquires and holds a lock on the specified mutex.
Definition: esynch.h:133
ESemaphorePublic(Long initcnt, Bool bInit=True)
Class constructor.
Definition: esynch.h:458
Void init(Long initialCount)
Initializes the data associated with the semaphore.
Definition: esynch.cpp:522
~EMutexData()
Class destructor.
Definition: esynch.h:80
Long currCount()
Retrieves the current semaphore count.
Definition: esynch.h:320
Long & initialCount()
Retrieves the initial semaphore value.
Definition: esynch.h:361
Contains the data associated with a public or private mutex.
Definition: esynch.h:72
Long currCount()
Retrieves the current semaphore value.
Definition: esynch.h:364