1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4#ifndef __GCENV_STRUCTS_INCLUDED__
5#define __GCENV_STRUCTS_INCLUDED__
6//
7// Structs shared between the GC and the environment
8//
9
10struct GCSystemInfo
11{
12 uint32_t dwNumberOfProcessors;
13 uint32_t dwPageSize;
14 uint32_t dwAllocationGranularity;
15};
16
17typedef void * HANDLE;
18
19#ifdef PLATFORM_UNIX
20
21typedef char TCHAR;
22#define _T(s) s
23
24#else
25
26#ifndef _INC_WINDOWS
27typedef wchar_t TCHAR;
28#define _T(s) L##s
29#endif
30
31#endif
32
33#ifdef PLATFORM_UNIX
34
35class EEThreadId
36{
37 pthread_t m_id;
38 // Indicates whether the m_id is valid or not. pthread_t doesn't have any
39 // portable "invalid" value.
40 bool m_isValid;
41
42public:
43 bool IsCurrentThread()
44 {
45 return m_isValid && pthread_equal(m_id, pthread_self());
46 }
47
48 void SetToCurrentThread()
49 {
50 m_id = pthread_self();
51 m_isValid = true;
52 }
53
54 void Clear()
55 {
56 m_isValid = false;
57 }
58};
59
60#else // PLATFORM_UNIX
61
62#ifndef _INC_WINDOWS
63extern "C" uint32_t __stdcall GetCurrentThreadId();
64#endif
65
66class EEThreadId
67{
68 uint64_t m_uiId;
69public:
70
71 bool IsCurrentThread()
72 {
73 return m_uiId == ::GetCurrentThreadId();
74 }
75
76 void SetToCurrentThread()
77 {
78 m_uiId = ::GetCurrentThreadId();
79 }
80
81 void Clear()
82 {
83 m_uiId = 0;
84 }
85};
86
87#endif // PLATFORM_UNIX
88
89#ifndef _INC_WINDOWS
90
91#ifdef PLATFORM_UNIX
92
93typedef struct _RTL_CRITICAL_SECTION {
94 pthread_mutex_t mutex;
95} CRITICAL_SECTION, RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
96
97#else
98
99#pragma pack(push, 8)
100
101typedef struct _RTL_CRITICAL_SECTION {
102 void* DebugInfo;
103
104 //
105 // The following three fields control entering and exiting the critical
106 // section for the resource
107 //
108
109 int32_t LockCount;
110 int32_t RecursionCount;
111 HANDLE OwningThread; // from the thread's ClientId->UniqueThread
112 HANDLE LockSemaphore;
113 uintptr_t SpinCount; // force size on 64-bit systems when packed
114} CRITICAL_SECTION, RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
115
116#pragma pack(pop)
117
118#endif
119
120#endif // _INC_WINDOWS
121
122#endif // __GCENV_STRUCTS_INCLUDED__
123