diff options
author | Adam <you@example.com> | 2020-05-17 05:51:50 +0200 |
---|---|---|
committer | Adam <you@example.com> | 2020-05-17 05:51:50 +0200 |
commit | e611b132f9b8abe35b362e5870b74bce94a1e58e (patch) | |
tree | a5781d2ec0e085eeca33cf350cf878f2efea6fe5 /public/sdk/inc/resource.hxx | |
download | NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.gz NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.bz2 NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.lz NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.xz NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.zst NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.zip |
Diffstat (limited to '')
-rw-r--r-- | public/sdk/inc/resource.hxx | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/public/sdk/inc/resource.hxx b/public/sdk/inc/resource.hxx new file mode 100644 index 000000000..3b61133d5 --- /dev/null +++ b/public/sdk/inc/resource.hxx @@ -0,0 +1,211 @@ +//+----------------------------------------------------------------------- +// +// File: resource.hxx +// +// Contents: CResource, CReadLock, CWriteLock, +// CSafeReadLock, CSafeWriteLock. +// +// +// History: 8 Mar 93 WadeR Created. +// 08-Jul-93 WadeR Moved from security to common +// 18-Nov-93 WadeR Made inline, added Safe locks +// +//------------------------------------------------------------------------ + +#ifndef _INC_RESOURCE_HXX_ +#define _INC_RESOURCE_HXX_ + +extern "C" +{ +#include <nt.h> +#include <ntrtl.h> +#include <nturtl.h> +} +#include <except.hxx> + +//+----------------------------------------------------------------- +// +// Class: CResource +// +// Purpose: Allows multiple readers or single writer at a resource. +// +// Interface: [CResource] -- +// [~CResource] -- +// [GetRead] -- +// [GetWrite] -- +// [ReadToWrite] -- +// [WriteToRead] -- +// [Release] -- +// +// History: 24-Feb-93 WadeR Created. +// +// Notes: This wrapper will allow starving writers, since it just +// passes everything through to the RTL Resource code, which +// allows starving writers. +// +//------------------------------------------------------------------ +class CResource +{ + RTL_RESOURCE _rResource; +public: + CResource(); + ~CResource(); + void Release(); + void GetRead(); + void GetWrite(); + void ReadToWrite(); + void WriteToRead(); +}; + + +inline +CResource::CResource() +{ + RtlInitializeResource( &_rResource ); +} + +inline +CResource::~CResource() +{ + RtlDeleteResource( &_rResource ); +} + +inline +void CResource::Release() +{ + RtlReleaseResource( &_rResource ); +} + +inline +void CResource::GetRead() +{ + RtlAcquireResourceShared( &_rResource, TRUE ); +} + +inline +void CResource::GetWrite() +{ + RtlAcquireResourceExclusive( &_rResource, TRUE ); +} + +inline +void CResource::ReadToWrite() +{ + RtlConvertSharedToExclusive( &_rResource ); +} + +inline +void CResource::WriteToRead() +{ + RtlConvertExclusiveToShared( &_rResource ); +} + + + +//+--------------------------------------------------------------------------- +// +// Class: CReadLock +// +// Purpose: Lock using a Resource monitor +// +// History: 24-Feb-93 WadeR Created. +// +// Notes: Simple lock object to be created on the stack. +// The constructor acquires the resource, the destructor +// (called when lock is going out of scope) releases it. +// +//---------------------------------------------------------------------------- + +class CReadLock +{ +public: + CReadLock ( CResource& r ) : _r(r) + { _r.GetRead(); }; + ~CReadLock () + { _r.Release(); }; +private: + CResource& _r; +}; + + +//+--------------------------------------------------------------------------- +// +// Class: CWriteLock +// +// Purpose: Lock using a Resource monitor +// +// History: 24-Feb-93 WadeR Created. +// +// Notes: Simple lock object to be created on the stack. +// The constructor acquires the resource, the destructor +// (called when lock is going out of scope) releases it. +// +//---------------------------------------------------------------------------- + +class CWriteLock +{ +public: + CWriteLock ( CResource& r ) : _r(r) + { _r.GetWrite(); }; + ~CWriteLock () + { _r.Release(); }; +private: + CResource& _r; +}; + + +//+--------------------------------------------------------------------------- +// +// Class: CSafeReadLock +// +// Purpose: Exception safe lock using a Resource monitor +// +// History: 24-Feb-93 WadeR Created. +// +// Notes: Simple lock object to be created on the stack. +// The constructor acquires the resource, the destructor +// (called when lock is going out of scope) releases it. +// +//---------------------------------------------------------------------------- + +class CSafeReadLock : INHERIT_UNWIND +{ + INLINE_UNWIND(CSafeReadLock); + +public: + CSafeReadLock ( CResource& r ) : _r(r) + { _r.GetRead(); END_CONSTRUCTION (CSafeReadLock); }; + ~CSafeReadLock () + { _r.Release(); }; +private: + CResource& _r; +}; + + +//+--------------------------------------------------------------------------- +// +// Class: CSafeWriteLock +// +// Purpose: Exception safe lock using a Resource monitor +// +// History: 24-Feb-93 WadeR Created. +// +// Notes: Simple lock object to be created on the stack. +// The constructor acquires the resource, the destructor +// (called when lock is going out of scope) releases it. +// +//---------------------------------------------------------------------------- + +class CSafeWriteLock : INHERIT_UNWIND +{ + INLINE_UNWIND(CSafeWriteLock); + +public: + CSafeWriteLock ( CResource& r ) : _r(r) + { _r.GetWrite(); END_CONSTRUCTION (CSafeWriteLock); }; + ~CSafeWriteLock () + { _r.Release(); }; +private: + CResource& _r; +}; +#endif // _INC_RESOURCE_HXX_ |