mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 20:42:44 +02:00
Event bringup
This commit is contained in:
parent
8e19bb5b0d
commit
9fc5e85c88
19
nx/include/switch/kernel/event.h
Normal file
19
nx/include/switch/kernel/event.h
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2018 plutoo
|
||||
#pragma once
|
||||
#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);
|
||||
|
62
nx/source/kernel/event.c
Normal file
62
nx/source/kernel/event.c
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright 2018 plutoo
|
||||
#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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user