Add ust fd mutex nesting getter
[lttng-ust.git] / liblttng-ust-comm / ust-cancelstate.c
CommitLineData
595c1577
MD
1/*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2021 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 */
6
7#include <pthread.h>
8#include <errno.h>
7beb5ba1 9#include <string.h>
595c1577
MD
10#include <urcu/tls-compat.h>
11#include <lttng/ust-cancelstate.h>
12#include <usterr-signal-safe.h>
13
14struct ust_cancelstate {
15 int nesting;
16 int oldstate; /* oldstate for outermost nesting */
17};
18
19static DEFINE_URCU_TLS(struct ust_cancelstate, thread_state);
20
21int lttng_ust_cancelstate_disable_push(void)
22{
23 struct ust_cancelstate *state = &URCU_TLS(thread_state);
24 int ret, oldstate;
25
26 if (state->nesting++)
27 goto end;
28 ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
29 if (ret) {
94e6e686 30 ERR("pthread_setcancelstate: ret=%d", ret);
595c1577
MD
31 return -1;
32 }
33 state->oldstate = oldstate;
34end:
35 return 0;
36}
37
38int lttng_ust_cancelstate_disable_pop(void)
39{
40 struct ust_cancelstate *state = &URCU_TLS(thread_state);
41 int ret, oldstate;
42
43 if (!state->nesting)
44 return -1;
45 if (--state->nesting)
46 goto end;
47 ret = pthread_setcancelstate(state->oldstate, &oldstate);
48 if (ret) {
94e6e686 49 ERR("pthread_setcancelstate: ret=%d", ret);
595c1577
MD
50 return -1;
51 }
52 if (oldstate != PTHREAD_CANCEL_DISABLE) {
53 ERR("pthread_setcancelstate: unexpected oldstate");
54 return -1;
55 }
56end:
57 return 0;
58}
59
60
This page took 0.035016 seconds and 5 git commands to generate.