add win_alloc, used by wpthread to allocate memory for critical sections (safe allocator that may be called at any time, even before _cinit and during static dtors)
This was SVN commit r1882.
This commit is contained in:
parent
be3be6cede
commit
6d807d1c9f
@ -38,6 +38,26 @@ void sle(int x)
|
||||
SetLastError((DWORD)x);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// safe allocator that may be used independently of libc malloc
|
||||
// (in particular, before _cinit and while calling static dtors).
|
||||
// used by wpthread critical section code.
|
||||
//
|
||||
|
||||
void* win_alloc(size_t size)
|
||||
{
|
||||
const DWORD flags = HEAP_ZERO_MEMORY;
|
||||
return HeapAlloc(GetProcessHeap(), flags, size);
|
||||
}
|
||||
|
||||
void win_free(void* p)
|
||||
{
|
||||
const DWORD flags = 0;
|
||||
HeapFree(GetProcessHeap(), flags, p);
|
||||
}
|
||||
|
||||
|
||||
char win_sys_dir[MAX_PATH+1];
|
||||
char win_exe_dir[MAX_PATH+1];
|
||||
|
||||
|
@ -404,6 +404,11 @@ extern void win_lock(uint idx);
|
||||
extern void win_unlock(uint idx);
|
||||
|
||||
|
||||
|
||||
extern void* win_alloc(size_t size);
|
||||
extern void win_free(void* p);
|
||||
|
||||
|
||||
// thread safe, useable in constructors
|
||||
#define WIN_ONCE(code) \
|
||||
{ \
|
||||
|
@ -158,7 +158,7 @@ void pthread_join(pthread_t thread, void** value_ptr)
|
||||
|
||||
pthread_mutex_t pthread_mutex_initializer()
|
||||
{
|
||||
CRITICAL_SECTION* cs = (CRITICAL_SECTION*)HeapAlloc(GetProcessHeap(), 0, sizeof(CRITICAL_SECTION));
|
||||
CRITICAL_SECTION* cs = (CRITICAL_SECTION*)win_alloc(sizeof(CRITICAL_SECTION));
|
||||
InitializeCriticalSection(cs);
|
||||
return (pthread_mutex_t)cs;
|
||||
}
|
||||
@ -167,7 +167,7 @@ int pthread_mutex_destroy(pthread_mutex_t* m)
|
||||
{
|
||||
CRITICAL_SECTION* cs = (CRITICAL_SECTION*)(*m);
|
||||
DeleteCriticalSection(cs);
|
||||
HeapFree(GetProcessHeap(), 0, cs);
|
||||
win_free(cs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user