INOS
inos_syn.h
Go to the documentation of this file.
1 //******************************************************************************
27 //******************************************************************************
28 
29 #if !defined( __INOS_SYN_H )
30 #define __INOS_SYN_H
31 
32 //--------------------------------------------------------------------------
33 //--- includes -----------------------------------------------------------------
34 //------------------------------------------------------------------------------
35 
36 //------------------------------------------------------------------------------
37 //--- definitions --------------------------------------------------------------
38 //------------------------------------------------------------------------------
39 
40 #define INOS_NO_WAIT 0x00000000 // don't wait
41 #define INOS_WAIT_FOREVER 0xFFFFFFFF // wait forever
42 
43 // --- locking cache -----------------------------------------------------------
44 
45 #ifndef ICACHE
46 #ifdef INOS_CACHE_LOCK_SUPPORT
47 #define ICACHE __attribute__ ((section (".icache")))
48 #define DCACHE __attribute__ ((section (".dcache")))
49 #else
50 #define ICACHE
51 #define DCACHE
52 #endif
53 #endif
54 
55 //------------------------------------------------------------------------------
56 //--- forwards -----------------------------------------------------------------
57 //------------------------------------------------------------------------------
58 class CINOSSyncNode;
59 class CINOSTaskExMsg;
60 class CINOSBus;
61 
62 //------------------------------------------------------------------------------
63 //--- class CINOSSync ----------------------------------------------------------
64 //------------------------------------------------------------------------------
65 
66 class CINOSSync
67 {
68  //--- user interface ---------------------------------------------------
69 
70  // constructor / destructor
71  public :
80  CINOSSync(
81  const char* aName=0,
82  uint32 aInitialCount=0,
83  bool aManual=false
84  );
85 
88  virtual ~CINOSSync();
89 
90  // public member functions
91  public :
94  virtual const char* GetName() { return m_pName;};
95 
102  ICACHE virtual uint32 Wait(uint32 aTimeout=INOS_WAIT_FOREVER);
103 
106  ICACHE virtual void Signal() { iSignal(false); }
107 
115  ICACHE virtual void SignalEx(CINOSTaskExMsg* apMsg, uint32 auRplId, uint32 auAppError) { Signal(); };
116 
121  ICACHE virtual bool MsgEvent(CINOSTaskExMsg* apMsg) { return false; };
122 
123 
126  virtual void Reset();
127 
130  volatile uint32* GetLockAdr()
131  { return m_Lock.GetAddr(); };
132 
133  // returns true if the event relies on polling to detect state transition.
134  // this is necessary for 'raw' handled ports.
135  virtual bool UsesPolling() const {return false;};
136 
137  bool IsSame(CINOSSync* i_pSync) {
138  return this == i_pSync;
139  }
140 
141  #if defined(INOS_SYNCGUARD)
142  CINOSSync* operator& () {
143  // remember that we're referenced
144  m_uReferenced++;
145  // return the address of the object
146  return this;
147  }
148  #endif
149 
150  //--- internals --------------------------------------------------------
151 
152  friend class CINOSKernel;
153  friend class CINOSScheduler;
154  friend class CINOSTask;
155  friend class CINOSMultiSync;
156 
157  // protected members
158  protected:
159  const char* m_pName;
160  uint32 m_uCount;
161  bool m_bManual;
165  CINOSSyncNode* m_pNode;
166  #if defined(INOS_SYNCGUARD)
167  uint32 m_uReferenced{};
168  uint32 m_uReferencedByParent{};
169  #endif
170 
171  // operators
172  public:
173  int operator < (const CINOSSync& aSync) const
174  { return (strcmp(m_pName, aSync.m_pName)<0);}
175  int operator == (const CINOSSync& aSync) const
176  { return (strcmp(m_pName, aSync.m_pName)==0);}
177  int operator < (const char* aName) const
178  { return (strcmp(m_pName, aName)<0);}
179  int operator == (const char* aName) const
180  { return (strcmp(m_pName, aName)==0);}
181 
182  // protected member functions
183  protected :
184  // parent checks signaled state
185  ICACHE virtual bool Signaled(CINOSSync*& aChild);
186  // get pointer to object node
187  /*ICACHE*/ virtual CINOSSyncNode* GetNode() {return m_pNode;};
188  // set pointer to object node
189  /*ICACHE*/ virtual void SetNode(CINOSSyncNode* aNode) {m_pNode = aNode;};
190 
196  ICACHE void SignalAndUnlock(uint32 auMsr) {
197  iSignal(true, auMsr);
198  }
199 
200  // private member functions
201  private :
207  void iSignal(bool abAlreadyLocked, uint32 uMsr = 0);
208 
209  // allow dynamic object handling (new/delete)
210  DECLARE_DYNAMIC(CINOSSync);
211 };
212 
213 //------------------------------------------------------------------------------
214 //--- class CINOSMultiSync -----------------------------------------------------
215 //------------------------------------------------------------------------------
216 
217 class CINOSExceptionCleanup;
234 class CINOSMultiSync : public CINOSSync
235 {
236  //--- user interface ---------------------------------------------------
237 
238  // constructor / destructor
239  public :
240  CINOSMultiSync(const char* aName=0);
241  virtual ~CINOSMultiSync();
242 
243  // public member functions
244  public :
247  void Or(CINOSSync* aChild);
250  void And(CINOSSync* aChild);
254  void Remove(CINOSSync* aChild, bool aDelete=false);
258  void RemoveAll(bool aDelete=false);
259 
262  ICACHE virtual uint32 Wait(uint32 aTimeout=INOS_WAIT_FOREVER) override;
266  ICACHE virtual uint32 Wait(CINOSSync*& aChild, uint32 aTimeout=INOS_WAIT_FOREVER);
267 
270  virtual void Reset() override;
271 
272  // returns true if the event relies on polling to detect state transition.
273  // this is necessary for 'raw' handled ports.
274  virtual bool UsesPolling() const override {return m_bUsesPolling;};
275 
279  CINOSBus* GetBus() { return m_pBus; }
280  void SetBus(CINOSBus* apBus) { m_pBus = apBus; }
281 
282  //--- internals --------------------------------------------------------
283 
284  friend class CINOSSyncNode;
285 
286  // protected members
287  protected:
288  CINOSSyncNode* pFirstChild; // pointer to first child
289  CINOSSyncNode* pLastChild; // pointer to last child
290 
291  // exception handling
292  CINOSExceptionCleanup* pCleanup;
293 
294  // Flag indicating if bit event is detected using polling
295  bool m_bUsesPolling;
296 
297  // pointer to bus (if any) used for sleep
298  CINOSBus* m_pBus;
299 
300  // protected member functions
301  protected :
302  // parent checks signaled state
303  ICACHE virtual bool Signaled(CINOSSync*& aChild) override;
304  // wake up because child state changed
305  void WakeUp();
306  // cleanup
307  void Cleanup();
308 
309  // allow dynamic object handling (new/delete)
311 };
312 
313 //------------------------------------------------------------------------------
314 //--- class CINOSSyncNode ------------------------------------------------------
315 //------------------------------------------------------------------------------
316 
318 class CINOSSyncNode
319 {
320  friend class CINOSSync;
321  friend class CINOSMultiSync;
322  friend class CINOSBitSetEvent;
323  friend class CINOSBitClearedEvent;
324 
325  // protected members
326  protected:
327  CINOSSync* pChild; // pointer to sync object
328  CINOSMultiSync* pParent; // pointer to parent sync object
329  CINOSSyncNode* pNext; // pointer to next node on the same level
330  // for the sake of simplicity (and runtime overhead), on multicore
331  // system, we do not support 'groups' of sync nodes anymore.
332  #ifndef INOS_MULTICORE
333  CINOSSyncNode* pNextGroup; // pointer to next sync group
334  #endif
335  bool mOrNode; // 'or' node true/false
336 
337  // constructor / destructor
338  public :
339  CINOSSyncNode(CINOSMultiSync* aParent, CINOSSync* aChild, bool aOrNode);
340  ~CINOSSyncNode();
341 
342  // protected member functions
343  protected :
344  // child changed to signaled state -> wake up parents
345  ICACHE void WakeUp();
346 
347  // allow dynamic object handling (new/delete)
348  DECLARE_DYNAMIC(CINOSSyncNode);
349 };
351 
352 
353 //------------------------------------------------------------------------------
354 //--- class CINOSConditionVariable ---------------------------------------------
355 //------------------------------------------------------------------------------
356 #include <mutex>
368 {
369  public :
370  enum EStatus {
371  eNoTimeout,
372  eTimeout
373  };
374 
379  CINOSConditionVariable(const char* aName=nullptr);
380 
383  virtual ~CINOSConditionVariable();
384 
385  public :
388  template< class Rep, class Period >
389  EStatus WaitFor(std::unique_lock<CINOSMutex>& lock,
390  const std::chrono::duration<Rep, Period>& rel_time)
391  {
392  uint32 waitUs = std::chrono::duration_cast<std::chrono::microseconds>(rel_time).count();
393  const uint32 uWaitTime = DoWait(lock, waitUs);
394  return (uWaitTime == 0) ? eTimeout : eNoTimeout;
395  }
396 
399  template< class Rep, class Period, class Predicate >
400  bool WaitFor( std::unique_lock<CINOSMutex>& lock,
401  const std::chrono::duration<Rep, Period>& rel_time,
402  Predicate pred) {
403  uint32 waitUs = checked_static_cast<uint32>(std::chrono::duration_cast<std::chrono::microseconds>(rel_time).count());
404  while( !pred() ) {
405  uint32 uWaitTime = DoWait(lock, waitUs);
406  if( !uWaitTime ) {
407  // timeout occurred
408  return false;
409  }
410  waitUs = (waitUs - uWaitTime) > 0 ? waitUs - uWaitTime : 0;
411  }
412  return true;
413  }
414 
417  void Wait( std::unique_lock<CINOSMutex>& lock ) {
418  DoWait(lock);
419  }
420 
423  template< class Predicate >
424  void wait( std::unique_lock<CINOSMutex>& lock, Predicate pred ) {
425  while( !pred() ) {
426  DoWait(lock);
427  }
428  }
429 
432  void NotifyOne();
435  void NotifyAll();
436 
437  private:
440  uint32 DoWait(std::unique_lock<CINOSMutex>& lock, uint32 auTimeout = INOS_WAIT_FOREVER);
441 
442  // allow dynamic object handling (new/delete)
443  DECLARE_DYNAMIC(CINOSConditionVariable);
444  // objects of CINOSConditionVariable need to be created very early during startup, when
445  // the CTORs have not been executed. Therefore, in order to create such
446  // objects, we need to provide the placement operator new.
447  DECLARE_DYNAMIC_PLACEMENT(CINOSConditionVariable);
448 
449 };
450 
451 //------------------------------------------------------------------------------
452 //--- class CINOSSemaphore -----------------------------------------------------
453 //------------------------------------------------------------------------------
454 
455 class CINOSSemaphore : public CINOSSync
456 {
457  //--- user interface ---------------------------------------------------
458 
459  // public members
460  public :
467  const char* apName = 0,
468  uint32 auInitialCount = 1,
469  uint32 auMaxCount = 0xffffffff
470  );
471 
474  virtual ~CINOSSemaphore();
475 
482  ICACHE uint32 Request(uint32 aTimeout=INOS_WAIT_FOREVER);
483 
486  ICACHE void Release();
487 
490  uint32 GetCount()
491  { return m_uCount; }
492 
495  uint32 GetMaxCount()
496  { return m_uMaxCount; }
497 
498  //--- internals --------------------------------------------------------
499 
500  private:
502  uint32 m_uMaxCount;
503 
504  // allow dynamic object handling (new/delete)
505  DECLARE_DYNAMIC(CINOSSemaphore);
506 };
507 
508 //------------------------------------------------------------------------------
509 //--- class CINOSQueue ---------------------------------------------------------
510 //------------------------------------------------------------------------------
511 
512 class CINOSQueue : public CINOSSync
513 {
514  //--- user interface ---------------------------------------------------
515 
516  // public members
517  public :
523  // create a queue with 'aNumber' entries of 'aSize' bytes
524  CINOSQueue(const char* apName, uint32 auNumber, uint32 auSize);
525 
528  virtual ~CINOSQueue();
529 
538  ICACHE uint32 Put(void* aData, uint32 aTimeout=INOS_WAIT_FOREVER, uint32 auFlags=0);
539 
547  ICACHE uint32 Get(void* aData, uint32 aTimeout=INOS_WAIT_FOREVER);
548 
556  void Inquiry(void* aData, uint32& aCountOfElements);
557 
568  bool InquiryAt(void* aData, uint32 auIndex);
569 
572  void Flush();
573 
577  bool Empty();
578 
582  uint32 GetNumber();
583 
587  const uint32 GetSize() const {
588  return mSize;
589  }
590 
594  const uint32 GetMaxNumber() const {
595  return mMaxNumber;
596  }
597 
601  const uint32* GetAdrNumber() const {
602  return &mNumber;
603  }
604 
608  const uint64* GetAdrCount() const {
609  return &mCount;
610  }
611 
615  void SetFlag(uint32 auFlag)
616  {
617  mQueueFlags |= auFlag;
618  }
619 
623  void ClrFlag(uint32 auFlag)
624  {
625  mQueueFlags &= ~auFlag;
626  }
627 
631  uint32 BeginAccess();
632 
638  bool Access(void*&ptrData, uint32 auIndex);
639 
643  void EndAccess(uint32 msr);
644 
647  enum {
648  eFlgOverflowCheck = 0x00000001, // check queue overflows
649  eFlgOverflowFatal = 0x00000002, // fatal error in case of an overflow
650  eFlgAccess = 0x00000004, // data access active (queue locked)
651  eFlgUnique = 0x00000008, // only allow unique entries in queue
652  };
653 
654  //--- internals --------------------------------------------------------
655 
656  // protected members
657  protected :
658  void* pBegin;
659  void* pEnd;
660  void* pPut;
661  void* pGet;
662  uint32 mNumber;
663  uint32 mSize;
664  uint32 mMaxNumber;
665  uint32 mQueueFlags;
667  uint64 mCount;
668 
669  // allow dynamic object handling (new/delete)
670  DECLARE_DYNAMIC(CINOSQueue);
671 };
672 
673 // include task queue handling
674 #include <cinostaskqueue.h>
675 
676 //------------------------------------------------------------------------------
677 //--- class CINOSEvent ---------------------------------------------------------
678 //------------------------------------------------------------------------------
679 
680 class CINOSEvent : public CINOSSync
681 {
682  //--- user interface ---------------------------------------------------
683 
684  // constructor / destructor
685  public :
686  CINOSEvent(
687  const char* aName=0,
688  uint32 aInitialCount=0,
689  bool aManual=false
690  );
691  virtual ~CINOSEvent();
692 
693  //--- internals --------------------------------------------------------
694 
695  friend class CINOSBitSetEvent;
696  friend class CINOSBitClearedEvent;
697 
698  // allow dynamic object handling (new/delete)
699  DECLARE_DYNAMIC(CINOSEvent);
700 };
701 
702 //------------------------------------------------------------------------------
703 //--- class CINOSBitSetEvent ---------------------------------------------------
704 //------------------------------------------------------------------------------
705 
706 #ifndef INOS_NO_BIT_EVENT_SUPPORT
707 class CINOSBit;
709 {
710  friend class CINOSBit;
711 
712  //--- user interface ---------------------------------------------------
713 
714  // constructor / destructor
715  public :
716  CINOSBitSetEvent(CINOSBit* apBit);
717  virtual ~CINOSBitSetEvent();
718 
719  // public member functions
720  public :
721  // get name of sync object
722  virtual const char* GetName() override {return m_pEvent->GetName();};
723  // wait for signaled state for max. aTimeout usec
724  virtual uint32 Wait(uint32 aTimeout=INOS_WAIT_FOREVER) override ;
725  // put object into the signaled state
726  virtual void Signal() override ;
727  // reset object state
728  virtual void Reset() override ;
729  // returns true if the event relies on polling to detect state transition.
730  // this is necessary for 'raw' handled ports.
731  virtual bool UsesPolling() const override {return m_bUsesPolling;};
732 
733  //--- internals --------------------------------------------------------
734 
735  // protected members
736  protected :
737  CINOSBit* m_pBit;
738  CINOSEvent* m_pEvent;
739 
740  // exception handling
741  CINOSExceptionCleanup* m_pCleanup;
742 
743  // Flag indicating if bit event is detected using polling
744  bool m_bUsesPolling;
745 
746  // protected member functions
747  protected :
748  // parent checks signaled state
749  virtual bool Signaled(CINOSSync*& aChild) override;
750  // get pointer to object node
751  virtual CINOSSyncNode* GetNode() override {return m_pEvent->GetNode();};
752  // set pointer to object node
753  virtual void SetNode(CINOSSyncNode* aNode) override {m_pEvent->SetNode(aNode);};
754  // cleanup
755  void Cleanup();
756 
757  // allow dynamic object handling (new/delete)
759 };
760 
761 //------------------------------------------------------------------------------
762 //--- class CINOSBitClearedEvent -----------------------------------------------
763 //------------------------------------------------------------------------------
764 
766 {
767  friend class CINOSBit;
768 
769  //--- user interface ---------------------------------------------------
770 
771  // constructor / destructor
772  public :
774  virtual ~CINOSBitClearedEvent();
775 
776  // public member functions
777  public :
778  // get name of sync object
779  virtual const char* GetName() override {return m_pEvent->GetName();};
780  // wait for signaled state for max. aTimeout usec
781  virtual uint32 Wait(uint32 aTimeout=INOS_WAIT_FOREVER) override ;
782  // put object into the signaled state
783  virtual void Signal() override ;
784  // reset object state
785  virtual void Reset() override ;
786  // returns true if the event relies on polling to detect state transition.
787  // this is necessary for 'raw' handled ports.
788  virtual bool UsesPolling() const override {return m_bUsesPolling;};
789 
790  //--- internals --------------------------------------------------------
791 
792  // protected members
793  protected :
794  CINOSBit* m_pBit;
795  CINOSEvent* m_pEvent;
796 
797  // exception handling
798  CINOSExceptionCleanup* m_pCleanup;
799 
800  // Flag indicating if bit event is detected using polling
801  bool m_bUsesPolling;
802 
803  // protected member functions
804  protected :
805  // parent checks signaled state
806  virtual bool Signaled(CINOSSync*& aChild) override ;
807  // get pointer to object node
808  virtual CINOSSyncNode* GetNode() override {return m_pEvent->GetNode();};
809  // set pointer to object node
810  virtual void SetNode(CINOSSyncNode* aNode) override {m_pEvent->SetNode(aNode);};
811  // cleanup
812  void Cleanup();
813 
814  // allow dynamic object handling (new/delete)
816 };
817 #endif
818 
819 //------------------------------------------------------------------------------
820 //--- class CINOSTimeEvent -----------------------------------------------------
821 //------------------------------------------------------------------------------
822 
823 #ifndef INOS_NO_1MS_SUPPORT
824 class CINOSxmsHandler;
825 class CINOSTimeEvent : public CINOSSync
826 {
827  //--- user interface ---------------------------------------------------
828 
829  // constructor / destructor
830  public :
831  enum {
832  eEventDisabled = 0,
833  eUsePreviousTime = 0
834  };
835 
840  CINOSTimeEvent(uint32 aTime);
841  virtual ~CINOSTimeEvent();
842 
843  // public member functions
844  public :
845  // reset event with new time (time = 0 -> reset with old time)
846  void Reset(uint32 aTime=eUsePreviousTime);
851  void Stop();
852  // start event with new time (time = 0 -> reset with old time)
853  void Start(uint32 aTime=eUsePreviousTime);
854 
855  //--- internals --------------------------------------------------------
856 
857  private:
860  void iAddHandler();
861  void iRemoveHandler();
862 
863  // protected members
864  protected :
865  uint32 mWaitTime = eEventDisabled;
866  CINOSxmsHandler* pHandler = nullptr;
867  // exception handling
868  CINOSExceptionCleanup* pCleanup = nullptr;
869 
870  // protected member functions
871  protected :
872  // event handler
873  void Handler();
874  // cleanup
875  void Cleanup();
876 
877  // allow dynamic object handling (new/delete)
878  DECLARE_DYNAMIC(CINOSTimeEvent);
879 };
880 
881 #endif
882 
883 //--------------------------------------------------------------------------
884 // CINOSSyncObjects
885 //--------------------------------------------------------------------------
886 
888 class CINOSSyncObjects
889 {
890  //--- user interface ---------------------------------------------------
891 
892  public :
893  // add sync object to the tree
894  void Add(CINOSSync* aSync);
895  // find sync object 'aName'
896  CINOSSync* Find(char* aName);
897 
898  //--- internals --------------------------------------------------------
899 
900  private :
901  // tree of all objects in the system
902  TINOSNameBalancedBinaryTree<CINOSSync>* pSyncObjects;
903 
904  // constructor
905  public:
906  CINOSSyncObjects() ;
907 };
909 
910 //--------------------------------------------------------------------------
911 // CINOSLockGuard
912 //--------------------------------------------------------------------------
913 
914 template<typename TLock>
916 {
917  //--- user interface ---------------------------------------------------
918 
919  public :
922  CINOSLockGuard(TLock& aLock):
923  m_Lock(aLock), m_bLocked(false)
924  {
925  m_bLocked = (m_Lock.Request() != 0);
926  }
929  CINOSLockGuard(TLock& aLock, uint32 auTimeout/*usec*/):
930  m_Lock(aLock), m_bLocked(false)
931  {
932  m_bLocked = (m_Lock.Request(auTimeout) != 0);
933  }
934  ~CINOSLockGuard() {
935  if (m_bLocked) m_Lock.Release();
936  }
937  bool IsLocked() const {
938  return m_bLocked;
939  }
940 
941  //--- internals --------------------------------------------------------
942 
943  private :
944  // Lock to be guarded
945  TLock& m_Lock;
946  // Flag indicating if the lock is held
947  bool m_bLocked;
948 };
949 
951 
952 //------------------------------------------------------------------------------
953 //--- class CINOSRefCount ------------------------------------------------------
954 //------------------------------------------------------------------------------
955 
961 {
962  //--- user interface ---------------------------------------------------
963 
964  // public members
965  public :
972  const char* apParentName,
973  const char* apBaseName,
974  int32 aiInitialCount = 0,
975  void* apHandlerObj = NULL,
976  void* apHandlerFunc = NULL
977  );
978 
981  virtual ~CINOSRefCount();
982 
985  int32 Increment();
986 
989  int32 Decrement();
990 
993  int32 GetCount();
994 
997  void SetCount(int32 aiNewCount);
998 
999  //--- internals --------------------------------------------------------
1000 
1001  protected :
1002 
1006  uint32 Request();
1007  void Release();
1008 
1009  protected :
1011  inosName32 m_sName;
1013  int32 m_iCount;
1016  void* m_pHandlerFunc;
1017 
1018  // allow dynamic object handling (new/delete)
1020 };
1021 
1023 
1024 inline CINOSTask* ActualTask();
1025 
1026 //------------------------------------------------------------------------------
1027 //--- class CINOSReadWriteLock -------------------------------------------------
1028 //------------------------------------------------------------------------------
1033  public:
1037  void ReadLock() {
1038  std::unique_lock<CINOSMutex> lock(m_Mutex);
1039  while (HasForeignWriter()) {
1040  m_Unlocked.wait(lock, [this]() { return !HasForeignWriter(); });
1041  }
1042  m_uReaders++;
1043  }
1045  void ReadUnlock() {
1046  std::unique_lock<CINOSMutex> lock(m_Mutex);
1047  m_uReaders--;
1048  if (m_uReaders == 0)
1049  m_Unlocked.NotifyAll();
1050  }
1055  void WriteLock() {
1056  std::unique_lock<CINOSMutex> lock(m_Mutex);
1057  while (HasForeignWriter() || HasReaders()) {
1058  m_Unlocked.wait(lock, [this]() { return !(HasForeignWriter() || HasReaders()); });
1059  }
1060  ++m_nWriter;
1061  m_pWriter = ActualTask();
1062  }
1064  void WriteUnlock() {
1065  std::unique_lock<CINOSMutex> lock(m_Mutex);
1066  --m_nWriter;
1067  if (m_nWriter == 0) {
1068  m_pWriter = nullptr;
1069  m_Unlocked.NotifyAll();
1070  }
1071  }
1072  private:
1073  bool HasReaders() const {
1074  return m_uReaders > 0;
1075  }
1076  bool HasForeignWriter() const {
1077  const bool bHasWriter = m_nWriter > 0;
1078  const bool bWriterIsMe = ActualTask() == m_pWriter;
1079  return bHasWriter && !bWriterIsMe;
1080  }
1081  private:
1083  size_t m_uReaders{};
1086  size_t m_nWriter{0};
1088  CINOSTask* m_pWriter{nullptr};
1090  CINOSMutex m_Mutex;
1093  CINOSConditionVariable m_Unlocked;
1094 };
1095 //------------------------------------------------------------------------------
1096 //--- class CINOSWriteLock -----------------------------------------------------
1097 //------------------------------------------------------------------------------
1101  public:
1103  : m_Lock(aLock)
1104  {
1105  m_Lock.WriteLock();
1106  }
1107  ~CINOSWriteLock() {
1108  m_Lock.WriteUnlock();
1109  }
1110  CINOSReadWriteLock& m_Lock;
1111 };
1112 //------------------------------------------------------------------------------
1113 //--- class CINOSReadLock ------------------------------------------------------
1114 //------------------------------------------------------------------------------
1118  public:
1120  : m_Lock(aLock)
1121  {
1122  m_Lock.ReadLock();
1123  }
1124  ~CINOSReadLock() {
1125  m_Lock.ReadUnlock();
1126  }
1127  CINOSReadWriteLock& m_Lock;
1128 };
1129 
1130 //--------------------------------------------------------------------------
1131 // global variables
1132 //--------------------------------------------------------------------------
1133 
1134 extern CINOSSyncObjects* pINOSSyncObjects; // binary tree of INOS sync objects
1135 
1136 #endif // __INOS_SYN_H
1137 
CINOSReadWriteLock::WriteUnlock
void WriteUnlock()
Definition: inos_syn.h:1064
CINOSMutex
Definition: cinosmutex.h:35
CINOSBus
Definition: cinosbus.h:562
CINOSReadWriteLock
Definition: inos_syn.h:1032
ActualTask
CINOSTask * ActualTask()
CINOSQueue::Access
bool Access(void *&ptrData, uint32 auIndex)
Access Try to gain access to the data at a given index. The call needs to be embraced by calls of uin...
CINOSReadWriteLock::ReadUnlock
void ReadUnlock()
Definition: inos_syn.h:1045
CINOSRefCount::Decrement
int32 Decrement()
Decrement the reference counter and return the new value.
CINOSBitClearedEvent
Definition: inos_syn.h:765
CINOSQueue::Inquiry
void Inquiry(void *aData, uint32 &aCountOfElements)
Gets the first element without removing it from the queue. Moreover, aCountOfElements returns the num...
CINOSQueue::mNumber
uint32 mNumber
actual number of blocks in queue
Definition: inos_syn.h:662
CINOSBitSetEvent::Reset
virtual void Reset() override
Reset object state.
CINOSQueue::SetFlag
void SetFlag(uint32 auFlag)
Set queue flag(s)
Definition: inos_syn.h:615
CINOSMultiSync::Remove
void Remove(CINOSSync *aChild, bool aDelete=false)
CINOSRefCount::m_iCount
int32 m_iCount
Reference count.
Definition: inos_syn.h:1013
CINOSSync::GetLockAdr
volatile uint32 * GetLockAdr()
Return pointer to core locking structure.
Definition: inos_syn.h:130
CINOSSync::Signal
virtual void Signal()
Put object into the signaled state.
Definition: inos_syn.h:106
CINOSQueue::CINOSQueue
CINOSQueue(const char *apName, uint32 auNumber, uint32 auSize)
Create a queue with the given name. See also Queue.
CINOSConditionVariable::NotifyAll
void NotifyAll()
Wake up all waiting tasks See http://en.cppreference.com/w/cpp/thread/condition_variable/notify_all f...
CINOSRefCount::~CINOSRefCount
virtual ~CINOSRefCount()
Destroy reference counter.
CINOSMultiSync::Wait
virtual uint32 Wait(uint32 aTimeout=0xFFFFFFFF) override
CINOSReadWriteLock::WriteLock
void WriteLock()
Definition: inos_syn.h:1055
CINOSQueue::pBegin
void * pBegin
pointer to begin of queue buffer
Definition: inos_syn.h:658
CINOSQueue::EndAccess
void EndAccess(uint32 msr)
EndAccess Needs to be called after Access.
CINOSQueue::pPut
void * pPut
pointer to actual put block
Definition: inos_syn.h:660
CINOSSync::Reset
virtual void Reset()
Reset object state.
CINOSSync::m_idFstWaiting
tTaskId m_idFstWaiting
id of first task waiting for the sync object
Definition: inos_syn.h:162
CINOSSync::m_bManual
bool m_bManual
manual object yes/no
Definition: inos_syn.h:161
CINOSBitClearedEvent::Reset
virtual void Reset() override
Reset object state.
CINOSBit
Definition: cinosbit.h:53
CINOSQueue::InquiryAt
bool InquiryAt(void *aData, uint32 auIndex)
Gets the element at auIndex (starting from 0..numberOfElementsInQueue) without removing it from the q...
CINOSKernel
Definition: inoskernel.h:238
CINOSRefCount::m_pHandlerObj
void * m_pHandlerObj
Handler method to call when count reaches 0.
Definition: inos_syn.h:1015
CINOSQueue::mSize
uint32 mSize
size of block in queue
Definition: inos_syn.h:663
CINOSSync::m_uCount
uint32 m_uCount
signaled count of object
Definition: inos_syn.h:160
CINOSRefCount::SetCount
void SetCount(int32 aiNewCount)
Set current count.
CINOSLockGuard::CINOSLockGuard
CINOSLockGuard(TLock &aLock)
Definition: inos_syn.h:922
CINOSRefCount
Definition: inos_syn.h:960
CINOSQueue::Put
uint32 Put(void *aData, uint32 aTimeout=0xFFFFFFFF, uint32 auFlags=0)
Put data to queue and wait for max. auTimeout usec if queue full.
CINOSQueue::mMaxNumber
uint32 mMaxNumber
maximum number of blocks in queue
Definition: inos_syn.h:664
SINOSCoreLock
Definition: inostype.h:257
CINOSConditionVariable::~CINOSConditionVariable
virtual ~CINOSConditionVariable()
Destroy condition variable object.
CINOSQueue::mQueueFlags
uint32 mQueueFlags
queue flags
Definition: inos_syn.h:665
CINOSQueue::Empty
bool Empty()
Get queue state.
CINOSWriteLock
Definition: inos_syn.h:1100
CINOSEvent
Definition: inos_syn.h:680
CINOSSemaphore::GetMaxCount
uint32 GetMaxCount()
Get max. allowed count.
Definition: inos_syn.h:495
CINOSSync::m_pNode
CINOSSyncNode * m_pNode
pointer to object node (if any)
Definition: inos_syn.h:165
CINOSSync::CINOSSync
CINOSSync(const char *aName=0, uint32 aInitialCount=0, bool aManual=false)
CINOSSync::m_Lock
SINOSCoreLock m_Lock
core lock
Definition: inos_syn.h:164
CINOSQueue
Definition: inos_syn.h:512
CINOSMultiSync::GetBus
CINOSBus * GetBus()
Definition: inos_syn.h:279
tTaskId
Definition: inostype.h:192
CINOSQueue::pGet
void * pGet
pointer to actual get block
Definition: inos_syn.h:661
CINOSQueue::BeginAccess
uint32 BeginAccess()
BeginAccess Needs to be called before Access.
CINOSSemaphore::GetCount
uint32 GetCount()
Get current count.
Definition: inos_syn.h:490
CINOSConditionVariable::wait
void wait(std::unique_lock< CINOSMutex > &lock, Predicate pred)
wait for being notified and 'pred' is true See http://en.cppreference.com/w/cpp/thread/condition_vari...
Definition: inos_syn.h:424
CINOSSync::~CINOSSync
virtual ~CINOSSync()
Destroy sync object.
CINOSSemaphore::~CINOSSemaphore
virtual ~CINOSSemaphore()
Destroy semaphore.
CINOSQueue::GetSize
const uint32 GetSize() const
Return size of one queue entry.
Definition: inos_syn.h:587
CINOSSync::Wait
virtual uint32 Wait(uint32 aTimeout=0xFFFFFFFF)
wait for signaled state for max. aTimeout usec
CINOSRefCount::m_sName
inosName32 m_sName
Reference counter name (for debugging purposes)
Definition: inos_syn.h:1011
CINOSConditionVariable::Wait
void Wait(std::unique_lock< CINOSMutex > &lock)
wait for being notified (even spuriously) See http://en.cppreference.com/w/cpp/thread/condition_varia...
Definition: inos_syn.h:417
CINOSBitClearedEvent::GetName
virtual const char * GetName() override
Get name of sync object.
Definition: inos_syn.h:779
CINOSLockGuard::CINOSLockGuard
CINOSLockGuard(TLock &aLock, uint32 auTimeout)
Definition: inos_syn.h:929
CINOSRefCount::CINOSRefCount
CINOSRefCount(const char *apParentName, const char *apBaseName, int32 aiInitialCount=0, void *apHandlerObj=NULL, void *apHandlerFunc=NULL)
Create a reference counter with the given name.
CINOSTimeEvent::CINOSTimeEvent
CINOSTimeEvent(uint32 aTime)
CINOSTimeEvent::Stop
void Stop()
CINOSConditionVariable
Definition: inos_syn.h:367
CINOSConditionVariable::WaitFor
bool WaitFor(std::unique_lock< CINOSMutex > &lock, const std::chrono::duration< Rep, Period > &rel_time, Predicate pred)
wait for being notified waiting at most aTimeout. See http://en.cppreference.com/w/cpp/thread/conditi...
Definition: inos_syn.h:400
CINOSSync::MsgEvent
virtual bool MsgEvent(CINOSTaskExMsg *apMsg)
Definition: inos_syn.h:121
CINOSConditionVariable::CINOSConditionVariable
CINOSConditionVariable(const char *aName=nullptr)
CINOSTimeEvent
Definition: inos_syn.h:825
CINOSSync::GetName
virtual const char * GetName()
Get name of sync object.
Definition: inos_syn.h:94
CINOSQueue::GetAdrNumber
const uint32 * GetAdrNumber() const
Return address of entries counter.
Definition: inos_syn.h:601
CINOSQueue::GetNumber
uint32 GetNumber()
Get number of queue entries.
CINOSQueue::GetAdrCount
const uint64 * GetAdrCount() const
Return address of overall counter.
Definition: inos_syn.h:608
CINOSQueue::Flush
void Flush()
Flush the queue.
CINOSBitClearedEvent::Wait
virtual uint32 Wait(uint32 aTimeout=0xFFFFFFFF) override
wait for signaled state for max. aTimeout usec
CINOSSemaphore::CINOSSemaphore
CINOSSemaphore(const char *apName=0, uint32 auInitialCount=1, uint32 auMaxCount=0xffffffff)
Create a semaphore with the given name. See also Semaphore.
CINOSBitClearedEvent::Signal
virtual void Signal() override
Put object into the signaled state.
CINOSSemaphore
Definition: inos_syn.h:455
CINOSQueue::Get
uint32 Get(void *aData, uint32 aTimeout=0xFFFFFFFF)
Get data from queue and wait for max. auTimeout usec if queue empty.
CINOSReadLock
Definition: inos_syn.h:1117
CINOSMultiSync::And
void And(CINOSSync *aChild)
CINOSSync::SignalAndUnlock
void SignalAndUnlock(uint32 auMsr)
Put object into the signaled state and release the core lock.
Definition: inos_syn.h:196
CINOSSync::SignalEx
virtual void SignalEx(CINOSTaskExMsg *apMsg, uint32 auRplId, uint32 auAppError)
Definition: inos_syn.h:115
CINOSSync::m_pName
const char * m_pName
name of sync object
Definition: inos_syn.h:159
CINOSMultiSync::Or
void Or(CINOSSync *aChild)
CINOSReadWriteLock::ReadLock
void ReadLock()
Definition: inos_syn.h:1037
CINOSBitSetEvent::GetName
virtual const char * GetName() override
Get name of sync object.
Definition: inos_syn.h:722
CINOSQueue::pEnd
void * pEnd
pointer to end of queue buffer
Definition: inos_syn.h:659
CINOSConditionVariable::WaitFor
EStatus WaitFor(std::unique_lock< CINOSMutex > &lock, const std::chrono::duration< Rep, Period > &rel_time)
wait for being notified waiting at most aTimeout. See http://en.cppreference.com/w/cpp/thread/conditi...
Definition: inos_syn.h:389
CINOSConditionVariable::NotifyOne
void NotifyOne()
Wake up one waiting task See http://en.cppreference.com/w/cpp/thread/condition_variable/notify_one fo...
CINOSxmsHandler
Definition: inos_1ms.h:90
CINOSBitSetEvent::Wait
virtual uint32 Wait(uint32 aTimeout=0xFFFFFFFF) override
wait for signaled state for max. aTimeout usec
CINOSQueue::ClrFlag
void ClrFlag(uint32 auFlag)
Clear queue flag(s)
Definition: inos_syn.h:623
CINOSSemaphore::Release
void Release()
Release seamphore.
CINOSBitSetEvent
Definition: inos_syn.h:708
CINOSSemaphore::Request
uint32 Request(uint32 aTimeout=0xFFFFFFFF)
Wait for semaphore for a max. amount of time.
CINOSQueue::pSemaphore
CINOSSemaphore * pSemaphore
semaphore to handle the number of queue entries
Definition: inos_syn.h:666
CINOSSync
Definition: inos_syn.h:66
CINOSMultiSync::RemoveAll
void RemoveAll(bool aDelete=false)
CINOSQueue::~CINOSQueue
virtual ~CINOSQueue()
Destroy queue.
CINOSRefCount::GetCount
int32 GetCount()
Get current count.
CINOSRefCount::Increment
int32 Increment()
Increment the reference counter and return the new value.
DECLARE_DYNAMIC
#define DECLARE_DYNAMIC(aClass)
Definition: cinospartitionmemory.h:328
CINOSTaskExMsg
Definition: cinostaskex.h:395
CINOSQueue::mCount
uint64 mCount
overall put count
Definition: inos_syn.h:667
CINOSMultiSync::Reset
virtual void Reset() override
CINOSMultiSync
Definition: inos_syn.h:234
CINOSSync::m_idLstWaiting
tTaskId m_idLstWaiting
id of last task waiting for the sync object
Definition: inos_syn.h:163
CINOSBitSetEvent::Signal
virtual void Signal() override
Put object into the signaled state.
CINOSLockGuard
Definition: inos_syn.h:915
CINOSQueue::GetMaxNumber
const uint32 GetMaxNumber() const
Return maximum number of entries.
Definition: inos_syn.h:594
CINOSTask
Definition: cinostask.h:51