mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-20 22:59:34 -05:00
ITS#9181 Fix race on Windows mutex init
This commit is contained in:
parent
2d87a1c7b5
commit
4f7ea78c95
2 changed files with 15 additions and 1 deletions
|
|
@ -152,10 +152,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_recursive_init( ldap_pvt_thread_mutex_t *mutex )
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue