You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
1.9 KiB
C
83 lines
1.9 KiB
C
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
#include "export.h"
|
|
#include "eventloop_platform.h"
|
|
#include "public/container_of.h"
|
|
#include "public/list.h"
|
|
|
|
EXPORT int tlsl_eventloop_init(struct tlsl_eventloop *el) {
|
|
int platform_res;
|
|
|
|
intrusive_list_init_empty(&el->event_list);
|
|
|
|
if ((platform_res = tlsl_platform_el_init(el)))
|
|
return platform_res;
|
|
|
|
el->valid = true;
|
|
return 0;
|
|
}
|
|
|
|
EXPORT void tlsl_eventloop_cleanup(struct tlsl_eventloop *el) {
|
|
struct intrusive_list *li;
|
|
struct tlsl_event *e;
|
|
|
|
if (!el || !el->valid)
|
|
return;
|
|
|
|
INTRUSIVE_LIST_FOR_EACH_NO_REMOVE(li, &el->event_list) {
|
|
e = TLSL_CONTAINER_OF(li, struct tlsl_event, list);
|
|
tlsl_platform_el_event_cleanup(el, e);
|
|
}
|
|
|
|
tlsl_platform_el_cleanup(el);
|
|
el->valid = false;
|
|
}
|
|
|
|
EXPORT int tlsl_eventloop_wait(
|
|
struct tlsl_eventloop *el,
|
|
tlsl_event_id_t *id_out,
|
|
uint32_t *flags_out,
|
|
int timeout_ms)
|
|
{
|
|
return tlsl_platform_el_wait(el, id_out, flags_out, timeout_ms);
|
|
}
|
|
|
|
EXPORT int tlsl_eventloop_clear(struct tlsl_eventloop *el, struct tlsl_event *e) {
|
|
return tlsl_platform_el_event_clear(el, e);
|
|
}
|
|
|
|
EXPORT void tlsl_eventloop_remove(struct tlsl_eventloop *el, struct tlsl_event *e) {
|
|
tlsl_platform_el_event_remove(el, e);
|
|
tlsl_platform_el_event_cleanup(el, e);
|
|
}
|
|
|
|
EXPORT int tlsl_eventloop_add_timer(
|
|
struct tlsl_eventloop *el,
|
|
struct tlsl_event *e,
|
|
uint64_t millis,
|
|
bool oneshot)
|
|
{
|
|
int res;
|
|
|
|
if ((res = tlsl_platform_el_add_timer(el, e, millis, oneshot)))
|
|
return res;
|
|
e->id.source = TLSL_EVENT_SOURCE_TIMER;
|
|
return 0;
|
|
}
|
|
|
|
EXPORT int tlsl_eventloop_add_fd(
|
|
struct tlsl_eventloop *el,
|
|
struct tlsl_event *e,
|
|
int fd,
|
|
uint32_t flags)
|
|
{
|
|
int res;
|
|
|
|
if ((res = tlsl_platform_el_add_fd(el, e, fd, flags)))
|
|
return res;
|
|
e->id.source = TLSL_EVENT_SOURCE_FD;
|
|
return 0;
|
|
}
|