ReactOS  0.4.14-dev-50-g13bb5e2
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;
50  new_key = (__mingwthr_key_t *) calloc (1, sizeof (__mingwthr_key_t));
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 }
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
smooth NULL
Definition: ftsmooth.c:416
static CRITICAL_SECTION __mingwthr_cs
Definition: tlsthrd.c:28
static volatile int __mingwthr_cs_init
Definition: tlsthrd.c:29
HKEY key
Definition: reg.c:42
static __mingwthr_key_t volatile * key_dtor_list
Definition: tlsthrd.c:41
#define calloc
Definition: rosglue.h:14
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTKEY **ppCryptKey)
Definition: rsaenh.c:794

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 }
__mingwthr_key_t volatile * next
Definition: tlsthrd.c:37
#define free
Definition: debug_ros.c:5
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
smooth NULL
Definition: ftsmooth.c:416
static CRITICAL_SECTION __mingwthr_cs
Definition: tlsthrd.c:28
static volatile int __mingwthr_cs_init
Definition: tlsthrd.c:29
DWORD key
Definition: tlsthrd.c:35
static __mingwthr_key_t volatile * key_dtor_list
Definition: tlsthrd.c:41
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
Definition: path.c:42

Referenced by __mingwthr_remove_key_dtor().

◆ __mingw_TLScallback() [1/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

◆ __mingw_TLScallback() [2/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  {
130  case DLL_PROCESS_ATTACH:
131  if (__mingwthr_cs_init == 0)
133  __mingwthr_cs_init = 1;
134  break;
135  case DLL_PROCESS_DETACH:
137  if (__mingwthr_cs_init == 1)
138  {
139  __mingwthr_cs_init = 0;
141  }
142  break;
143  case DLL_THREAD_ATTACH:
144  break;
145  case DLL_THREAD_DETACH:
147  break;
148  }
149  return TRUE;
150 }
#define TRUE
Definition: types.h:120
#define DLL_THREAD_ATTACH
Definition: compat.h:121
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
#define DLL_THREAD_DETACH
Definition: compat.h:122
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
#define DLL_PROCESS_DETACH
Definition: compat.h:119
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
static void __mingwthr_run_key_dtors(void)
Definition: tlsthrd.c:101
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904

◆ __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
__mingwthr_key_t volatile * next
Definition: tlsthrd.c:37
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static CRITICAL_SECTION __mingwthr_cs
Definition: tlsthrd.c:28
static volatile int __mingwthr_cs_init
Definition: tlsthrd.c:29
void(* dtor)(void *)
Definition: tlsthrd.c:36
DWORD key
Definition: tlsthrd.c:35
static __mingwthr_key_t volatile * key_dtor_list
Definition: tlsthrd.c:41
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1228
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by __mingw_TLScallback().

Variable Documentation

◆ __mingwthr_cs

◆ __mingwthr_cs_init

volatile int __mingwthr_cs_init = 0
static

◆ key_dtor_list