2021-06-27 21:25:29 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
2022-11-17 07:46:07 +00:00
|
|
|
File: AuSemaphore.Generic.hpp
|
2021-06-27 21:25:29 +00:00
|
|
|
Date: 2021-6-12
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
2022-11-17 07:46:07 +00:00
|
|
|
#include "AuSemaphore.NT.hpp"
|
2022-12-28 23:44:45 +00:00
|
|
|
#elif defined(AURORA_IS_LINUX_DERIVED)
|
|
|
|
#include "AuSemaphore.Linux.hpp"
|
2021-06-27 21:25:29 +00:00
|
|
|
#elif defined(AURORA_HAS_PTHREADS)
|
2022-11-17 07:46:07 +00:00
|
|
|
#include "AuSemaphore.Unix.hpp"
|
2021-06-27 21:25:29 +00:00
|
|
|
#else
|
|
|
|
#define _AURUNTIME_GENERIC_SEMAPHORE
|
|
|
|
|
|
|
|
namespace Aurora::Threading::Primitives
|
|
|
|
{
|
|
|
|
class Semaphore : public ISemaphore
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Semaphore(long intialValue = 0);
|
|
|
|
~Semaphore();
|
|
|
|
|
|
|
|
bool HasOSHandle(AuMach &mach) override;
|
|
|
|
bool HasLockImplementation() override;
|
|
|
|
bool TryLock() override;
|
|
|
|
bool Lock(AuUInt64 timeout) override;
|
|
|
|
void Lock() override;
|
2023-08-18 14:25:54 +00:00
|
|
|
void Unlock(AuUInt16 count) override;
|
2021-06-27 21:25:29 +00:00
|
|
|
void Unlock() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::atomic_long value_{};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|