rpcs3/Utilities/Semaphore.h
Ivan da7472fe81 Optimizations (#1680)
* Optimizations

1) Some headers simplified for better compilation time
2) Some templates simplified for smaller executable size
3) Eliminate std::future to fix compilation for mingw64
4) PKG installation can be cancelled now
5) cellGame fixes
6) XAudio2 fix for mingw64
7) PPUInterpreter bug fixed (Clang)

* any_pod<> implemented

Aliases: any16, any32, any64
rsx::make_command fixed
2016-04-25 13:49:12 +03:00

41 lines
608 B
C++

#pragma once
#include "types.h"
#include "Atomic.h"
class semaphore_t
{
// semaphore mutex
std::mutex m_mutex;
// semaphore condition variable
std::condition_variable m_cv;
struct alignas(8) sync_var_t
{
u32 value; // current semaphore value
u32 waiters; // current amount of waiters
};
// current semaphore value
atomic_t<sync_var_t> m_var;
public:
// max semaphore value
const u32 max_value;
semaphore_t(u32 max_value = 1, u32 value = 0)
: m_var(sync_var_t{ value, 0 })
, max_value(max_value)
{
}
bool try_wait();
bool try_post();
void wait();
bool post_and_wait();
};