mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-04 02:22:15 +02:00
Event bringup
This commit is contained in:
parent
ec5721ea47
commit
516278a4a1
18
nx/include/switch/kernel/event.h
Normal file
18
nx/include/switch/kernel/event.h
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright plutoo 2018
|
||||
#include "../types.h"
|
||||
#include "../result.h"
|
||||
#include "../kernel/svc.h"
|
||||
|
||||
typedef struct {
|
||||
Handle revent;
|
||||
Handle wevent;
|
||||
} Event;
|
||||
|
||||
Result eventCreate(Event* t);
|
||||
void eventLoadRemote(Event* t, Handle handle);
|
||||
void eventClose(Event* t);
|
||||
|
||||
Result eventWait(Event* t, u64 timeout);
|
||||
Result eventFire(Event* t);
|
||||
Result eventClear(Event* t);
|
||||
|
@ -216,6 +216,13 @@ Result svcSleepThread(u64 nano);
|
||||
///@name Synchronization
|
||||
///@{
|
||||
|
||||
/**
|
||||
* @brief Signals an event.
|
||||
* @return Result code.
|
||||
* @note Syscall number 0x11.
|
||||
*/
|
||||
Result svcSignalEvent(Handle handle);
|
||||
|
||||
/**
|
||||
* @brief Clears an event's signalled status.
|
||||
* @return Result code.
|
||||
|
62
nx/source/kernel/event.c
Normal file
62
nx/source/kernel/event.c
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright plutoo 2018
|
||||
#include "types.h"
|
||||
#include "result.h"
|
||||
#include "kernel/svc.h"
|
||||
#include "kernel/event.h"
|
||||
|
||||
Result eventCreate(Event* t)
|
||||
{
|
||||
Result rc;
|
||||
|
||||
rc = svcCreateEvent(&t->revent, &t->wevent);
|
||||
|
||||
if (R_FAILED(rc)) {
|
||||
t->revent = INVALID_HANDLE;
|
||||
t->wevent = INVALID_HANDLE;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void eventLoadRemote(Event* t, Handle handle) {
|
||||
t->revent = handle;
|
||||
}
|
||||
|
||||
Result eventWait(Event* t, u64 timeout)
|
||||
{
|
||||
Result rc;
|
||||
|
||||
rc = svcWaitSynchronizationSingle(t->revent, timeout);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
rc = svcResetSignal(t->revent);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result eventFire(Event* t) {
|
||||
return svcSignalEvent(t->wevent);
|
||||
}
|
||||
|
||||
Result eventClear(Event* t)
|
||||
{
|
||||
if (t->wevent != INVALID_HANDLE)
|
||||
return svcClearEvent(t->wevent);
|
||||
|
||||
if (t->revent != INVALID_HANDLE)
|
||||
return svcClearEvent(t->revent);
|
||||
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
}
|
||||
|
||||
void eventClose(Event* t)
|
||||
{
|
||||
if (t->revent != INVALID_HANDLE)
|
||||
svcCloseHandle(t->revent);
|
||||
if (t->wevent != INVALID_HANDLE)
|
||||
svcCloseHandle(t->wevent);
|
||||
|
||||
t->revent = INVALID_HANDLE;
|
||||
t->wevent = INVALID_HANDLE;
|
||||
}
|
@ -75,6 +75,11 @@ SVC_BEGIN svcSleepThread
|
||||
ret
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcSignalEvent
|
||||
svc 0x11
|
||||
ret
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcClearEvent
|
||||
svc 0x12
|
||||
ret
|
||||
@ -215,6 +220,16 @@ SVC_BEGIN svcReplyAndReceive
|
||||
ret
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcCreateEvent
|
||||
stp x0, x1, [sp, #-16]!
|
||||
svc 0x45
|
||||
ldr x3, [sp], #8
|
||||
str w1, [x3]
|
||||
ldr x3, [sp], #8
|
||||
str w2, [x3]
|
||||
ret
|
||||
SVC_END
|
||||
|
||||
SVC_BEGIN svcCreateJitMemory
|
||||
str x0, [sp, #-16]!
|
||||
svc 0x4B
|
||||
|
Loading…
Reference in New Issue
Block a user