Commit 82b94e22 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Change SLAPD shutdown to do a cond wait on active threads instead

of a busy wait and allow the pthread_yield within the loop to be
removed.  This was the only pthread_yield which was necessary
when usng non-preemptive threads.  As such, the configure.in
sched_yield/pthread_yield missing error can be removed from
configure.in.  If explicit yield function is missing, just provide
a no-op replacement.
Moved declaration of various slapd globals from main.c to init.c
so they can be shared with ldbm tools.
parent 334768c1
......@@ -37,7 +37,8 @@ these steps:
CC C Compiler (cc, ecgs)
CFLAGS C Flags (-ansi)
CPPFLAGS CPP Flags (-I/path/include -Ddef)
LDFLAGS LDFLAGS (-L/path/lib -llib)
LDFLAGS LDFLAGS (-L/path/lib)
LIBS LIBS (-llib)
See the 'USING ENVIRONMENT VARIABLES' section for information
on how to use the variables.
......@@ -154,8 +155,8 @@ Supported Environmental Variables
CC C compiler (cc, egcc)
CFLAGS C flags (-ansi)
CPPFLAGS cpp flags (-I/path/include -Ddef)
LDFLAGS ld flags (-s)
LIBS libraries (-L/usr/local/lib -llib)
LDFLAGS ld flags (-L/usr/local/lib)
LIBS libraries (-llib)
PATH command path /usr/local/bin:/usr/bin:/bin
* Including alternative compilers
......
This diff is collapsed.
......@@ -575,7 +575,6 @@ 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
......
......@@ -583,6 +583,9 @@
/* Define if you have the V3 library (-lV3). */
#undef HAVE_LIBV3
/* Define if you have the bind library (-lbind). */
#undef HAVE_LIBBIND
/* Define if you have the dmalloc library (-ldmalloc). */
#undef HAVE_LIBDMALLOC
......
......@@ -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;
}
......
......@@ -393,14 +393,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 );
......
......@@ -12,52 +12,6 @@
#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 slap_debug = 0;
#ifdef LDAP_DEBUG
int ldap_syslog = LDAP_DEBUG_STATS;
#else
int ldap_syslog;
#endif
int ldap_syslog_level = LOG_DEBUG;
int udp;
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;
/*
* when more than one slapd is running on one machine, each one might have
* it's own LOCAL for syslogging and must have its own pid/args files
......@@ -118,11 +72,13 @@ main( int argc, char **argv )
int i;
int inetd = 0;
int port;
int udp;
Backend *be = NULL;
FILE *fp = NULL;
#ifdef LOG_LOCAL4
int syslogUser = DEFAULT_SYSLOG_USER;
#endif
char *configfile;
configfile = SLAPD_DEFAULT_CONFIGFILE;
port = LDAP_PORT;
......
......@@ -242,7 +242,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