Commit | Line | Data |
---|---|---|
b878f05a | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
b878f05a | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: GPL-2.0-only |
b878f05a | 5 | * |
b878f05a JG |
6 | */ |
7 | ||
8 | #include <stdbool.h> | |
9 | ||
10 | #ifndef THREAD_H | |
11 | #define THREAD_H | |
12 | ||
13 | struct lttng_thread; | |
14 | ||
15 | /* Main function of the new thread. */ | |
e665dfbc | 16 | using lttng_thread_entry_point = void *(*) (void *); |
b878f05a JG |
17 | |
18 | /* Callback invoked to initiate the shutdown a thread. */ | |
e665dfbc | 19 | using lttng_thread_shutdown_cb = bool (*)(void *); |
b878f05a JG |
20 | |
21 | /* | |
22 | * Callback invoked to clean-up the thread data. | |
23 | * Invoked when the thread is destroyed to ensure there is no | |
24 | * race between a use by the "thread shutdown callback" and | |
25 | * a use by the thread itself. | |
26 | */ | |
e665dfbc | 27 | using lttng_thread_cleanup_cb = void (*)(void *); |
b878f05a JG |
28 | |
29 | /* | |
30 | * Returns a reference to the newly-created thread. | |
31 | * The shutdown and cleanup callbacks are optional. | |
32 | */ | |
33 | struct lttng_thread *lttng_thread_create(const char *name, | |
28f23191 JG |
34 | lttng_thread_entry_point entry, |
35 | lttng_thread_shutdown_cb shutdown, | |
36 | lttng_thread_cleanup_cb cleanup, | |
37 | void *thread_data); | |
b878f05a JG |
38 | |
39 | bool lttng_thread_get(struct lttng_thread *thread); | |
40 | void lttng_thread_put(struct lttng_thread *thread); | |
41 | ||
42 | const char *lttng_thread_get_name(const struct lttng_thread *thread); | |
43 | ||
44 | /* | |
45 | * Explicitly shutdown a thread. This function returns once the | |
46 | * thread has returned and been joined. | |
47 | * | |
48 | * It is invalid to call this function more than once on a thread. | |
49 | * | |
50 | * Returns true on success, false on error. | |
51 | */ | |
52 | bool lttng_thread_shutdown(struct lttng_thread *thread); | |
53 | ||
54 | /* | |
55 | * Shutdown all orphaned threads (threads to which no external reference | |
56 | * exist). | |
57 | * | |
58 | * Returns once all orphaned threads have been joined. | |
59 | */ | |
cd9adb8b | 60 | void lttng_thread_list_shutdown_orphans(); |
b878f05a JG |
61 | |
62 | #endif /* THREAD_H */ |