2014-06-21 16:24:27 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
struct sys_semaphore_attribute
|
|
|
|
|
{
|
|
|
|
|
be_t<u32> protocol;
|
|
|
|
|
be_t<u32> pshared; // undefined
|
|
|
|
|
be_t<u64> ipc_key; // undefined
|
2014-09-19 02:19:22 +02:00
|
|
|
be_t<s32> flags; // undefined
|
2014-06-21 16:24:27 +02:00
|
|
|
be_t<u32> pad; // not used
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
char name[8];
|
|
|
|
|
u64 name_u64;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Semaphore
|
|
|
|
|
{
|
2014-12-23 00:31:11 +01:00
|
|
|
sleep_queue_t queue;
|
2015-01-02 00:41:29 +01:00
|
|
|
atomic_le_t<s32> value;
|
2014-06-21 16:24:27 +02:00
|
|
|
|
2014-09-19 02:19:22 +02:00
|
|
|
const s32 max;
|
2014-06-21 16:24:27 +02:00
|
|
|
const u32 protocol;
|
|
|
|
|
const u64 name;
|
|
|
|
|
|
2014-09-19 02:19:22 +02:00
|
|
|
Semaphore(s32 initial_count, s32 max_count, u32 protocol, u64 name)
|
2015-01-02 00:41:29 +01:00
|
|
|
: max(max_count)
|
2014-06-21 16:24:27 +02:00
|
|
|
, protocol(protocol)
|
|
|
|
|
, name(name)
|
|
|
|
|
{
|
2015-01-02 00:41:29 +01:00
|
|
|
value.write_relaxed(initial_count);
|
2014-06-21 16:24:27 +02:00
|
|
|
}
|
2014-06-25 00:38:34 +02:00
|
|
|
};
|
|
|
|
|
|
2014-09-19 02:19:22 +02:00
|
|
|
// Aux
|
|
|
|
|
u32 semaphore_create(s32 initial_count, s32 max_count, u32 protocol, u64 name_u64);
|
|
|
|
|
|
2014-06-25 00:38:34 +02:00
|
|
|
// SysCalls
|
2014-10-11 19:20:01 +02:00
|
|
|
s32 sys_semaphore_create(vm::ptr<u32> sem, vm::ptr<sys_semaphore_attribute> attr, s32 initial_count, s32 max_count);
|
2014-06-25 00:38:34 +02:00
|
|
|
s32 sys_semaphore_destroy(u32 sem_id);
|
|
|
|
|
s32 sys_semaphore_wait(u32 sem_id, u64 timeout);
|
|
|
|
|
s32 sys_semaphore_trywait(u32 sem_id);
|
2014-09-19 02:19:22 +02:00
|
|
|
s32 sys_semaphore_post(u32 sem_id, s32 count);
|
2014-10-11 19:20:01 +02:00
|
|
|
s32 sys_semaphore_get_value(u32 sem_id, vm::ptr<s32> count);
|