libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Loading...
Searching...
No Matches
worker.h
1/*
2 * CDDL HEADER START
3 *
4 * This file and its contents are supplied under the terms of the
5 * Common Development and Distribution License ("CDDL"), version 1.0.
6 * You may only use this file in accordance with the terms of version
7 * 1.0 of the CDDL.
8 *
9 * A full copy of the text of the CDDL should have accompanied this
10 * source. A copy of the CDDL is also available via the Internet at
11 * http://www.illumos.org/license/CDDL.
12 *
13 * CDDL HEADER END
14 */
15/*
16 * Copyright 2018 Saso Kiselkov. All rights reserved.
17 */
18
19#ifndef _ACFUTILS_WORKER_H_
20#define _ACFUTILS_WORKER_H_
21
22#include "thread.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28typedef struct {
29 mutex_t lock;
30 condvar_t cv;
31 uint64_t intval_us;
32 bool_t run;
33 bool_t inside_cb;
34 bool_t dontstop;
35 thread_t thread;
36 bool_t (*init_func)(void *userinfo);
37 bool_t (*worker_func)(void *userinfo);
38 void (*fini_func)(void *userinfo);
39 void *userinfo;
40 char name[32];
41} worker_t;
42
43API_EXPORT void worker_init(worker_t *wk, bool_t (*worker_func)(void *userinfo),
44 uint64_t intval_us, void *userinfo, const char *thread_name);
45API_EXPORT void worker_init2(worker_t *wk,
46 bool_t (*init_func)(void *userinfo),
47 bool_t (*worker_func)(void *userinfo),
48 void (*fini_func)(void *userinfo),
49 uint64_t intval_us, void *userinfo, const char *thread_name);
50API_EXPORT void worker_fini(worker_t *wk);
51
52API_EXPORT void worker_set_interval(worker_t *wk, uint64_t intval_us);
53API_EXPORT void worker_set_interval_nowake(worker_t *wk, uint64_t intval_us);
54API_EXPORT void worker_wake_up(worker_t *wk);
55API_EXPORT void worker_wake_up_wait(worker_t *wk);
56
57#ifdef __cplusplus
58}
59#endif
60
61#endif /* _ACFUTILS_WORKER_H_ */
CONDITION_VARIABLE condvar_t
Definition thread.h:465
HANDLE thread_t
Definition thread.h:393