Skip to content
Snippets Groups Projects
Commit 61bdf0e6 authored by Howard Chu's avatar Howard Chu Committed by Quanah Gibson-Mount
Browse files

ITS#9181 Fix race on Windows mutex init

parent 4d590c95
No related branches found
No related tags found
No related merge requests found
......@@ -180,10 +180,13 @@ typedef HANDLE ldap_int_thread_mutex_t;
typedef HANDLE ldap_int_thread_cond_t;
typedef DWORD ldap_int_thread_key_t;
LDAP_F( int )
ldap_pvt_thread_mutex_init_first LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
#ifndef LDAP_INT_MUTEX_NULL
#define LDAP_INT_MUTEX_NULL ((HANDLE)0)
#define LDAP_INT_MUTEX_FIRSTCREATE(m) \
((void) ((m) || ldap_pvt_thread_mutex_init(&(m))))
ldap_pvt_thread_mutex_init_first(&(m))
#endif
LDAP_END_DECL
......
......@@ -161,6 +161,17 @@ ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
return ( 0 );
}
int
ldap_pvt_thread_mutex_init_first( ldap_pvt_thread_mutex_t *mutex )
{
if ( *mutex == NULL ) {
HANDLE p = CreateMutex( NULL, 0, NULL );
if ( InterlockedCompareExchangePointer((PVOID*)mutex, (PVOID)p, NULL) != NULL)
CloseHandle( p );
}
return ( 0 );
}
int
ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment