2020-12-05 13:08:24 +01:00
|
|
|
#pragma once
|
2014-02-13 17:59:13 +01:00
|
|
|
|
2016-04-14 00:23:53 +02:00
|
|
|
#include "sys_sync.h"
|
2018-09-26 00:14:10 +02:00
|
|
|
#include "sys_mutex.h"
|
2015-06-19 17:49:38 +02:00
|
|
|
|
2017-01-29 17:50:18 +01:00
|
|
|
struct lv2_mutex;
|
2015-03-06 23:10:04 +01:00
|
|
|
|
|
|
|
|
struct sys_cond_attribute_t
|
2014-02-13 17:59:13 +01:00
|
|
|
{
|
|
|
|
|
be_t<u32> pshared;
|
2015-01-02 00:41:29 +01:00
|
|
|
be_t<s32> flags;
|
2015-03-06 23:10:04 +01:00
|
|
|
be_t<u64> ipc_key;
|
|
|
|
|
|
2014-02-13 17:59:13 +01:00
|
|
|
union
|
|
|
|
|
{
|
2019-10-25 16:50:46 +02:00
|
|
|
nse_t<u64, 1> name_u64;
|
2019-07-08 19:00:27 +02:00
|
|
|
char name[sizeof(u64)];
|
2014-02-13 17:59:13 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2017-01-29 17:50:18 +01:00
|
|
|
struct lv2_cond final : lv2_obj
|
2014-02-13 17:59:13 +01:00
|
|
|
{
|
2017-01-25 18:50:30 +01:00
|
|
|
static const u32 id_base = 0x86000000;
|
|
|
|
|
|
2017-02-02 18:47:25 +01:00
|
|
|
const u32 shared;
|
|
|
|
|
const s32 flags;
|
|
|
|
|
const u64 key;
|
2015-03-06 23:10:04 +01:00
|
|
|
const u64 name;
|
2020-06-09 17:35:14 +02:00
|
|
|
const u32 mtx_id;
|
2015-03-06 23:10:04 +01:00
|
|
|
|
2017-02-02 18:47:25 +01:00
|
|
|
std::shared_ptr<lv2_mutex> mutex; // Associated Mutex
|
|
|
|
|
atomic_t<u32> waiters{0};
|
|
|
|
|
std::deque<cpu_thread*> sq;
|
2015-03-10 15:42:08 +01:00
|
|
|
|
2020-06-09 17:35:14 +02:00
|
|
|
lv2_cond(u32 shared, s32 flags, u64 key, u64 name, u32 mtx_id, std::shared_ptr<lv2_mutex> mutex)
|
2017-07-24 17:59:48 +02:00
|
|
|
: shared(shared)
|
|
|
|
|
, flags(flags)
|
2020-02-21 13:20:10 +01:00
|
|
|
, key(key)
|
2015-03-06 23:10:04 +01:00
|
|
|
, name(name)
|
2020-06-09 17:35:14 +02:00
|
|
|
, mtx_id(mtx_id)
|
2017-02-02 18:47:25 +01:00
|
|
|
, mutex(std::move(mutex))
|
2014-02-13 17:59:13 +01:00
|
|
|
{
|
2020-06-04 05:37:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CellError on_id_create()
|
|
|
|
|
{
|
|
|
|
|
if (!mutex->obj_count.fetch_op([](typename lv2_mutex::count_info& info)
|
|
|
|
|
{
|
|
|
|
|
if (info.mutex_count)
|
|
|
|
|
return info.cond_count++, true;
|
|
|
|
|
return false;
|
|
|
|
|
}).second)
|
|
|
|
|
{
|
|
|
|
|
// Mutex has been destroyed, cannot create conditional variable
|
|
|
|
|
return CELL_ESRCH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {};
|
2014-02-13 17:59:13 +01:00
|
|
|
}
|
2014-06-25 00:38:34 +02:00
|
|
|
};
|
|
|
|
|
|
2016-07-27 23:43:22 +02:00
|
|
|
class ppu_thread;
|
2014-12-23 00:31:11 +01:00
|
|
|
|
2017-02-02 18:47:25 +01:00
|
|
|
// Syscalls
|
|
|
|
|
|
2019-06-09 00:38:01 +02:00
|
|
|
error_code sys_cond_create(ppu_thread& ppu, vm::ptr<u32> cond_id, u32 mutex_id, vm::ptr<sys_cond_attribute_t> attr);
|
|
|
|
|
error_code sys_cond_destroy(ppu_thread& ppu, u32 cond_id);
|
2017-02-02 18:47:25 +01:00
|
|
|
error_code sys_cond_wait(ppu_thread& ppu, u32 cond_id, u64 timeout);
|
2017-02-06 19:36:46 +01:00
|
|
|
error_code sys_cond_signal(ppu_thread& ppu, u32 cond_id);
|
|
|
|
|
error_code sys_cond_signal_all(ppu_thread& ppu, u32 cond_id);
|
|
|
|
|
error_code sys_cond_signal_to(ppu_thread& ppu, u32 cond_id, u32 thread_id);
|