gatelib  2.1
g_mthread_ISyncObject.h
1 #pragma once
2 
3 #include "g_common.h"
4 #include <string>
5 
6 namespace g
7 {
8 namespace mthread
9 {
10 
11 enum NamedSyncObjectCreationOptions_t
12 {
13  g_create_once = 1 ,
14  g_create_always = 2 ,
15  g_open = 3
16 };
17 
18 G_EXC_DEFINE(SyncObjectException,Exception);
19 G_EXC_DEFINE(ServerSyncObjectAlreadyExistsException,SyncObjectException);
20 G_EXC_DEFINE(NamedSyncObjectNotExistsException,SyncObjectException);
21 G_EXC_DEFINE(WrongSyncObjectNameException,SyncObjectException);
22 G_EXC_DEFINE_MSG(SignalInterruptedWaitExc,SyncObjectException,"Wait was interrupted by a signal!");
23 G_EXC_DEFINE_MSG(InvalidValueForNamedSyncObjectCreationOptionsException,SyncObjectException,"Not a valid value for NamedSyncObjectCreationFlags!");
24 
25 
26 class G_LIB_ITEM ISyncObject
27 {
28 public:
29  ISyncObject ( ) : mIsOwner(false){ }
30 
31  virtual ~ISyncObject(){}
32 
33  //wait indefinetely for the object
34  virtual void wait ( ) = 0;
35 
36  virtual bool tryWait ( ) = 0;
37 
38  // Wait until synchronisation occurs
39  virtual bool wait ( GTimeoutSec_t aTimeOutSec ) = 0;
40 
41  //on POSIX/UNIX the object that first creates the named mutex/semaphore has the
42  //ownship, when the destructor is called the object is unlinked
43  //(object is destroyed when last object is destroyed).
44  //has not effect on windows (is left for compatibility)
45  bool isOwner ( ) const { return mIsOwner; }
46 
47  //Meaning:
48  //Windows: handle of the object
49  //POSIX/UNIX: pointer to the sync object struct
50  void* getData ( ) const { return mSyncObjectData; }
51  const std::string& getName ( ) const { return mName; }
52  bool isAnonimous ( ) const { return ( mName.size() == 0 ); }
53 
54 protected:
55  std::string mName;
56  void* mSyncObjectData;
57  bool mIsOwner;
58 };
59 
60 }//namespace mthread
61 }//namespace g
Definition: g_mthread_ISyncObject.h:26
#define G_EXC_DEFINE_MSG(aexctypename, abaseexctypename, amsg)
Definition: g_exception_macros.h:43
#define G_EXC_DEFINE(aexctypename, abaseexctypename)
Definition: g_exception_macros.h:39
Definition: g.mthread.ThreadSimpleEvent.h:5