wut/include/coreinit/event.h

147 lines
3.4 KiB
C
Raw Normal View History

2016-01-07 13:07:13 +01:00
#pragma once
#include <wut.h>
#include "thread.h"
#include "threadqueue.h"
2016-01-07 17:02:54 +01:00
/**
* \defgroup coreinit_event Event Object
* \ingroup coreinit
2016-01-07 20:24:54 +01:00
*
* Standard event object implementation. There are two supported event object modes, check OSEventMode.
*
* Similar to Windows <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms682655(v=vs.85).aspx">Event Objects</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 OSEvent OSEvent;
2016-01-08 16:28:52 +01:00
typedef enum OSEventMode
2016-01-07 13:07:13 +01:00
{
2016-01-07 20:24:54 +01:00
//! A manual event will only reset when OSResetEvent is called.
2016-01-07 13:07:13 +01:00
OS_EVENT_MODE_MANUAL = 0,
2016-01-07 20:24:54 +01:00
//! An auto event will reset everytime a thread is woken.
2016-01-07 13:07:13 +01:00
OS_EVENT_MODE_AUTO = 1,
2016-01-08 16:28:52 +01:00
} OSEventMode;
2016-01-07 13:07:13 +01:00
#define OS_EVENT_TAG 0x65566E54u
2016-01-07 13:07:13 +01:00
struct OSEvent
{
2016-01-07 20:24:54 +01:00
//! Should always be set to the value OS_EVENT_TAG.
2016-01-07 13:07:13 +01:00
uint32_t tag;
2016-01-07 20:24:54 +01:00
//! Name set by OSInitEventEx.
2016-01-07 13:07:13 +01:00
const char *name;
2016-01-07 20:24:54 +01:00
2016-01-07 13:07:13 +01:00
UNKNOWN(4);
2016-01-07 20:24:54 +01:00
//! The current value of the event object.
2016-01-07 13:07:13 +01:00
BOOL value;
2016-01-07 20:24:54 +01:00
//! The threads currently waiting on this event object with OSWaitEvent.
2016-01-07 13:07:13 +01:00
OSThreadQueue queue;
2016-01-07 20:24:54 +01:00
//! The mode of the event object, set by OSInitEvent.
2016-01-07 13:07:13 +01:00
OSEventMode mode;
};
CHECK_OFFSET(OSEvent, 0x0, tag);
CHECK_OFFSET(OSEvent, 0x4, name);
CHECK_OFFSET(OSEvent, 0xc, value);
CHECK_OFFSET(OSEvent, 0x10, queue);
CHECK_OFFSET(OSEvent, 0x20, mode);
CHECK_SIZE(OSEvent, 0x24);
2016-01-07 20:24:54 +01:00
/**
* Initialise an event object with value and mode.
*/
2016-01-07 13:07:13 +01:00
void
OSInitEvent(OSEvent *event,
BOOL value,
OSEventMode mode);
2016-01-07 20:24:54 +01:00
/**
* Initialise an event object with value, mode and name.
*/
2016-01-07 13:07:13 +01:00
void
OSInitEventEx(OSEvent *event,
BOOL value,
OSEventMode mode,
char *name);
2016-01-07 20:24:54 +01:00
/**
* Signals the event.
*
* If no threads are waiting the event value is set.
*
* If the event mode is OS_EVENT_MODE_MANUAL this will wake all waiting threads
* and the event will remain set until OSResetEvent is called.
*
* If the event mode is OS_EVENT_MODE_AUTO this will wake only one thread
* and the event will be reset immediately.
*
* Similar to <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms686211(v=vs.85).aspx">SetEvent</a>.
*/
2016-01-07 13:07:13 +01:00
void
OSSignalEvent(OSEvent *event);
2016-01-07 20:24:54 +01:00
/**
* Signals all threads waiting on an event.
*
* If no threads are waiting the event value is set.
*
* If the event mode is OS_EVENT_MODE_MANUAL this will wake all waiting threads
* and the event will remain set until OSResetEvent is called.
*
* If the event mode is OS_EVENT_MODE_AUTO this will wake all waiting threads
* and the event will be reset.
*/
2016-01-07 13:07:13 +01:00
void
OSSignalEventAll(OSEvent *event);
2016-01-07 20:24:54 +01:00
/**
* Wait until an event is signalled.
*
* If the event is already set, this returns immediately.
*
* If the event mode is OS_EVENT_MODE_AUTO the event will be reset before
* returning from this method.
*
* Similar to <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms687032(v=vs.85).aspx">WaitForSingleObject</a>.
*/
2016-01-07 13:07:13 +01:00
void
OSWaitEvent(OSEvent *event);
2016-01-07 20:24:54 +01:00
/**
* Resets the event object.
*
* Similar to <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms685081(v=vs.85).aspx">ResetEvent</a>.
*/
2016-01-07 13:07:13 +01:00
void
OSResetEvent(OSEvent *event);
2016-01-07 20:24:54 +01:00
/**
* Wait until an event is signalled or a timeout has occurred.
*
* Similar to <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms687032(v=vs.85).aspx">WaitForSingleObject</a>.
*/
2016-01-07 13:07:13 +01:00
BOOL
OSWaitEventWithTimeout(OSEvent *event,
OSTime timeout);
2016-01-07 15:09:43 +01:00
#ifdef __cplusplus
}
#endif
2016-01-07 17:02:54 +01:00
/** @} */