| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #pragma once
- #include <condition_variable>
- #include <initializer_list>
- #include "OperatingSystem.h"
- namespace Framework
- {
- class Thread;
- class Critical
- {
- private:
- CRITICAL_SECTION cs;
- Thread* owner;
- int lockCount;
- int id;
- public:
- //! Constructor
- DLLEXPORT Critical();
- //! Destructor
- DLLEXPORT ~Critical();
- //! Locks the object
- DLLEXPORT void lock();
- //! Tries to lock the object
- DLLEXPORT bool tryLock();
- //! Unlocks the object
- DLLEXPORT void unlock();
- //! Returns true if the object is locked
- DLLEXPORT bool isLocked() const;
- //! Returns a pointer to the thread that locked the object
- DLLEXPORT const Thread* zOwner() const;
- };
- class CriticalLock
- {
- private:
- Critical** criticals;
- int size;
- public:
- DLLEXPORT CriticalLock(std::initializer_list<Critical*> criticals);
- DLLEXPORT ~CriticalLock();
- };
- #define LOCK(x) CriticalLock _lock(x)
- #define LOCKN(x, i) CriticalLock _lock_##i(x)
- class Synchronizer
- {
- private:
- std::condition_variable block;
- std::mutex mutex;
- int numWaiting;
- bool skip;
- public:
- DLLEXPORT Synchronizer();
- DLLEXPORT ~Synchronizer();
- DLLEXPORT bool wait();
- DLLEXPORT bool wait(int milisec);
- DLLEXPORT void notify();
- DLLEXPORT void notify(int amount);
- DLLEXPORT void notifyAll();
- DLLEXPORT int getNumberOfWaitingThreads() const;
- };
- } // namespace Framework
|