X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap_r%2Fthr_posix.c;h=e68ec0549ce89b9b9d03a9eee14ed1f25404737f;hb=a8f01cc88589a407cb9835b47ece8661c91e6a6b;hp=ec6677f8c7beb1a7f713006d4e4f8fd1eb61ec0a;hpb=dc52a6fcabd71eb6f122aac93d790bb026d4f44b;p=openldap
diff --git a/libraries/libldap_r/thr_posix.c b/libraries/libldap_r/thr_posix.c
index ec6677f8c7..e68ec0549c 100644
--- a/libraries/libldap_r/thr_posix.c
+++ b/libraries/libldap_r/thr_posix.c
@@ -2,7 +2,7 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
- * Copyright 1998-2015 The OpenLDAP Foundation.
+ * Copyright 1998-2017 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -33,6 +33,8 @@
#include "ldap_thr_debug.h" /* May rename the symbols defined below */
#include /* For pthread_kill() */
+extern int ldap_int_stackguard;
+
#if HAVE_PTHREADS < 6
# define LDAP_INT_THREAD_ATTR_DEFAULT pthread_attr_default
# define LDAP_INT_THREAD_CONDATTR_DEFAULT pthread_condattr_default
@@ -56,6 +58,8 @@ static pthread_mutexattr_t mutex_attr;
# define LDAP_INT_THREAD_MUTEXATTR_DEFAULT &mutex_attr
#endif
+static pthread_mutexattr_t mutex_attr_recursive;
+
#if HAVE_PTHREADS < 7
#define ERRVAL(val) ((val) < 0 ? errno : 0)
#else
@@ -69,6 +73,10 @@ ldap_int_thread_initialize( void )
pthread_mutexattr_init( &mutex_attr );
pthread_mutexattr_settype( &mutex_attr, LDAP_INT_THREAD_MUTEXATTR );
#endif
+ if (pthread_mutexattr_init(&mutex_attr_recursive))
+ return -1;
+ if (pthread_mutexattr_settype(&mutex_attr_recursive, PTHREAD_MUTEX_RECURSIVE))
+ return -1;
return 0;
}
@@ -82,6 +90,7 @@ ldap_int_thread_destroy( void )
#ifdef LDAP_INT_THREAD_MUTEXATTR
pthread_mutexattr_destroy( &mutex_attr );
#endif
+ pthread_mutexattr_destroy( &mutex_attr_recursive );
return 0;
}
@@ -148,6 +157,8 @@ ldap_pvt_thread_create( ldap_pvt_thread_t * thread,
#ifdef LDAP_PVT_THREAD_SET_STACK_SIZE
/* this should be tunable */
pthread_attr_setstacksize( &attr, LDAP_PVT_THREAD_STACK_SIZE );
+ if ( ldap_int_stackguard )
+ pthread_attr_setguardsize( &attr, LDAP_PVT_THREAD_STACK_SIZE );
#endif
#if HAVE_PTHREADS > 5
@@ -308,6 +319,21 @@ ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
return ERRVAL( pthread_mutex_unlock( mutex ) );
}
+int
+ldap_pvt_thread_mutex_recursive_init( ldap_pvt_thread_mutex_t *mutex )
+{
+ return ERRVAL( pthread_mutex_init( mutex, &mutex_attr_recursive ) );
+}
+
+int ldap_pvt_thread_mutex_recursive_destroy( ldap_pvt_thread_mutex_recursive_t *mutex )
+ LDAP_GCCATTR((alias("ldap_pvt_thread_mutex_destroy")));
+int ldap_pvt_thread_mutex_recursive_lock( ldap_pvt_thread_mutex_recursive_t *mutex )
+ LDAP_GCCATTR((alias("ldap_pvt_thread_mutex_lock")));
+int ldap_pvt_thread_mutex_recursive_trylock( ldap_pvt_thread_mutex_recursive_t *mutex )
+ LDAP_GCCATTR((alias("ldap_pvt_thread_mutex_trylock")));
+int ldap_pvt_thread_mutex_recursive_unlock( ldap_pvt_thread_mutex_recursive_t *mutex )
+ LDAP_GCCATTR((alias("ldap_pvt_thread_mutex_unlock")));
+
ldap_pvt_thread_t ldap_pvt_thread_self( void )
{
return pthread_self();