rpcsx/rpcs3/Emu/SysCalls/lv2/sys_mutex.h

50 lines
1.1 KiB
C
Raw Normal View History

#pragma once
struct sys_mutex_attribute
{
be_t<u32> protocol; // SYS_SYNC_FIFO, SYS_SYNC_PRIORITY or SYS_SYNC_PRIORITY_INHERIT
be_t<u32> recursive; // SYS_SYNC_RECURSIVE or SYS_SYNC_NOT_RECURSIVE
be_t<u32> pshared; // always 0x200 (not shared)
be_t<u32> adaptive;
be_t<u64> ipc_key;
be_t<int> flags;
be_t<u32> pad;
union
{
char name[8];
u64 name_u64;
};
};
struct Mutex
{
2014-12-23 00:31:11 +01:00
atomic_le_t<u32> id;
atomic_le_t<u32> owner;
2014-12-24 00:38:13 +01:00
std::atomic<u32> recursive_count; // recursive locks count
std::atomic<u32> cond_count; // count of condition variables associated
2014-12-24 00:38:13 +01:00
sleep_queue_t queue;
const u32 protocol;
const bool is_recursive;
Mutex(u32 protocol, bool is_recursive, u64 name)
: protocol(protocol)
, is_recursive(is_recursive)
2014-12-23 00:31:11 +01:00
, queue(name)
, cond_count(0)
{
2014-12-23 00:31:11 +01:00
owner.write_relaxed(0);
}
2014-03-07 22:31:08 +01:00
2014-08-22 16:21:55 +02:00
~Mutex();
};
2014-12-23 00:31:11 +01:00
class PPUThread;
// SysCalls
2014-12-23 00:31:11 +01:00
s32 sys_mutex_create(PPUThread& CPU, vm::ptr<u32> mutex_id, vm::ptr<sys_mutex_attribute> attr);
s32 sys_mutex_destroy(PPUThread& CPU, u32 mutex_id);
s32 sys_mutex_lock(PPUThread& CPU, u32 mutex_id, u64 timeout);
s32 sys_mutex_trylock(PPUThread& CPU, u32 mutex_id);
s32 sys_mutex_unlock(PPUThread& CPU, u32 mutex_id);