This source file includes following definitions.
- tss_create
- tss_set
- tss_get
- tss_delete
- tss_create
- tss_set
- tss_get
- tss_delete
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include <threads.h>
22
23 #include <string.h>
24
25 #if defined _WIN32 && ! defined __CYGWIN__
26
27
28 # define WIN32_LEAN_AND_MEAN
29 # include <windows.h>
30
31 #else
32
33
34 # include <pthread.h>
35
36 #endif
37
38 #if defined _WIN32 && ! defined __CYGWIN__
39
40
41 int
42 tss_create (tss_t *keyp, tss_dtor_t destructor)
43 {
44 int err = glwthread_tls_key_create (keyp, destructor);
45 if (err == 0)
46 return thrd_success;
47 else
48 {
49 memset (keyp, '\0', sizeof (tss_t));
50 return thrd_error;
51 }
52 }
53
54 int
55 tss_set (tss_t key, void *value)
56 {
57 int err = glwthread_tls_set (key, value);
58 return (err == 0 ? thrd_success : thrd_error);
59 }
60
61 void *
62 tss_get (tss_t key)
63 {
64 return glwthread_tls_get (key);
65 }
66
67 void
68 tss_delete (tss_t key)
69 {
70 glwthread_tls_key_delete (key);
71 }
72
73 #else
74
75
76 int
77 tss_create (tss_t *keyp, tss_dtor_t destructor)
78 {
79 int err = pthread_key_create (keyp, destructor);
80 if (err == 0)
81 return thrd_success;
82 else
83 {
84 memset (keyp, '\0', sizeof (tss_t));
85 return thrd_error;
86 }
87 }
88
89 int
90 tss_set (tss_t key, void *value)
91 {
92 int err = pthread_setspecific (key, value);
93 return (err == 0 ? thrd_success : thrd_error);
94 }
95
96 void *
97 tss_get (tss_t key)
98 {
99 return pthread_getspecific (key);
100 }
101
102 void
103 tss_delete (tss_t key)
104 {
105 pthread_key_delete (key);
106 }
107
108 #endif