Xenomai  3.0.8
current.h
1 /*
2  * Copyright (C) 2009 Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 #ifndef _LIB_COBALT_CURRENT_H
19 #define _LIB_COBALT_CURRENT_H
20 
21 #include <stdint.h>
22 #include <pthread.h>
23 #include <cobalt/uapi/thread.h>
24 #include <xeno_config.h>
25 
26 extern pthread_key_t cobalt_current_window_key;
27 
28 xnhandle_t cobalt_get_current_slow(void);
29 
30 #ifdef HAVE_TLS
31 extern __thread __attribute__ ((tls_model (CONFIG_XENO_TLS_MODEL)))
32 xnhandle_t cobalt_current;
33 extern __thread __attribute__ ((tls_model (CONFIG_XENO_TLS_MODEL)))
34 struct xnthread_user_window *cobalt_current_window;
35 
36 static inline xnhandle_t cobalt_get_current(void)
37 {
38  return cobalt_current;
39 }
40 
41 static inline xnhandle_t cobalt_get_current_fast(void)
42 {
43  return cobalt_get_current();
44 }
45 
46 static inline int cobalt_get_current_mode(void)
47 {
48  return cobalt_current_window ? cobalt_current_window->state : XNRELAX;
49 }
50 
51 static inline struct xnthread_user_window *cobalt_get_current_window(void)
52 {
53  return cobalt_current ? cobalt_current_window : NULL;
54 }
55 
56 #else /* ! HAVE_TLS */
57 extern pthread_key_t cobalt_current_key;
58 
59 xnhandle_t cobalt_get_current_slow(void);
60 
61 static inline xnhandle_t cobalt_get_current(void)
62 {
63  void *val = pthread_getspecific(cobalt_current_key);
64 
65  return (xnhandle_t)(uintptr_t)val ?: cobalt_get_current_slow();
66 }
67 
68 /* syscall-free, but unreliable in TSD destructor context */
69 static inline xnhandle_t cobalt_get_current_fast(void)
70 {
71  void *val = pthread_getspecific(cobalt_current_key);
72 
73  return (xnhandle_t)(uintptr_t)val ?: XN_NO_HANDLE;
74 }
75 
76 static inline int cobalt_get_current_mode(void)
77 {
78  struct xnthread_user_window *window;
79 
80  window = pthread_getspecific(cobalt_current_window_key);
81 
82  return window ? window->state : XNRELAX;
83 }
84 
85 static inline struct xnthread_user_window *cobalt_get_current_window(void)
86 {
87  return pthread_getspecific(cobalt_current_window_key);
88 }
89 
90 #endif /* ! HAVE_TLS */
91 
92 void cobalt_init_current_keys(void);
93 
94 void cobalt_set_tsd(__u32 u_winoff);
95 
96 void cobalt_clear_tsd(void);
97 
98 #endif /* _LIB_COBALT_CURRENT_H */
#define XNRELAX
Relaxed shadow thread (blocking bit)
Definition: thread.h:39