AudRecordLib
|
00001 00006 #ifndef AUDRECORD_RTLRESOURCE_H 00007 #define AUDRECORD_RTLRESOURCE_H 00008 00009 #pragma once 00010 00016 typedef struct RTL_RESOURCE 00017 { 00018 CRITICAL_SECTION CSection; 00019 HANDLE hSharedSemaphore; 00020 ULONG sharedExclusive; 00021 HANDLE hExclusiveSemaphore; 00022 ULONG exclusiveWaiters; 00023 ULONG numberOfWaiters; 00024 HANDLE hOwnerThread; 00025 ULONG flags; 00026 PRTL_RESOURCE_DEBUG DebugInfo; 00027 } *PRTL_RESOURCE; 00028 00030 class RtlResource 00031 { 00032 private: 00034 RTL_RESOURCE resource; 00036 RtlResource(const RtlResource&); 00037 void operator=(const RtlResource&); 00038 public: 00039 RtlResource(); 00040 ~RtlResource(); 00041 BOOLEAN AcquireShared(BOOLEAN waitForAccess); 00042 BOOLEAN AcquireExclusive(BOOLEAN waitForAccess); 00043 void Release(); 00044 void OutputDebugText() const; 00045 }; 00046 00048 struct SharedRtlResourceLock 00049 { 00050 private: 00052 RtlResource& r; 00053 SharedRtlResourceLock(const SharedRtlResourceLock&); 00054 void operator=(const SharedRtlResourceLock&); 00055 public: 00061 SharedRtlResourceLock(RtlResource& r, BOOLEAN wait = TRUE) 00062 : r(r) 00063 { 00064 r.AcquireShared(wait); 00065 } 00066 00068 ~SharedRtlResourceLock() 00069 { 00070 r.Release(); 00071 } 00072 }; 00073 00075 struct ExclusiveRtlResourceLock 00076 { 00077 private: 00079 RtlResource& r; 00080 ExclusiveRtlResourceLock(const ExclusiveRtlResourceLock&); 00081 void operator=(const ExclusiveRtlResourceLock&); 00082 public: 00088 ExclusiveRtlResourceLock(RtlResource& r, BOOLEAN wait = TRUE) 00089 : r(r) 00090 { 00091 r.AcquireExclusive(wait); 00092 } 00093 00095 ~ExclusiveRtlResourceLock() 00096 { 00097 r.Release(); 00098 } 00099 }; 00100 00102 #endif