2016-04-14 00:23:53 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "Utilities/SleepQueue.h"
|
2016-09-07 00:38:52 +02:00
|
|
|
#include "Utilities/Thread.h"
|
|
|
|
|
#include "Utilities/mutex.h"
|
|
|
|
|
#include "Utilities/sema.h"
|
|
|
|
|
#include "Utilities/cond.h"
|
2016-04-14 00:23:53 +02:00
|
|
|
|
|
|
|
|
// attr_protocol (waiting scheduling policy)
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
// First In, First Out
|
|
|
|
|
SYS_SYNC_FIFO = 1,
|
|
|
|
|
// Priority Order
|
|
|
|
|
SYS_SYNC_PRIORITY = 2,
|
|
|
|
|
// Basic Priority Inheritance Protocol (probably not implemented)
|
|
|
|
|
SYS_SYNC_PRIORITY_INHERIT = 3,
|
|
|
|
|
// Not selected while unlocking
|
|
|
|
|
SYS_SYNC_RETRY = 4,
|
|
|
|
|
//
|
|
|
|
|
SYS_SYNC_ATTR_PROTOCOL_MASK = 0xF,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// attr_recursive (recursive locks policy)
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
// Recursive locks are allowed
|
|
|
|
|
SYS_SYNC_RECURSIVE = 0x10,
|
|
|
|
|
// Recursive locks are NOT allowed
|
|
|
|
|
SYS_SYNC_NOT_RECURSIVE = 0x20,
|
|
|
|
|
//
|
|
|
|
|
SYS_SYNC_ATTR_RECURSIVE_MASK = 0xF0, //???
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// attr_pshared
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
SYS_SYNC_NOT_PROCESS_SHARED = 0x200,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// attr_adaptive
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
SYS_SYNC_ADAPTIVE = 0x1000,
|
|
|
|
|
SYS_SYNC_NOT_ADAPTIVE = 0x2000,
|
|
|
|
|
};
|
|
|
|
|
|
2017-01-29 17:50:18 +01:00
|
|
|
// Base class for some kernel objects (shared set of 8192 objects).
|
|
|
|
|
struct lv2_obj
|
|
|
|
|
{
|
|
|
|
|
using id_type = lv2_obj;
|
|
|
|
|
|
|
|
|
|
static const u32 id_step = 0x100;
|
|
|
|
|
static const u32 id_count = 8192;
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-07 00:38:52 +02:00
|
|
|
// Temporary implementation for LV2_UNLOCK (TODO: remove it)
|
|
|
|
|
struct lv2_lock_guard
|
2016-04-14 00:23:53 +02:00
|
|
|
{
|
2016-09-07 00:38:52 +02:00
|
|
|
static semaphore<> g_sema;
|
2016-04-14 00:23:53 +02:00
|
|
|
|
2016-09-07 00:38:52 +02:00
|
|
|
lv2_lock_guard(const lv2_lock_guard&) = delete;
|
2016-04-14 00:23:53 +02:00
|
|
|
|
2016-09-07 00:38:52 +02:00
|
|
|
lv2_lock_guard()
|
2016-04-14 00:23:53 +02:00
|
|
|
{
|
2016-09-07 00:38:52 +02:00
|
|
|
g_sema.post();
|
2016-04-14 00:23:53 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-07 00:38:52 +02:00
|
|
|
~lv2_lock_guard()
|
2016-04-14 00:23:53 +02:00
|
|
|
{
|
2016-09-07 00:38:52 +02:00
|
|
|
g_sema.wait();
|
2016-04-14 00:23:53 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-07 00:38:52 +02:00
|
|
|
using lv2_lock_t = semaphore_lock&;
|
|
|
|
|
|
|
|
|
|
#define LV2_LOCK semaphore_lock lv2_lock(lv2_lock_guard::g_sema)
|
|
|
|
|
|
|
|
|
|
#define LV2_UNLOCK lv2_lock_guard{}
|