1 /* ISO C 11 thread-specific storage in multithreaded situations.
2 Copyright (C) 2005-2019 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2005, 2019. */
25 #if defined _WIN32 && ! defined __CYGWIN__
26 /* Use Windows threads. */
28 # define WIN32_LEAN_AND_MEAN /* avoid including junk */
32 /* Use POSIX threads. */
38 #if defined _WIN32 && ! defined __CYGWIN__
39 /* Use Windows threads. */
42 tss_create (tss_t
*keyp
, tss_dtor_t destructor
)
44 int err
= glwthread_tls_key_create (keyp
, destructor
);
49 memset (keyp
, '\0', sizeof (tss_t
));
55 tss_set (tss_t key
, void *value
)
57 int err
= glwthread_tls_set (key
, value
);
58 return (err
== 0 ? thrd_success
: thrd_error
);
64 return glwthread_tls_get (key
);
68 tss_delete (tss_t key
)
70 glwthread_tls_key_delete (key
);
74 /* Use POSIX threads. */
77 tss_create (tss_t
*keyp
, tss_dtor_t destructor
)
79 int err
= pthread_key_create (keyp
, destructor
);
84 memset (keyp
, '\0', sizeof (tss_t
));
90 tss_set (tss_t key
, void *value
)
92 int err
= pthread_setspecific (key
, value
);
93 return (err
== 0 ? thrd_success
: thrd_error
);
99 return pthread_getspecific (key
);
103 tss_delete (tss_t key
)
105 pthread_key_delete (key
);