The OpenD Programming Language

1 /**
2  * This module provides types and constants used in thread package.
3  *
4  * Copyright: Copyright Sean Kelly 2005 - 2012.
5  * License: Distributed under the
6  *      $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
7  *    (See accompanying file LICENSE)
8  * Authors:   Sean Kelly, Walter Bright, Alex Rønne Petersen, Martin Nowak
9  * Source:    $(DRUNTIMESRC core/thread/osthread.d)
10  */
11 
12 module core.thread.types;
13 
14 /**
15  * Represents the ID of a thread, as returned by $(D Thread.)$(LREF id).
16  * The exact type varies from platform to platform.
17  */
18 version (Windows)
19     alias ThreadID = uint;
20 else
21 version (Posix)
22 {
23     import core.sys.posix.pthread;
24 
25     alias ThreadID = pthread_t;
26 }
27 else
28     alias ThreadID = int;
29 
30 struct ll_ThreadData
31 {
32     ThreadID tid;
33     version (Windows)
34         void delegate() nothrow cbDllUnload;
35 }
36 
37 version (GNU)
38 {
39     version (GNU_StackGrowsDown)
40         enum isStackGrowingDown = true;
41     else
42         enum isStackGrowingDown = false;
43 }
44 else version (LDC)
45 {
46     // The only LLVM targets as of LLVM 16 with stack growing *upwards* are
47     // apparently NVPTX and AMDGPU, both without druntime support.
48     // Note that there's an analogous `version = StackGrowsDown` in
49     // core.thread.fiber.
50     enum isStackGrowingDown = true;
51 }
52 else
53 {
54     version (X86) enum isStackGrowingDown = true;
55     else version (X86_64) enum isStackGrowingDown = true;
56     else static assert(0, "It is undefined how the stack grows on this architecture.");
57 }
58 
59 package
60 {
61     version (Posix) static immutable size_t PTHREAD_STACK_MIN;
62 }
63 
64 shared static this()
65 {
66     version (Posix)
67     {
68         import core.sys.posix.unistd;
69 
70         PTHREAD_STACK_MIN = cast(size_t)sysconf(_SC_THREAD_STACK_MIN);
71     }
72 }