ReactOS 0.4.15-dev-7942-gd23573b
tlsthrd.c File Reference
#include <stdlib.h>
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
Include dependency graph for tlsthrd.c:

Go to the source code of this file.

Classes

struct  __mingwthr_key
 

Typedefs

typedef struct __mingwthr_key __mingwthr_key_t
 

Functions

WINBOOL __mingw_TLScallback (HANDLE hDllHandle, DWORD reason, LPVOID reserved)
 
int ___w64_mingwthr_remove_key_dtor (DWORD key)
 
int ___w64_mingwthr_add_key_dtor (DWORD key, void(*dtor)(void *))
 
static void __mingwthr_run_key_dtors (void)
 
WINBOOL __mingw_TLScallback (HANDLE __UNUSED_PARAM(hDllHandle), DWORD reason, LPVOID __UNUSED_PARAM(reserved))
 

Variables

static CRITICAL_SECTION __mingwthr_cs
 
static volatile int __mingwthr_cs_init = 0
 
static __mingwthr_key_t volatilekey_dtor_list
 

Typedef Documentation

◆ __mingwthr_key_t

Definition at line 31 of file tlsthrd.c.

Function Documentation

◆ ___w64_mingwthr_add_key_dtor()

int ___w64_mingwthr_add_key_dtor ( DWORD  key,
void(*)(void *)  dtor 
)

Definition at line 44 of file tlsthrd.c.

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}
#define NULL
Definition: types.h:112
static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTKEY **ppCryptKey)
Definition: rsaenh.c:794
#define calloc
Definition: rosglue.h:14
Definition: copy.c:22
static CRITICAL_SECTION __mingwthr_cs
Definition: tlsthrd.c:28
static volatile int __mingwthr_cs_init
Definition: tlsthrd.c:29
static __mingwthr_key_t volatile * key_dtor_list
Definition: tlsthrd.c:41
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

Referenced by __mingwthr_key_dtor().

◆ ___w64_mingwthr_remove_key_dtor()

int ___w64_mingwthr_remove_key_dtor ( DWORD  key)

Definition at line 67 of file tlsthrd.c.

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}
#define free
Definition: debug_ros.c:5
__mingwthr_key_t volatile * next
Definition: tlsthrd.c:37
DWORD key
Definition: tlsthrd.c:35

Referenced by __mingwthr_remove_key_dtor().

◆ __mingw_TLScallback() [1/2]

WINBOOL __mingw_TLScallback ( HANDLE   __UNUSED_PARAMhDllHandle,
DWORD  reason,
LPVOID   __UNUSED_PARAMreserved 
)

Definition at line 124 of file tlsthrd.c.

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}
#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
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
static void __mingwthr_run_key_dtors(void)
Definition: tlsthrd.c:101
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

◆ __mingw_TLScallback() [2/2]

WINBOOL __mingw_TLScallback ( HANDLE  hDllHandle,
DWORD  reason,
LPVOID  reserved 
)

This file has no copyright assigned and is placed in the Public Domain. This file is part of the w64 mingw-runtime package. No warranty is given; refer to the file DISCLAIMER.PD within this package.

Written by Kai Tietz kai.t.nosp@m.ietz.nosp@m.@onev.nosp@m.isio.nosp@m.n.com

This file is used by if gcc is built with –enable-threads=win32.

Based on version created by Mumit Khan khan@.nosp@m.nano.nosp@m.tech..nosp@m.wisc.nosp@m..edu

◆ __mingwthr_run_key_dtors()

static void __mingwthr_run_key_dtors ( void  )
static

Definition at line 101 of file tlsthrd.c.

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}
#define ERROR_SUCCESS
Definition: deptool.c:10
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1240
void(* dtor)(void *)
Definition: tlsthrd.c:36
Definition: pdh_main.c:94
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by __mingw_TLScallback().

Variable Documentation

◆ __mingwthr_cs

◆ __mingwthr_cs_init

volatile int __mingwthr_cs_init = 0
static

◆ key_dtor_list