Serious-Engine/Sources/Engine/Base/Synchronization.h
Ryan C. Gordon 24cb244d43 First attempt to hand-merge Ryan's Linux and Mac OS X port.
This was a _ton_ of changes, made 15 years ago, so there are probably some
problems to work out still.

Among others: Engine/Base/Stream.* was mostly abandoned and will need to be
re-ported.

Still, this is a pretty good start, and probably holds a world record for
lines of changes or something.  :)
2016-03-28 23:46:13 -04:00

45 lines
1.3 KiB
C++

/* Copyright (c) 2002-2012 Croteam Ltd. All rights reserved. */
#ifndef SE_INCL_SYNCHRONIZATION_H
#define SE_INCL_SYNCHRONIZATION_H
#ifdef PRAGMA_ONCE
#pragma once
#endif
// intra-process mutex (only used by thread of same process)
class CTCriticalSection {
public:
// !!! FIXME : rcg10142001 This would be better with a real subclass,
// !!! FIXME : and not void pointers.
void *cs_pvObject; // object is internal to implementation
INDEX cs_iIndex; // index of mutex used to prevent deadlock with assertions
// use numbers from 1 and above for deadlock control, or -1 for no deadlock control
ENGINE_API CTCriticalSection(void);
ENGINE_API ~CTCriticalSection(void);
INDEX Lock(void);
INDEX TryToLock(void);
INDEX Unlock(void);
private:
ULONG LockCounter;
ULONG owner;
};
// lock object for locking a mutex with automatic unlocking
class CTSingleLock {
public:
CTCriticalSection &sl_cs; // the mutex this object refers to
BOOL sl_bLocked; // set while locked
INDEX sl_iLastLockedIndex; // index of mutex that was locked before this lock
ENGINE_API CTSingleLock(CTCriticalSection *pcs, BOOL bLock);
ENGINE_API ~CTSingleLock(void);
ENGINE_API void Lock(void);
ENGINE_API BOOL TryToLock(void);
ENGINE_API BOOL IsLocked(void);
ENGINE_API void Unlock(void);
};
#endif /* include-once check. */