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 
28 struct ll_ThreadData
29 {
30     ThreadID tid;
31     version (Windows)
32         void delegate() nothrow cbDllUnload;
33 }
34 
35 version (GNU)
36 {
37     version (GNU_StackGrowsDown)
38         enum isStackGrowingDown = true;
39     else
40         enum isStackGrowingDown = false;
41 }
42 else version (LDC)
43 {
44     // The only LLVM targets as of LLVM 16 with stack growing *upwards* are
45     // apparently NVPTX and AMDGPU, both without druntime support.
46     // Note that there's an analogous `version = StackGrowsDown` in
47     // core.thread.fiber.
48     enum isStackGrowingDown = true;
49 }
50 else
51 {
52     version (X86) enum isStackGrowingDown = true;
53     else version (X86_64) enum isStackGrowingDown = true;
54     else static assert(0, "It is undefined how the stack grows on this architecture.");
55 }
56 
57 package
58 {
59     version (Posix) static immutable size_t PTHREAD_STACK_MIN;
60 }
61 
62 shared static this()
63 {
64     version (Posix)
65     {
66         import core.sys.posix.unistd;
67 
68         PTHREAD_STACK_MIN = cast(size_t)sysconf(_SC_THREAD_STACK_MIN);
69     }
70 }