ReactOS 0.4.15-dev-7924-g5949c20
tlsthrd.c
Go to the documentation of this file.
1
14/*#ifndef WIN32_LEAN_AND_MEAN
15#define WIN32_LEAN_AND_MEAN
16#endif
17#include <windows.h>*/
18#include <stdlib.h>
19#include <stdarg.h>
20#include <windef.h>
21#include <winbase.h>
22
25int ___w64_mingwthr_add_key_dtor (DWORD key, void (*dtor)(void *));
26
27/* To protect the thread/key association data structure modifications. */
29static volatile int __mingwthr_cs_init = 0;
30
32
33/* The list of threads active with key/dtor pairs. */
36 void (*dtor)(void *);
38};
39
40
42
43int
44___w64_mingwthr_add_key_dtor (DWORD key, void (*dtor)(void *))
45{
47
48 if (__mingwthr_cs_init == 0)
49 return 0;
51 if (new_key == NULL)
52 return -1;
53
54 new_key->key = key;
55 new_key->dtor = dtor;
56
58
59 new_key->next = key_dtor_list;
61
63 return 0;
64}
65
66int
68{
69 __mingwthr_key_t volatile *prev_key;
70 __mingwthr_key_t volatile *cur_key;
71
72 if (__mingwthr_cs_init == 0)
73 return 0;
74
76
77 prev_key = NULL;
78 cur_key = key_dtor_list;
79
80 while (cur_key != NULL)
81 {
82 if ( cur_key->key == key)
83 {
84 if (prev_key == NULL)
85 key_dtor_list = cur_key->next;
86 else
87 prev_key->next = cur_key->next;
88
89 free ((void*)cur_key);
90 break;
91 }
92 prev_key = cur_key;
93 cur_key = cur_key->next;
94 }
95
97 return 0;
98}
99
100static void
102{
103 __mingwthr_key_t volatile *keyp;
104
105 if (__mingwthr_cs_init == 0)
106 return;
108
109 for (keyp = key_dtor_list; keyp; )
110 {
111 LPVOID value = TlsGetValue (keyp->key);
112 if (GetLastError () == ERROR_SUCCESS)
113 {
114 if (value)
115 (*keyp->dtor) (value);
116 }
117 keyp = keyp->next;
118 }
119
121}
122
127{
128 switch (reason)
129 {
131 if (__mingwthr_cs_init == 0)
134 break;
137 if (__mingwthr_cs_init == 1)
138 {
141 }
142 break;
144 break;
147 break;
148 }
149 return TRUE;
150}
151
#define __UNUSED_PARAM(x)
Definition: _mingw.h:74
#define free
Definition: debug_ros.c:5
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904
#define DLL_THREAD_DETACH
Definition: compat.h:133
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define DLL_THREAD_ATTACH
Definition: compat.h:132
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1240
static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTKEY **ppCryptKey)
Definition: rsaenh.c:794
r reserved
Definition: btrfs.c:3006
unsigned long DWORD
Definition: ntddk_ex.h:95
#define calloc
Definition: rosglue.h:14
void(* dtor)(void *)
Definition: tlsthrd.c:36
__mingwthr_key_t volatile * next
Definition: tlsthrd.c:37
DWORD key
Definition: tlsthrd.c:35
Definition: copy.c:22
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
static CRITICAL_SECTION __mingwthr_cs
Definition: tlsthrd.c:28
static volatile int __mingwthr_cs_init
Definition: tlsthrd.c:29
int ___w64_mingwthr_remove_key_dtor(DWORD key)
Definition: tlsthrd.c:67
int ___w64_mingwthr_add_key_dtor(DWORD key, void(*dtor)(void *))
Definition: tlsthrd.c:44
WINBOOL __mingw_TLScallback(HANDLE hDllHandle, DWORD reason, LPVOID reserved)
static __mingwthr_key_t volatile * key_dtor_list
Definition: tlsthrd.c:41
static void __mingwthr_run_key_dtors(void)
Definition: tlsthrd.c:101
int32_t WINBOOL
Definition: typedefs.h:58
Definition: pdh_main.c:94
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)