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//------------------------------------------------------------------------------
58class CINOSSyncNode;
59class CINOSTaskExMsg;
60class CINOSBus;
61
62//------------------------------------------------------------------------------
63//--- class CINOSSync ----------------------------------------------------------
64//------------------------------------------------------------------------------
65
67{
68 //--- user interface ---------------------------------------------------
69
70 // constructor / destructor
71 public :
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;
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)
211};
212
213//------------------------------------------------------------------------------
214//--- class CINOSSyncEx --------------------------------------------------------
215//------------------------------------------------------------------------------
216
217class CINOSSyncEx : public CINOSSync
218{
219 public :
227 ICACHE virtual void SignalEx(CINOSTaskExMsg* apMsg, uint32 auRplId, uint32 auAppError) override
228 {
229 // save reply id and app error
230 m_uRplId = auRplId;
231 m_uAppError = auAppError;
232 // call base
233 CINOSSync::SignalEx(apMsg, auRplId, auAppError);
234 };
235
239 uint32 GetRplId() const
240 {
241 return m_uRplId;
242 }
243
247 uint32 GetAppError() const
248 {
249 return m_uAppError;
250 }
251
255 uint32 GetAppErrorAndRpl() const
256 {
257 return (GetRplId() << 24) | GetAppError();
258 }
259
260 private :
262 uint32 m_uRplId{};
264 uint32 m_uAppError{};
265};
266
267//------------------------------------------------------------------------------
268//--- class CINOSMultiSync -----------------------------------------------------
269//------------------------------------------------------------------------------
270
271class CINOSExceptionCleanup;
289{
290 //--- user interface ---------------------------------------------------
291
292 // constructor / destructor
293 public :
294 CINOSMultiSync(const char* aName=0);
295 virtual ~CINOSMultiSync();
296
297 // public member functions
298 public :
301 void Or(CINOSSync* aChild);
304 void And(CINOSSync* aChild);
308 void Remove(CINOSSync* aChild, bool aDelete=false);
312 void RemoveAll(bool aDelete=false);
313
316 ICACHE virtual uint32 Wait(uint32 aTimeout=INOS_WAIT_FOREVER) override;
320 ICACHE virtual uint32 Wait(CINOSSync*& aChild, uint32 aTimeout=INOS_WAIT_FOREVER);
321
324 virtual void Reset() override;
325
326 // returns true if the event relies on polling to detect state transition.
327 // this is necessary for 'raw' handled ports.
328 virtual bool UsesPolling() const override {return m_bUsesPolling;};
329
333 CINOSBus* GetBus() { return m_pBus; }
334 void SetBus(CINOSBus* apBus) { m_pBus = apBus; }
335
336 //--- internals --------------------------------------------------------
337
338 friend class CINOSSyncNode;
339
340 // protected members
341 protected:
342 CINOSSyncNode* pFirstChild; // pointer to first child
343 CINOSSyncNode* pLastChild; // pointer to last child
344
345 // exception handling
346 CINOSExceptionCleanup* pCleanup;
347
348 // Flag indicating if bit event is detected using polling
349 bool m_bUsesPolling;
350
351 // pointer to bus (if any) used for sleep
352 CINOSBus* m_pBus;
353
354 // protected member functions
355 protected :
356 // parent checks signaled state
357 ICACHE virtual bool Signaled(CINOSSync*& aChild) override;
358 // wake up because child state changed
359 void WakeUp();
360 // cleanup
361 void Cleanup();
362
363 // allow dynamic object handling (new/delete)
365};
366
367//------------------------------------------------------------------------------
368//--- class CINOSSyncNode ------------------------------------------------------
369//------------------------------------------------------------------------------
370
372class CINOSSyncNode
373{
374 friend class CINOSSync;
375 friend class CINOSMultiSync;
376 friend class CINOSBitSetEvent;
377 friend class CINOSBitClearedEvent;
378
379 // protected members
380 protected:
381 CINOSSync* pChild; // pointer to sync object
382 CINOSMultiSync* pParent; // pointer to parent sync object
383 CINOSSyncNode* pNext; // pointer to next node on the same level
384 // for the sake of simplicity (and runtime overhead), on multicore
385 // system, we do not support 'groups' of sync nodes anymore.
386 #ifndef INOS_MULTICORE
387 CINOSSyncNode* pNextGroup; // pointer to next sync group
388 #endif
389 bool mOrNode; // 'or' node true/false
390
391 // constructor / destructor
392 public :
393 CINOSSyncNode(CINOSMultiSync* aParent, CINOSSync* aChild, bool aOrNode);
394 ~CINOSSyncNode();
395
396 // protected member functions
397 protected :
398 // child changed to signaled state -> wake up parents
399 ICACHE void WakeUp();
400
401 // allow dynamic object handling (new/delete)
402 DECLARE_DYNAMIC(CINOSSyncNode);
403};
405
406
407//------------------------------------------------------------------------------
408//--- class CINOSConditionVariable ---------------------------------------------
409//------------------------------------------------------------------------------
410#include <mutex>
422{
423 public :
424 enum EStatus {
425 eNoTimeout,
426 eTimeout
427 };
428
433 CINOSConditionVariable(const char* aName=nullptr);
434
438
439 public :
442 template< class Rep, class Period >
443 EStatus WaitFor(std::unique_lock<CINOSMutex>& lock,
444 const std::chrono::duration<Rep, Period>& rel_time)
445 {
446 uint32 waitUs = std::chrono::duration_cast<std::chrono::microseconds>(rel_time).count();
447 const uint32 uWaitTime = DoWait(lock, waitUs);
448 return (uWaitTime == 0) ? eTimeout : eNoTimeout;
449 }
450
453 template< class Rep, class Period, class Predicate >
454 bool WaitFor( std::unique_lock<CINOSMutex>& lock,
455 const std::chrono::duration<Rep, Period>& rel_time,
456 Predicate pred) {
457 uint32 waitUs = checked_static_cast<uint32>(std::chrono::duration_cast<std::chrono::microseconds>(rel_time).count());
458 while( !pred() ) {
459 uint32 uWaitTime = DoWait(lock, waitUs);
460 if( !uWaitTime ) {
461 // timeout occurred
462 return false;
463 }
464 waitUs = (waitUs - uWaitTime) > 0 ? waitUs - uWaitTime : 0;
465 }
466 return true;
467 }
468
471 void Wait( std::unique_lock<CINOSMutex>& lock ) {
472 DoWait(lock);
473 }
474
477 template< class Predicate >
478 void wait( std::unique_lock<CINOSMutex>& lock, Predicate pred ) {
479 while( !pred() ) {
480 DoWait(lock);
481 }
482 }
483
486 void NotifyOne();
489 void NotifyAll();
490
491 private:
494 uint32 DoWait(std::unique_lock<CINOSMutex>& lock, uint32 auTimeout = INOS_WAIT_FOREVER);
495
496 // allow dynamic object handling (new/delete)
498 // objects of CINOSConditionVariable need to be created very early during startup, when
499 // the CTORs have not been executed. Therefore, in order to create such
500 // objects, we need to provide the placement operator new.
502
503};
504
505//------------------------------------------------------------------------------
506//--- class CINOSSemaphore -----------------------------------------------------
507//------------------------------------------------------------------------------
508
510{
511 //--- user interface ---------------------------------------------------
512
513 // public members
514 public :
521 const char* apName = 0,
522 uint32 auInitialCount = 1,
523 uint32 auMaxCount = 0xffffffff
524 );
525
529
536 ICACHE uint32 Request(uint32 aTimeout=INOS_WAIT_FOREVER);
537
540 ICACHE void Release();
541
544 uint32 GetCount()
545 { return m_uCount; }
546
549 uint32 GetMaxCount()
550 { return m_uMaxCount; }
551
552 //--- internals --------------------------------------------------------
553
554 private:
556 uint32 m_uMaxCount;
557
558 // allow dynamic object handling (new/delete)
560};
561
562//------------------------------------------------------------------------------
563//--- class CINOSQueue ---------------------------------------------------------
564//------------------------------------------------------------------------------
565
566class CINOSQueue : public CINOSSync
567{
568 //--- user interface ---------------------------------------------------
569
570 // public members
571 public :
577 // create a queue with 'aNumber' entries of 'aSize' bytes
578 CINOSQueue(const char* apName, uint32 auNumber, uint32 auSize);
579
582 virtual ~CINOSQueue();
583
592 ICACHE uint32 Put(void* aData, uint32 aTimeout=INOS_WAIT_FOREVER, uint32 auFlags=0);
593
601 ICACHE uint32 Get(void* aData, uint32 aTimeout=INOS_WAIT_FOREVER);
602
610 void Inquiry(void* aData, uint32& aCountOfElements);
611
622 bool InquiryAt(void* aData, uint32 auIndex);
623
626 void Flush();
627
631 bool Empty();
632
636 uint32 GetNumber();
637
641 const uint32 GetSize() const {
642 return mSize;
643 }
644
648 const uint32 GetMaxNumber() const {
649 return mMaxNumber;
650 }
651
655 const uint32* GetAdrNumber() const {
656 return &mNumber;
657 }
658
662 const uint64* GetAdrCount() const {
663 return &mCount;
664 }
665
669 void SetFlag(uint32 auFlag)
670 {
671 mQueueFlags |= auFlag;
672 }
673
677 void ClrFlag(uint32 auFlag)
678 {
679 mQueueFlags &= ~auFlag;
680 }
681
685 uint32 BeginAccess();
686
692 bool Access(void*&ptrData, uint32 auIndex);
693
697 void EndAccess(uint32 msr);
698
701 enum {
702 eFlgOverflowCheck = 0x00000001, // check queue overflows
703 eFlgOverflowFatal = 0x00000002, // fatal error in case of an overflow
704 eFlgAccess = 0x00000004, // data access active (queue locked)
705 eFlgUnique = 0x00000008, // only allow unique entries in queue
706 };
707
708 //--- internals --------------------------------------------------------
709
710 // protected members
711 protected :
712 void* pBegin;
713 void* pEnd;
714 void* pPut;
715 void* pGet;
716 uint32 mNumber;
717 uint32 mSize;
718 uint32 mMaxNumber;
719 uint32 mQueueFlags;
721 uint64 mCount;
722
723 // allow dynamic object handling (new/delete)
725};
726
727// include task queue handling
728#include <cinostaskqueue.h>
729
730//------------------------------------------------------------------------------
731//--- class CINOSEvent ---------------------------------------------------------
732//------------------------------------------------------------------------------
733
734class CINOSEvent : public CINOSSync
735{
736 //--- user interface ---------------------------------------------------
737
738 // constructor / destructor
739 public :
741 const char* aName=0,
742 uint32 aInitialCount=0,
743 bool aManual=false
744 );
745 virtual ~CINOSEvent();
746
747 //--- internals --------------------------------------------------------
748
749 friend class CINOSBitSetEvent;
750 friend class CINOSBitClearedEvent;
751
752 // allow dynamic object handling (new/delete)
754};
755
756//------------------------------------------------------------------------------
757//--- class CINOSBitSetEvent ---------------------------------------------------
758//------------------------------------------------------------------------------
759
760#ifndef INOS_NO_BIT_EVENT_SUPPORT
761class CINOSBit;
763{
764 friend class CINOSBit;
765
766 //--- user interface ---------------------------------------------------
767
768 // constructor / destructor
769 public :
771 virtual ~CINOSBitSetEvent();
772
773 // public member functions
774 public :
775 // get name of sync object
776 virtual const char* GetName() override {return m_pEvent->GetName();};
777 // wait for signaled state for max. aTimeout usec
778 virtual uint32 Wait(uint32 aTimeout=INOS_WAIT_FOREVER) override ;
779 // put object into the signaled state
780 virtual void Signal() override ;
781 // reset object state
782 virtual void Reset() override ;
783 // returns true if the event relies on polling to detect state transition.
784 // this is necessary for 'raw' handled ports.
785 virtual bool UsesPolling() const override {return m_bUsesPolling;};
786
787 //--- internals --------------------------------------------------------
788
789 // protected members
790 protected :
791 CINOSBit* m_pBit;
792 CINOSEvent* m_pEvent;
793
794 // exception handling
795 CINOSExceptionCleanup* m_pCleanup;
796
797 // Flag indicating if bit event is detected using polling
798 bool m_bUsesPolling;
799
800 // protected member functions
801 protected :
802 // parent checks signaled state
803 virtual bool Signaled(CINOSSync*& aChild) override;
804 // get pointer to object node
805 virtual CINOSSyncNode* GetNode() override {return m_pEvent->GetNode();};
806 // set pointer to object node
807 virtual void SetNode(CINOSSyncNode* aNode) override {m_pEvent->SetNode(aNode);};
808 // cleanup
809 void Cleanup();
810
811 // allow dynamic object handling (new/delete)
813};
814
815//------------------------------------------------------------------------------
816//--- class CINOSBitClearedEvent -----------------------------------------------
817//------------------------------------------------------------------------------
818
820{
821 friend class CINOSBit;
822
823 //--- user interface ---------------------------------------------------
824
825 // constructor / destructor
826 public :
828 virtual ~CINOSBitClearedEvent();
829
830 // public member functions
831 public :
832 // get name of sync object
833 virtual const char* GetName() override {return m_pEvent->GetName();};
834 // wait for signaled state for max. aTimeout usec
835 virtual uint32 Wait(uint32 aTimeout=INOS_WAIT_FOREVER) override ;
836 // put object into the signaled state
837 virtual void Signal() override ;
838 // reset object state
839 virtual void Reset() override ;
840 // returns true if the event relies on polling to detect state transition.
841 // this is necessary for 'raw' handled ports.
842 virtual bool UsesPolling() const override {return m_bUsesPolling;};
843
844 //--- internals --------------------------------------------------------
845
846 // protected members
847 protected :
848 CINOSBit* m_pBit;
849 CINOSEvent* m_pEvent;
850
851 // exception handling
852 CINOSExceptionCleanup* m_pCleanup;
853
854 // Flag indicating if bit event is detected using polling
855 bool m_bUsesPolling;
856
857 // protected member functions
858 protected :
859 // parent checks signaled state
860 virtual bool Signaled(CINOSSync*& aChild) override ;
861 // get pointer to object node
862 virtual CINOSSyncNode* GetNode() override {return m_pEvent->GetNode();};
863 // set pointer to object node
864 virtual void SetNode(CINOSSyncNode* aNode) override {m_pEvent->SetNode(aNode);};
865 // cleanup
866 void Cleanup();
867
868 // allow dynamic object handling (new/delete)
870};
871#endif
872
873//------------------------------------------------------------------------------
874//--- class CINOSTimeEvent -----------------------------------------------------
875//------------------------------------------------------------------------------
876
877#ifndef INOS_NO_1MS_SUPPORT
878class CINOSxmsHandler;
880{
881 //--- user interface ---------------------------------------------------
882
883 // constructor / destructor
884 public :
885 enum {
886 eEventDisabled = 0,
887 eUsePreviousTime = 0
888 };
889
894 CINOSTimeEvent(uint32 aTime);
895 virtual ~CINOSTimeEvent();
896
897 // public member functions
898 public :
899 // reset event with new time (time = 0 -> reset with old time)
900 void Reset(uint32 aTime=eUsePreviousTime);
905 void Stop();
906 // start event with new time (time = 0 -> reset with old time)
907 void Start(uint32 aTime=eUsePreviousTime);
908
909 //--- internals --------------------------------------------------------
910
911 private:
914 void iAddHandler();
915 void iRemoveHandler();
916
917 // protected members
918 protected :
919 uint32 mWaitTime = eEventDisabled;
920 CINOSxmsHandler* pHandler = nullptr;
921 // exception handling
922 CINOSExceptionCleanup* pCleanup = nullptr;
923
924 // protected member functions
925 protected :
926 // event handler
927 void Handler();
928 // cleanup
929 void Cleanup();
930
931 // allow dynamic object handling (new/delete)
933};
934
935#endif
936
937//--------------------------------------------------------------------------
938// CINOSSyncObjects
939//--------------------------------------------------------------------------
940
942class CINOSSyncObjects
943{
944 //--- user interface ---------------------------------------------------
945
946 public :
947 // add sync object to the tree
948 void Add(CINOSSync* aSync);
949 // find sync object 'aName'
950 CINOSSync* Find(char* aName);
951
952 //--- internals --------------------------------------------------------
953
954 private :
955 // tree of all objects in the system
956 TINOSNameBalancedBinaryTree<CINOSSync>* pSyncObjects;
957
958 // constructor
959 public:
960 CINOSSyncObjects() ;
961};
963
964//--------------------------------------------------------------------------
965// CINOSLockGuard
966//--------------------------------------------------------------------------
967
968template<typename TLock>
970{
971 //--- user interface ---------------------------------------------------
972
973 public :
976 CINOSLockGuard(TLock& aLock):
977 m_Lock(aLock), m_bLocked(false)
978 {
979 m_bLocked = (m_Lock.Request() != 0);
980 }
983 CINOSLockGuard(TLock& aLock, uint32 auTimeout/*usec*/):
984 m_Lock(aLock), m_bLocked(false)
985 {
986 m_bLocked = (m_Lock.Request(auTimeout) != 0);
987 }
989 if (m_bLocked) m_Lock.Release();
990 }
991 bool IsLocked() const {
992 return m_bLocked;
993 }
994
995 //--- internals --------------------------------------------------------
996
997 private :
998 // Lock to be guarded
999 TLock& m_Lock;
1000 // Flag indicating if the lock is held
1001 bool m_bLocked;
1002};
1003
1004typedef CINOSLockGuard<CINOSSemaphore> CINOSSemaphoreGuard;
1005
1006//------------------------------------------------------------------------------
1007//--- class CINOSRefCount ------------------------------------------------------
1008//------------------------------------------------------------------------------
1009
1015{
1016 //--- user interface ---------------------------------------------------
1017
1018 // public members
1019 public :
1026 const char* apParentName,
1027 const char* apBaseName,
1028 int32 aiInitialCount = 0,
1029 void* apHandlerObj = NULL,
1030 void* apHandlerFunc = NULL
1031 );
1032
1036
1039 int32 Increment();
1040
1043 int32 Decrement();
1044
1047 int32 GetCount();
1048
1051 void SetCount(int32 aiNewCount);
1052
1053 //--- internals --------------------------------------------------------
1054
1055 protected :
1056
1059 friend class CINOSLockGuard<CINOSRefCount>;
1060 uint32 Request();
1061 void Release();
1062
1063 protected :
1065 inosName32 m_sName;
1070 void* m_pHandlerFunc;
1071
1072 // allow dynamic object handling (new/delete)
1074};
1075
1077
1079
1080//------------------------------------------------------------------------------
1081//--- class CINOSReadWriteLock -------------------------------------------------
1082//------------------------------------------------------------------------------
1087 public:
1091 void ReadLock() {
1092 std::unique_lock<CINOSMutex> lock(m_Mutex);
1093 while (HasForeignWriter()) {
1094 m_Unlocked.wait(lock, [this]() { return !HasForeignWriter(); });
1095 }
1096 m_uReaders++;
1097 }
1099 void ReadUnlock() {
1100 std::unique_lock<CINOSMutex> lock(m_Mutex);
1101 m_uReaders--;
1102 if (m_uReaders == 0)
1103 m_Unlocked.NotifyAll();
1104 }
1109 void WriteLock() {
1110 std::unique_lock<CINOSMutex> lock(m_Mutex);
1111 while (HasForeignWriter() || HasReaders()) {
1112 m_Unlocked.wait(lock, [this]() { return !(HasForeignWriter() || HasReaders()); });
1113 }
1114 ++m_nWriter;
1115 m_pWriter = ActualTask();
1116 }
1119 std::unique_lock<CINOSMutex> lock(m_Mutex);
1120 --m_nWriter;
1121 if (m_nWriter == 0) {
1122 m_pWriter = nullptr;
1123 m_Unlocked.NotifyAll();
1124 }
1125 }
1126 private:
1127 bool HasReaders() const {
1128 return m_uReaders > 0;
1129 }
1130 bool HasForeignWriter() const {
1131 const bool bHasWriter = m_nWriter > 0;
1132 const bool bWriterIsMe = ActualTask() == m_pWriter;
1133 return bHasWriter && !bWriterIsMe;
1134 }
1135 private:
1137 size_t m_uReaders{};
1140 size_t m_nWriter{0};
1142 CINOSTask* m_pWriter{nullptr};
1144 CINOSMutex m_Mutex;
1147 CINOSConditionVariable m_Unlocked;
1148};
1149//------------------------------------------------------------------------------
1150//--- class CINOSWriteLock -----------------------------------------------------
1151//------------------------------------------------------------------------------
1155 public:
1157 : m_Lock(aLock)
1158 {
1159 m_Lock.WriteLock();
1160 }
1161 ~CINOSWriteLock() {
1162 m_Lock.WriteUnlock();
1163 }
1164 CINOSReadWriteLock& m_Lock;
1165};
1166//------------------------------------------------------------------------------
1167//--- class CINOSReadLock ------------------------------------------------------
1168//------------------------------------------------------------------------------
1172 public:
1174 : m_Lock(aLock)
1175 {
1176 m_Lock.ReadLock();
1177 }
1178 ~CINOSReadLock() {
1179 m_Lock.ReadUnlock();
1180 }
1181 CINOSReadWriteLock& m_Lock;
1182};
1183
1184//--------------------------------------------------------------------------
1185// global variables
1186//--------------------------------------------------------------------------
1187
1188extern CINOSSyncObjects* pINOSSyncObjects; // binary tree of INOS sync objects
1189
1190#endif // __INOS_SYN_H
1191
#define DECLARE_DYNAMIC_PLACEMENT(aClass)
Definition cinospartitionmemory.h:348
#define DECLARE_DYNAMIC(aClass)
Definition cinospartitionmemory.h:328
Definition inos_syn.h:820
virtual void Signal() override
Put object into the signaled state.
virtual const char * GetName() override
Get name of sync object.
Definition inos_syn.h:833
virtual void Reset() override
Reset object state.
virtual uint32 Wait(uint32 aTimeout=0xFFFFFFFF) override
wait for signaled state for max. aTimeout usec
Definition inos_syn.h:763
virtual uint32 Wait(uint32 aTimeout=0xFFFFFFFF) override
wait for signaled state for max. aTimeout usec
virtual const char * GetName() override
Get name of sync object.
Definition inos_syn.h:776
virtual void Reset() override
Reset object state.
virtual void Signal() override
Put object into the signaled state.
Definition cinosbit.h:54
Definition cinosbus.h:565
Definition inos_syn.h:422
void NotifyAll()
Wake up all waiting tasks See http://en.cppreference.com/w/cpp/thread/condition_variable/notify_all f...
virtual ~CINOSConditionVariable()
Destroy condition variable object.
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:471
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:478
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:454
CINOSConditionVariable(const char *aName=nullptr)
void NotifyOne()
Wake up one waiting task See http://en.cppreference.com/w/cpp/thread/condition_variable/notify_one fo...
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:443
Definition inos_syn.h:735
Definition inoskernel.h:229
Definition inos_syn.h:970
CINOSLockGuard(TLock &aLock)
Definition inos_syn.h:976
CINOSLockGuard(TLock &aLock, uint32 auTimeout)
Definition inos_syn.h:983
Definition inos_syn.h:289
virtual uint32 Wait(CINOSSync *&aChild, uint32 aTimeout=0xFFFFFFFF)
CINOSBus * GetBus()
Definition inos_syn.h:333
void Remove(CINOSSync *aChild, bool aDelete=false)
void And(CINOSSync *aChild)
void Or(CINOSSync *aChild)
virtual uint32 Wait(uint32 aTimeout=0xFFFFFFFF) override
virtual void Reset() override
void RemoveAll(bool aDelete=false)
Definition cinosmutex.h:36
Definition inos_syn.h:567
const uint32 * GetAdrNumber() const
Return address of entries counter.
Definition inos_syn.h:655
void * pGet
pointer to actual get block
Definition inos_syn.h:715
void ClrFlag(uint32 auFlag)
Clear queue flag(s)
Definition inos_syn.h:677
const uint32 GetSize() const
Return size of one queue entry.
Definition inos_syn.h:641
void * pPut
pointer to actual put block
Definition inos_syn.h:714
void EndAccess(uint32 msr)
EndAccess Needs to be called after Access.
void Flush()
Flush the queue.
const uint32 GetMaxNumber() const
Return maximum number of entries.
Definition inos_syn.h:648
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...
void Inquiry(void *aData, uint32 &aCountOfElements)
Gets the first element without removing it from the queue. Moreover, aCountOfElements returns the num...
const uint64 * GetAdrCount() const
Return address of overall counter.
Definition inos_syn.h:662
CINOSSemaphore * pSemaphore
semaphore to handle the number of queue entries
Definition inos_syn.h:720
uint32 mSize
size of block in queue
Definition inos_syn.h:717
uint32 BeginAccess()
BeginAccess Needs to be called before Access.
bool InquiryAt(void *aData, uint32 auIndex)
Gets the element at auIndex (starting from 0..numberOfElementsInQueue) without removing it from the q...
uint32 Put(void *aData, uint32 aTimeout=0xFFFFFFFF, uint32 auFlags=0)
Put data to queue and wait for max. auTimeout usec if queue full.
void SetFlag(uint32 auFlag)
Set queue flag(s)
Definition inos_syn.h:669
uint32 GetNumber()
Get number of queue entries.
uint32 mMaxNumber
maximum number of blocks in queue
Definition inos_syn.h:718
uint32 Get(void *aData, uint32 aTimeout=0xFFFFFFFF)
Get data from queue and wait for max. auTimeout usec if queue empty.
uint32 mQueueFlags
queue flags
Definition inos_syn.h:719
void * pBegin
pointer to begin of queue buffer
Definition inos_syn.h:712
uint64 mCount
overall put count
Definition inos_syn.h:721
bool Empty()
Get queue state.
virtual ~CINOSQueue()
Destroy queue.
void * pEnd
pointer to end of queue buffer
Definition inos_syn.h:713
uint32 mNumber
actual number of blocks in queue
Definition inos_syn.h:716
CINOSQueue(const char *apName, uint32 auNumber, uint32 auSize)
Create a queue with the given name. See also Queue.
Definition inos_syn.h:1171
Definition inos_syn.h:1086
void ReadLock()
Definition inos_syn.h:1091
void WriteLock()
Definition inos_syn.h:1109
void ReadUnlock()
Definition inos_syn.h:1099
void WriteUnlock()
Definition inos_syn.h:1118
Definition inos_syn.h:1015
int32 Increment()
Increment the reference counter and return the new value.
int32 GetCount()
Get current count.
void * m_pHandlerObj
Handler method to call when count reaches 0.
Definition inos_syn.h:1069
virtual ~CINOSRefCount()
Destroy reference counter.
void SetCount(int32 aiNewCount)
Set current count.
int32 Decrement()
Decrement the reference counter and return the new value.
inosName32 m_sName
Reference counter name (for debugging purposes)
Definition inos_syn.h:1065
CINOSRefCount(const char *apParentName, const char *apBaseName, int32 aiInitialCount=0, void *apHandlerObj=NULL, void *apHandlerFunc=NULL)
Create a reference counter with the given name.
int32 m_iCount
Reference count.
Definition inos_syn.h:1067
Definition inos_syn.h:510
virtual ~CINOSSemaphore()
Destroy semaphore.
void Release()
Release seamphore.
uint32 GetMaxCount()
Get max. allowed count.
Definition inos_syn.h:549
uint32 Request(uint32 aTimeout=0xFFFFFFFF)
Wait for semaphore for a max. amount of time.
CINOSSemaphore(const char *apName=0, uint32 auInitialCount=1, uint32 auMaxCount=0xffffffff)
Create a semaphore with the given name. See also Semaphore.
uint32 GetCount()
Get current count.
Definition inos_syn.h:544
Definition inos_syn.h:218
uint32 GetRplId() const
Definition inos_syn.h:239
uint32 GetAppErrorAndRpl() const
Definition inos_syn.h:255
virtual void SignalEx(CINOSTaskExMsg *apMsg, uint32 auRplId, uint32 auAppError) override
Definition inos_syn.h:227
uint32 GetAppError() const
Definition inos_syn.h:247
Definition inos_syn.h:67
virtual ~CINOSSync()
Destroy sync object.
CINOSSync(const char *aName=0, uint32 aInitialCount=0, bool aManual=false)
virtual const char * GetName()
Get name of sync object.
Definition inos_syn.h:94
tTaskId m_idFstWaiting
id of first task waiting for the sync object
Definition inos_syn.h:162
virtual void SignalEx(CINOSTaskExMsg *apMsg, uint32 auRplId, uint32 auAppError)
Definition inos_syn.h:115
SINOSCoreLock m_Lock
core lock
Definition inos_syn.h:164
CINOSSyncNode * m_pNode
pointer to object node (if any)
Definition inos_syn.h:165
virtual bool MsgEvent(CINOSTaskExMsg *apMsg)
Definition inos_syn.h:121
const char * m_pName
name of sync object
Definition inos_syn.h:159
void SignalAndUnlock(uint32 auMsr)
Put object into the signaled state and release the core lock.
Definition inos_syn.h:196
virtual uint32 Wait(uint32 aTimeout=0xFFFFFFFF)
wait for signaled state for max. aTimeout usec
virtual void Signal()
Put object into the signaled state.
Definition inos_syn.h:106
tTaskId m_idLstWaiting
id of last task waiting for the sync object
Definition inos_syn.h:163
virtual void Reset()
Reset object state.
uint32 m_uCount
signaled count of object
Definition inos_syn.h:160
volatile uint32 * GetLockAdr()
Return pointer to core locking structure.
Definition inos_syn.h:130
bool m_bManual
manual object yes/no
Definition inos_syn.h:161
Definition cinostaskex.h:396
Definition cinostask.h:52
Definition inos_syn.h:880
CINOSTimeEvent(uint32 aTime)
Definition inos_syn.h:1154
Definition inos_1ms.h:91
CINOSTask * ActualTask()
Definition inostype.h:258
Definition inostype.h:192