1 | //------------------------------------------------------------------------------ |
2 | // Copyright (c) 2016 by Lukasz Janyst <lukasz@jany.st> |
3 | //------------------------------------------------------------------------------ |
4 | // This file is part of thread-bites. |
5 | // |
6 | // thread-bites is free software: you can redistribute it and/or modify |
7 | // it under the terms of the GNU General Public License as published by |
8 | // the Free Software Foundation, either version 3 of the License, or |
9 | // (at your option) any later version. |
10 | // |
11 | // thread-bites is distributed in the hope that it will be useful, |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | // GNU General Public License for more details. |
15 | // |
16 | // You should have received a copy of the GNU General Public License |
17 | // along with thread-bites. If not, see <http://www.gnu.org/licenses/>. |
18 | //------------------------------------------------------------------------------ |
19 | |
20 | #pragma once |
21 | |
22 | // the thread is detached |
23 | #define TB_DETACHED TBTHREAD_CREATE_DETACHED |
24 | |
25 | // the thread is joinable |
26 | #define TB_JOINABLE TBTHREAD_CREATE_JOINABLE |
27 | |
28 | // the thread is joinable and its status cannot be changed anymore |
29 | #define TB_JOINABLE_FIXED 2 |
30 | |
31 | #define TB_ONCE_NEW 0 |
32 | #define TB_ONCE_IN_PROGRESS 1 |
33 | #define TB_ONCE_DONE 2 |
34 | |
35 | #define TB_CANCEL_ENABLED 0x01 |
36 | #define TB_CANCEL_DEFERRED 0x02 |
37 | #define TB_CANCELING 0x04 |
38 | #define TB_CANCELED 0x08 |
39 | |
40 | #define SIGCANCEL SIGRTMIN |
41 | |
42 | #define TB_START_OK 0 |
43 | #define TB_START_WAIT 1 |
44 | #define TB_START_EXIT 2 |
45 | |
46 | #define SCHED_INFO_PACK(policy, priority) (((uint16_t)policy << 8) | priority) |
47 | #define SCHED_INFO_POLICY(info) (info >> 8) |
48 | #define SCHED_INFO_PRIORITY(info) (info & 0x00ff) |
49 | |
50 | void tb_tls_call_destructors(); |
51 | void tb_cancel_handler(int sig, siginfo_t *si, void *ctx); |
52 | void tb_call_cleanup_handlers(); |
53 | void tb_clear_cleanup_handlers(); |
54 | |
55 | int tb_set_sched(tbthread_t thread, int policy, int priority); |
56 | int tb_compute_sched(tbthread_t thread); |
57 | |
58 | void tb_protect_mutex_sched(tbthread_mutex_t *mutex); |
59 | void tb_protect_mutex_unsched(tbthread_mutex_t *mutex); |
60 | void tb_inherit_mutex_add(tbthread_mutex_t *mutex); |
61 | void tb_inherit_mutex_unsched(tbthread_mutex_t *mutex); |
62 | void tb_inherit_mutex_sched(tbthread_mutex_t *mutex, tbthread_t thread); |
63 | |
64 | void tb_futex_lock(int *futex); |
65 | int tb_futex_trylock(int *futex); |
66 | void tb_futex_unlock(int *futex); |
67 | |
68 | extern tbthread_mutex_t desc_mutex; |
69 | extern list_t used_desc; |
70 | extern int tb_pid; |
71 | |