Commit 30e6b973 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Import slapd changes from devel including:

	shutdown without busy loop, explicit yield func no longer mandatory
	use pthread_detach() to detach threads (instead of creating them
		in a detached state)
	pthread_create error reporting
	moved declarations to init.c
Import configure changes:
	revamp res_search check
	remove strtok_r check
parent 17b4826d
This diff is collapsed.
......@@ -582,11 +582,11 @@ if test $ol_with_threads = auto -o $ol_with_threads = yes \
if test $ac_cv_func_sched_yield = no -a \
$ac_cv_func_pthread_yield = no ; then
AC_MSG_WARN([could not locate sched_yield() or pthread_yield()])
AC_MSG_ERROR([POSIX Threads are not usable])
fi
dnl Check functions for compatibility
AC_CHECK_FUNCS(pthread_kill)
AC_CHECK_FUNCS(pthread_kill pthread_detach)
AC_CHECK_FUNCS( \
pthread_attr_create pthread_attr_init \
pthread_attr_destroy pthread_attr_delete \
......@@ -856,25 +856,6 @@ int x = errno;
LIBS="$LTHREAD_LIBS $LIBS"
LTHREAD_LIBS=""
fi
dnl check for reentrant/threadsafe functions
dnl
dnl note: these should only be used when linking
dnl with $LTHREAD_LIBS
dnl
save_CPPFLAGS="$CPPFLAGS"
save_LIBS="$LIBS"
LIBS="$LTHREAD_LIBS $LIBS"
AC_CHECK_FUNCS( \
strtok_r \
gmtime_r \
gethostbyaddr_r gethostbyname_r \
feof_unlocked unlocked_feof \
putc_unlocked unlocked_putc \
flockfile ftrylockfile \
)
CPPFLAGS="$save_CPPFLAGS"
LIBS="$save_LIBS"
fi
dnl ----------------------------------------------------------------
......
......@@ -278,27 +278,12 @@
/* Define if you have the bcopy function. */
#undef HAVE_BCOPY
/* Define if you have the feof_unlocked function. */
#undef HAVE_FEOF_UNLOCKED
/* Define if you have the flock function. */
#undef HAVE_FLOCK
/* Define if you have the flockfile function. */
#undef HAVE_FLOCKFILE
/* Define if you have the ftrylockfile function. */
#undef HAVE_FTRYLOCKFILE
/* Define if you have the getdtablesize function. */
#undef HAVE_GETDTABLESIZE
/* Define if you have the gethostbyaddr_r function. */
#undef HAVE_GETHOSTBYADDR_R
/* Define if you have the gethostbyname_r function. */
#undef HAVE_GETHOSTBYNAME_R
/* Define if you have the gethostname function. */
#undef HAVE_GETHOSTNAME
......@@ -311,9 +296,6 @@
/* Define if you have the gettimeofday function. */
#undef HAVE_GETTIMEOFDAY
/* Define if you have the gmtime_r function. */
#undef HAVE_GMTIME_R
/* Define if you have the lockf function. */
#undef HAVE_LOCKF
......@@ -344,6 +326,9 @@
/* Define if you have the pthread_attr_setdetachstate function. */
#undef HAVE_PTHREAD_ATTR_SETDETACHSTATE
/* Define if you have the pthread_detach function. */
#undef HAVE_PTHREAD_DETACH
/* Define if you have the pthread_kill function. */
#undef HAVE_PTHREAD_KILL
......@@ -353,9 +338,6 @@
/* Define if you have the pthread_yield function. */
#undef HAVE_PTHREAD_YIELD
/* Define if you have the putc_unlocked function. */
#undef HAVE_PUTC_UNLOCKED
/* Define if you have the res_search function. */
#undef HAVE_RES_SEARCH
......@@ -404,9 +386,6 @@
/* Define if you have the strtok function. */
#undef HAVE_STRTOK
/* Define if you have the strtok_r function. */
#undef HAVE_STRTOK_R
/* Define if you have the strtol function. */
#undef HAVE_STRTOL
......@@ -422,12 +401,6 @@
/* Define if you have the thr_setconcurrency function. */
#undef HAVE_THR_SETCONCURRENCY
/* Define if you have the unlocked_feof function. */
#undef HAVE_UNLOCKED_FEOF
/* Define if you have the unlocked_putc function. */
#undef HAVE_UNLOCKED_PUTC
/* Define if you have the vsnprintf function. */
#undef HAVE_VSNPRINTF
......
......@@ -7,12 +7,11 @@
#if defined( HAVE_PTHREADS )
#ifndef HAVE_PTHREAD_KILL
/***********************************************************************
* *
* pthreads package with DCE - no mapping to do (except to create a *
* pthread_kill() routine) *
* *
***********************************************************************/
/*
* Some pthreads packages (ie: DCE) don't have pthread_kill()
* pthread_kill() routine)
*
*/
/* ARGSUSED */
void
......@@ -22,6 +21,19 @@ pthread_kill( pthread_t tid, int sig )
}
#endif /* HAVE_PTHREAD_KILL */
#if !defined(HAVE_SCHED_YIELD) && !defined(HAVE_PTHREAD_YIELD)
/*
* Some pthreads packages don't have sched_yield() nor
* the draft4 pthread_kill() routine, assume it's not
* needed.
*/
void
pthread_yield( void )
{
/* assume pthread implementation is preemptive */
}
#endif /* missing sched_yield() */
#elif defined( HAVE_MACH_CTHREADS )
/***********************************************************************
......
......@@ -100,6 +100,9 @@ connection_operation( void *arg_v )
pthread_mutex_lock( &active_threads_mutex );
active_threads--;
if( active_threads < 1 ) {
pthread_cond_signal(&active_threads_cond);
}
pthread_mutex_unlock( &active_threads_mutex );
return NULL;
}
......@@ -109,7 +112,10 @@ connection_activity(
Connection *conn
)
{
#ifndef HAVE_PTHREAD_DETACH
pthread_attr_t attr;
#endif
int status;
struct co_arg *arg;
unsigned long tag, len;
long msgid;
......@@ -192,15 +198,33 @@ connection_activity(
free( tmpdn );
}
#ifdef HAVE_PTHREAD_DETACH
if ( status = pthread_create( &arg->co_op->o_tid, NULL,
connection_operation, (void *) arg ) != 0 ) {
Debug( LDAP_DEBUG_ANY, "pthread_create failed (%d)\n", status, 0, 0 );
} else {
pthread_mutex_lock( &active_threads_mutex );
active_threads++;
pthread_mutex_unlock( &active_threads_mutex );
}
#if !defined(HAVE_PTHREADS_D4)
pthread_detach( arg->co_op->o_tid );
#else
pthread_detach( &arg->co_op->o_tid );
#endif
#else /* !pthread detach */
pthread_attr_init( &attr );
pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
#if !defined(HAVE_PTHREADS_D4)
/* POSIX_THREADS or compatible
* This is a draft 10 or standard pthreads implementation
*/
if ( pthread_create( &arg->co_op->o_tid, &attr,
if ( status = pthread_create( &arg->co_op->o_tid, &attr,
connection_operation, (void *) arg ) != 0 ) {
Debug( LDAP_DEBUG_ANY, "pthread_create failed\n", 0, 0, 0 );
Debug( LDAP_DEBUG_ANY, "pthread_create failed (%d)\n", status, 0, 0 );
} else {
pthread_mutex_lock( &active_threads_mutex );
active_threads++;
......@@ -210,9 +234,9 @@ connection_activity(
/*
* This is a draft 4 or earlier pthreads implementation
*/
if ( pthread_create( &arg->co_op->o_tid, attr,
if ( status = pthread_create( &arg->co_op->o_tid, attr,
connection_operation, (void *) arg ) != 0 ) {
Debug( LDAP_DEBUG_ANY, "pthread_create failed\n", 0, 0, 0 );
Debug( LDAP_DEBUG_ANY, "pthread_create failed (%d)\n", status, 0, 0 );
} else {
pthread_mutex_lock( &active_threads_mutex );
active_threads++;
......@@ -220,4 +244,5 @@ connection_activity(
}
#endif /* pthread draft4 */
pthread_attr_destroy( &attr );
#endif
}
......@@ -36,6 +36,7 @@ int deny_severity = LOG_NOTICE;
int dtblsize;
Connection *c;
static int slapd_shutdown = 0;
static void set_shutdown(int sig);
static void do_nothing (int sig);
......@@ -369,14 +370,13 @@ slapd_daemon(
}
close( tcps );
pthread_mutex_lock( &active_threads_mutex );
Debug( LDAP_DEBUG_ANY,
"slapd shutting down - waiting for %d threads to terminate\n",
active_threads, 0, 0 );
while ( active_threads > 0 ) {
pthread_mutex_unlock( &active_threads_mutex );
pthread_yield();
pthread_mutex_lock( &active_threads_mutex );
pthread_cond_wait(&active_threads_cond, &active_threads_mutex);
}
pthread_mutex_unlock( &active_threads_mutex );
......
......@@ -11,10 +11,63 @@
#include "portable.h"
#include "slap.h"
/*
* read-only global variables or variables only written by the listener
* thread (after they are initialized) - no need to protect them with a mutex.
*/
int slap_debug = 0;
#ifdef LDAP_DEBUG
int ldap_syslog = LDAP_DEBUG_STATS;
#else
int ldap_syslog;
#endif
int ldap_syslog_level = LOG_DEBUG;
char *default_referral;
time_t starttime;
pthread_t listener_tid;
int g_argc;
char **g_argv;
/*
* global variables that need mutex protection
*/
int active_threads;
pthread_mutex_t active_threads_mutex;
pthread_cond_t active_threads_cond;
time_t currenttime;
pthread_mutex_t currenttime_mutex;
pthread_mutex_t new_conn_mutex;
#ifdef SLAPD_CRYPT
pthread_mutex_t crypt_mutex;
#endif
pthread_mutex_t strtok_mutex;
int num_conns;
long ops_initiated;
long ops_completed;
pthread_mutex_t ops_mutex;
long num_entries_sent;
long num_bytes_sent;
pthread_mutex_t num_sent_mutex;
/*
* these mutexes must be used when calling the entry2str()
* routine since it returns a pointer to static data.
*/
pthread_mutex_t entry2str_mutex;
pthread_mutex_t replog_mutex;
void
init( void )
{
pthread_mutex_init( &active_threads_mutex, pthread_mutexattr_default );
pthread_cond_init( &active_threads_cond, pthread_condattr_default );
pthread_mutex_init( &new_conn_mutex, pthread_mutexattr_default );
pthread_mutex_init( &currenttime_mutex, pthread_mutexattr_default );
pthread_mutex_init( &strtok_mutex, pthread_mutexattr_default );
......
......@@ -11,52 +11,6 @@
#include "slap.h"
#include "lutil.h" /* Get lutil_detach() */
/*
* read-only global variables or variables only written by the listener
* thread (after they are initialized) - no need to protect them with a mutex.
*/
int ldap_debug = 0;
#ifdef LDAP_DEBUG
int ldap_syslog = LDAP_DEBUG_STATS;
#else
int ldap_syslog;
#endif
int ldap_syslog_level = LOG_DEBUG;
int udp;
int slapd_shutdown;
char *default_referral;
char *configfile;
time_t starttime;
pthread_t listener_tid;
int g_argc;
char **g_argv;
/*
* global variables that need mutex protection
*/
time_t currenttime;
pthread_mutex_t currenttime_mutex;
pthread_mutex_t strtok_mutex;
int active_threads;
pthread_mutex_t active_threads_mutex;
pthread_mutex_t new_conn_mutex;
#ifdef SLAPD_CRYPT
pthread_mutex_t crypt_mutex;
#endif
long ops_initiated;
long ops_completed;
int num_conns;
pthread_mutex_t ops_mutex;
long num_entries_sent;
long num_bytes_sent;
pthread_mutex_t num_sent_mutex;
/*
* these mutexes must be used when calling the entry2str()
* routine since it returns a pointer to static data.
*/
pthread_mutex_t entry2str_mutex;
pthread_mutex_t replog_mutex;
static void
usage( char *name )
{
......@@ -70,8 +24,10 @@ main( int argc, char **argv )
int inetd = 0;
int port;
char *myname;
int udp;
Backend *be = NULL;
FILE *fp = NULL;
char *configfile;
configfile = SLAPD_DEFAULT_CONFIGFILE;
port = LDAP_PORT;
......
......@@ -239,7 +239,10 @@ extern long num_bytes_sent;
extern long num_entries_sent;
extern long ops_completed;
extern long ops_initiated;
extern pthread_mutex_t active_threads_mutex;
extern pthread_cond_t active_threads_cond;
extern pthread_mutex_t currenttime_mutex;
extern pthread_mutex_t strtok_mutex;
extern pthread_mutex_t entry2str_mutex;
......
......@@ -116,6 +116,10 @@ send_ldap_result2(
pthread_kill( listener_tid, LDAP_SIGUSR1 );
pthread_cond_wait( &conn->c_wcv, &active_threads_mutex );
if( active_threads < 1 ) {
pthread_cond_signal(&active_threads_cond);
}
pthread_mutex_unlock( &active_threads_mutex );
pthread_yield();
......@@ -346,6 +350,10 @@ send_search_entry(
conn->c_writewaiter = 1;
pthread_kill( listener_tid, LDAP_SIGUSR1 );
pthread_cond_wait( &conn->c_wcv, &active_threads_mutex );
if( active_threads < 1 ) {
pthread_cond_signal(&active_threads_cond);
}
pthread_mutex_unlock( &active_threads_mutex );
pthread_yield();
......
......@@ -31,31 +31,9 @@ static void free_and_close(struct dbcache *dbc, Datum key, Datum data);
static void edit_entry(char c, Datum *data);
static void get_keydata(FILE *fp, char c, Datum *key, Datum *data);
struct dbcache *dbc;
LDBM dbp;
char *tailorfile;
Backend *be = NULL;
int ldap_debug;
int ldap_syslog;
int ldap_syslog_level;
long num_entries_sent;
long num_bytes_sent;
int active_threads;
char *default_referral;
time_t currenttime;
pthread_t listener_tid;
pthread_mutex_t num_sent_mutex;
pthread_mutex_t entry2str_mutex;
pthread_mutex_t active_threads_mutex;
pthread_mutex_t new_conn_mutex;
pthread_mutex_t currenttime_mutex;
pthread_mutex_t strtok_mutex;
pthread_mutex_t replog_mutex;
pthread_mutex_t ops_mutex;
pthread_mutex_t regex_mutex;
#ifdef SLAPD_CRYPT
pthread_mutex_t crypt_mutex;
#endif
static struct dbcache *dbc;
static LDBM dbp;
static Backend *be = NULL;
int
main( int argc, char **argv )
......@@ -67,6 +45,7 @@ main( int argc, char **argv )
IDList *idl;
Backend *tbe;
int i;
char *tailorfile;
#ifdef HAVE_BERKELEY_DB2
DBC *cursorp;
......
......@@ -11,10 +11,6 @@
#include "ldap.h"
#include "ldif.h"
int ldap_syslog;
int ldap_syslog_level;
static void
usage( char *name )
{
......
......@@ -16,29 +16,6 @@
#define MAXARGS 100
int lineno;
int ldap_debug;
int ldap_syslog;
int ldap_syslog_level;
long num_entries_sent;
long num_bytes_sent;
int active_threads;
char *default_referral;
time_t currenttime;
pthread_t listener_tid;
pthread_mutex_t num_sent_mutex;
pthread_mutex_t entry2str_mutex;
pthread_mutex_t active_threads_mutex;
pthread_mutex_t new_conn_mutex;
pthread_mutex_t currenttime_mutex;
pthread_mutex_t strtok_mutex;
pthread_mutex_t replog_mutex;
pthread_mutex_t ops_mutex;
pthread_mutex_t regex_mutex;
#ifdef SLAPD_CRYPT
pthread_mutex_t crypt_mutex;
#endif
static char *tailorfile;
static char *inputfile;
......
......@@ -14,28 +14,6 @@
#define MAXARGS 100
int ldap_debug;
int ldap_syslog;
int ldap_syslog_level;
long num_entries_sent;
long num_bytes_sent;
int active_threads;
char *default_referral;
time_t currenttime;
pthread_t listener_tid;
pthread_mutex_t num_sent_mutex;
pthread_mutex_t entry2str_mutex;
pthread_mutex_t active_threads_mutex;
pthread_mutex_t new_conn_mutex;
pthread_mutex_t currenttime_mutex;
pthread_mutex_t strtok_mutex;
pthread_mutex_t replog_mutex;
pthread_mutex_t ops_mutex;
pthread_mutex_t regex_mutex;
#ifdef SLAPD_CRYPT
pthread_mutex_t crypt_mutex;
#endif
static char *tailorfile;
static char *inputfile;
......
......@@ -16,29 +16,6 @@
#define MAXARGS 100
int ldap_debug;
int ldap_syslog;
int ldap_syslog_level;
long num_entries_sent;
long num_bytes_sent;
int active_threads;
char *default_referral;
time_t currenttime;
pthread_t listener_tid;
pthread_mutex_t num_sent_mutex;
pthread_mutex_t entry2str_mutex;
pthread_mutex_t active_threads_mutex;
pthread_mutex_t new_conn_mutex;
pthread_mutex_t currenttime_mutex;
pthread_mutex_t strtok_mutex;
pthread_mutex_t replog_mutex;
pthread_mutex_t ops_mutex;
pthread_mutex_t regex_mutex;
#ifdef SLAPD_CRYPT
pthread_mutex_t crypt_mutex;
#endif
static void
usage( char *name )
{
......
......@@ -20,28 +20,6 @@
#define ID2CHILDRENCMD "ldif2id2children"
#define MAXARGS 100
int ldap_debug;
int ldap_syslog;
int ldap_syslog_level;
long num_entries_sent;
long num_bytes_sent;
int active_threads;
char *default_referral;
time_t currenttime;
pthread_t listener_tid;
pthread_mutex_t num_sent_mutex;
pthread_mutex_t entry2str_mutex;
pthread_mutex_t active_threads_mutex;
pthread_mutex_t new_conn_mutex;
pthread_mutex_t currenttime_mutex;
pthread_mutex_t strtok_mutex;
pthread_mutex_t replog_mutex;
pthread_mutex_t ops_mutex;
pthread_mutex_t regex_mutex;
#ifdef SLAPD_CRYPT
pthread_mutex_t crypt_mutex;
#endif
static void fork_child( char *prog, char *args[] );
static void wait4kids( int nkidval );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment