/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * 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
#include "ldap_thr_debug.h" /* May rename the symbols defined below */
#include <signal.h> /* 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
# 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
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;
}
#ifdef LDAP_INT_THREAD_MUTEXATTR
pthread_mutexattr_destroy( &mutex_attr );
#endif
+ pthread_mutexattr_destroy( &mutex_attr_recursive );
return 0;
}
#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
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();