wut/include/coreinit/condition.h

85 lines
1.8 KiB
C
Raw Normal View History

2016-01-07 13:07:13 +01:00
#pragma once
#include <wut.h>
#include "threadqueue.h"
2016-01-07 17:02:54 +01:00
/**
* \defgroup coreinit_cond Condition Variable
* \ingroup coreinit
2016-01-07 20:24:54 +01:00
*
* Standard condition variable implementation.
*
* Similar to <a href="http://en.cppreference.com/w/cpp/thread/condition_variable">std::condition_variable</a>.
2016-01-07 17:02:54 +01:00
* @{
*/
2016-01-07 15:09:43 +01:00
#ifdef __cplusplus
extern "C" {
#endif
2016-01-07 13:07:13 +01:00
typedef struct OSCondition OSCondition;
2016-01-07 13:45:18 +01:00
typedef struct OSMutex OSMutex;
2016-01-07 13:07:13 +01:00
#define OS_CONDITION_TAG 0x634E6456u
2016-01-07 13:07:13 +01:00
struct OSCondition
{
2016-01-07 17:02:54 +01:00
//! Should always be set to the value OS_CONDITION_TAG.
2016-01-07 13:07:13 +01:00
uint32_t tag;
2016-01-07 17:02:54 +01:00
//! Name set by OSInitCondEx.
2016-01-07 13:07:13 +01:00
const char *name;
UNKNOWN(4);
2016-01-07 17:02:54 +01:00
//! Queue of threads currently waiting on condition with OSWaitCond.
2016-01-07 13:07:13 +01:00
OSThreadQueue queue;
};
CHECK_OFFSET(OSCondition, 0x00, tag);
CHECK_OFFSET(OSCondition, 0x04, name);
CHECK_OFFSET(OSCondition, 0x0c, queue);
CHECK_SIZE(OSCondition, 0x1c);
2016-01-07 20:24:54 +01:00
/**
* Initialise a condition variable structure.
*/
2016-01-07 13:07:13 +01:00
void
OSInitCond(OSCondition *condition);
2016-01-07 20:24:54 +01:00
/**
* Initialise a condition variable structure with a name.
*/
2016-01-07 13:07:13 +01:00
void
OSInitCondEx(OSCondition *condition,
const char *name);
2016-01-07 20:24:54 +01:00
/**
* Sleep the current thread until the condition variable has been signalled.
*
* The mutex must be locked when entering this function.
* Will unlock the mutex and then sleep, reacquiring the mutex when woken.
*
* Similar to <a href="http://en.cppreference.com/w/cpp/thread/condition_variable/wait">std::condition_variable::wait</a>.
*/
2016-01-07 13:07:13 +01:00
void
OSWaitCond(OSCondition *condition,
OSMutex *mutex);
2016-01-07 20:24:54 +01:00
/**
* Will wake up any threads waiting on the condition with OSWaitCond.
*
* Similar to <a href="http://en.cppreference.com/w/cpp/thread/condition_variable/notify_all">std::condition_variable::notify_all</a>.
*/
2016-01-07 13:07:13 +01:00
void
OSSignalCond(OSCondition *condition);
2016-01-07 20:24:54 +01:00
2016-01-07 15:09:43 +01:00
#ifdef __cplusplus
}
#endif
2016-01-07 17:02:54 +01:00
/** @} */