rpcsx/rpcs3/Emu/SysCalls/lv2/sys_mutex.h
Alexandro Sánchez Bach 08d61163ea Removed external functions from SysCalls.h
* Replace `int` with `s32` as return type for syscalls.
* Renamed `SC_Something.*` files with the proper lv2 name
`sys_something.*`.
* Moving away from the lv2, those functions and folders that doesn't
correspond to lv2 functions. E.g. module functions from sys_io,
sysPrxForUser, cellGcmSys.
* Splitted some files (memory -> memory+mmapper) and merged other ones
(event+event_flag ->event, spu+spu_thread -> spu), according to common
sense, PSDevWiki docs, and checking firmware files.
* Removed external functions from `SysCalls.h`.

NOTE: What should we do about: cellGcmCallback? It's not a lv2 syscall
but it appears on the sc_table and it is actually called in games. Is
this some kind of hack?
2014-07-06 16:23:37 +02:00

63 lines
1.4 KiB
C++

#pragma once
#include "sys_lwmutex.h"
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
{
u32 id;
SMutex m_mutex;
SleepQueue m_queue;
u32 recursive; // recursive locks count
std::atomic<u32> cond_count; // count of condition variables associated
const u32 protocol;
const bool is_recursive;
Mutex(u32 protocol, bool is_recursive, u64 name)
: protocol(protocol)
, is_recursive(is_recursive)
, m_queue(name)
, cond_count(0)
{
}
~Mutex()
{
if (u32 owner = m_mutex.GetOwner())
{
LOG_NOTICE(HLE, "Mutex(%d) was owned by thread %d (recursive=%d)", id, owner, recursive);
}
if (!m_queue.m_mutex.try_lock()) return;
for (u32 i = 0; i < m_queue.list.size(); i++)
{
if (u32 owner = m_queue.list[i]) LOG_NOTICE(HLE, "Mutex(%d) was waited by thread %d", id, owner);
}
m_queue.m_mutex.unlock();
}
};
// SysCalls
s32 sys_mutex_create(mem32_t mutex_id, mem_ptr_t<sys_mutex_attribute> attr);
s32 sys_mutex_destroy(u32 mutex_id);
s32 sys_mutex_lock(u32 mutex_id, u64 timeout);
s32 sys_mutex_trylock(u32 mutex_id);
s32 sys_mutex_unlock(u32 mutex_id);