1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
// GNU D Compiler thread support for emulated TLS routines.
// Copyright (C) 2019-2025 Free Software Foundation, Inc.
// GCC is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 3, or (at your option) any later
// version.
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
module gcc.gthread;
import gcc.config;
extern (C) nothrow @nogc:
alias GthreadDestroyFn = extern (C) void function(void*);
alias GthreadOnceFn = extern (C) void function();
static if (GNU_Thread_Model == ThreadModel.Posix)
{
import core.sys.posix.pthread;
alias __gthread_key_create = pthread_key_create;
alias __gthread_key_delete = pthread_key_delete;
alias __gthread_getspecific = pthread_getspecific;
alias __gthread_setspecific = pthread_setspecific;
alias __gthread_once = pthread_once;
alias __gthread_key_t = pthread_key_t;
alias __gthread_once_t = pthread_once_t;
enum GTHREAD_ONCE_INIT = PTHREAD_ONCE_INIT;
// TODO: FreeBSD and Solaris exposes a dummy POSIX threads
// interface that will need to be handled here.
extern (D) int __gthread_active_p()
{
return 1;
}
}
else static if (GNU_Thread_Model == ThreadModel.Single)
{
alias __gthread_key_t = int;
alias __gthread_once_t = int;
enum GTHREAD_ONCE_INIT = 0;
extern (D) int __gthread_key_create(__gthread_key_t*, GthreadDestroyFn)
{
return 0;
}
extern (D) int __gthread_key_delete(__gthread_key_t)
{
return 0;
}
extern (D) void* __gthread_getspecific(__gthread_key_t)
{
return null;
}
extern (D) int __gthread_setspecific(__gthread_key_t, void*)
{
return 0;
}
extern (D) int __gthread_once(__gthread_once_t*, GthreadOnceFn)
{
return 0;
}
extern (D) int __gthread_active_p()
{
return 0;
}
}
else static if (GNU_Thread_Model == ThreadModel.Win32)
{
import core.stdc.config;
struct __gthread_once_t
{
int done;
c_long started;
}
int __gthr_win32_key_create(__gthread_key_t* keyp, GthreadDestroyFn dtor);
int __gthr_win32_key_delete(__gthread_key_t key);
void* __gthr_win32_getspecific(__gthread_key_t key);
int __gthr_win32_setspecific(__gthread_key_t key, const void* ptr);
int __gthr_win32_once(__gthread_once_t* once, GthreadOnceFn);
alias __gthread_key_create = __gthr_win32_key_create;
alias __gthread_key_delete = __gthr_win32_key_delete;
alias __gthread_getspecific = __gthr_win32_getspecific;
alias __gthread_setspecific = __gthr_win32_setspecific;
alias __gthread_once = __gthr_win32_once;
enum GTHREAD_ONCE_INIT = __gthread_once_t(0, -1);
alias __gthread_key_t = c_ulong;
version (MinGW)
{
// Mingw runtime >= v0.3 provides a magic variable that is set to nonzero
// if -mthreads option was specified, or 0 otherwise.
extern __gshared int _CRT_MT;
}
extern (D) int __gthread_active_p()
{
version (MinGW)
return _CRT_MT;
else
return 1;
}
}
else
{
static assert(false, "Not implemented");
}
|