summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-05-29 18:32:21 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-05-29 18:32:21 -0400
commit32dd26f4052b57bf1cdc7fad2cc47874ff989cc1 (patch)
tree586ce4398ea36ba4936503f50be568b2806127ae
parentca79c5d953727a31583520ef882316edd62e3bc3 (diff)
- switch to creating a PRThread instead of a pthread
-rwxr-xr-xautogen.sh2
-rw-r--r--configure.ac2
-rw-r--r--src/plugin.c27
-rw-r--r--src/plugin.h6
4 files changed, 33 insertions, 4 deletions
diff --git a/autogen.sh b/autogen.sh
index d963f7b..b39d0d3 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -3,4 +3,4 @@ export CFLAGS="`rpm --eval '%{optflags}'` -Wall -Wimplicit -Wextra -Wuninitializ
libarch=`gcc --print-multi-os-directory`
usrlibarch=`cd /usr/lib/$libarch; /bin/pwd`
libarch=`basename $usrlibarch`
-./configure --prefix=/usr --sysconfdir=/etc --libdir=/usr/$libarch --enable-maintainer-mode --with-server=dirsrv
+./configure --prefix=/usr --sysconfdir=/etc --libdir=/usr/$libarch --enable-maintainer-mode --with-server=dirsrv "$@"
diff --git a/configure.ac b/configure.ac
index 395ecc6..664bb39 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,6 +34,7 @@ dirsrv)
fi
CFLAGS="$saved_CFLAGS"
LIBS="$saved_LIBS"
+ AC_DEFINE(USE_NSPR_THREADS,1,[Define to use NSPR's threading functions.])
;;
*)
RUNTIME_CFLAGS=
@@ -42,6 +43,7 @@ dirsrv)
if test x$ac_cv_header_slapi_plugin_h = xno ; then
AC_ERROR([<slapi-plugin.h> not found])
fi
+ AC_DEFINE(USE_PTHREADS,1,[Define to use POSIX threading functions.])
esac
mylibdir=`eval echo "$libdir" | sed "s,NONE,$ac_default_prefix,g"`
diff --git a/src/plugin.c b/src/plugin.c
index a0f604d..3219f4b 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -30,7 +30,6 @@
#include <errno.h>
#include <netinet/in.h>
#include <poll.h>
-#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
@@ -48,6 +47,10 @@
#include <slapi-plugin.h>
#endif
+#ifdef USE_PTHREADS
+#include <pthread.h>
+#endif
+
#include "dispatch.h"
#include "map.h"
#include "nis.h"
@@ -112,14 +115,32 @@ plugin_startup(Slapi_PBlock *pb)
}
}
}
- /* Start a new listening thread to handle incoming traffic. FIXME:
- * switch to using NSPR's threading facilities. */
+#if defined(USE_PTHREADS)
+ /* Start a new listening thread to handle incoming traffic. */
if (pthread_create(&state->tid, NULL, &dispatch_thread, state) != 0) {
slapi_log_error(SLAPI_LOG_PLUGIN,
plugin_description.spd_id,
"error starting listener thread\n");
return -1;
}
+#elif defined(USE_NSPR_THREADS)
+ /* Start a new listening thread to handle incoming traffic. */
+ state->tid = PR_CreateThread(PR_USER_THREAD,
+ &dispatch_thread,
+ state,
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_JOINABLE_THREAD,
+ 0);
+ if (state->tid == NULL) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ plugin_description.spd_id,
+ "error starting listener thread\n");
+ return -1;
+ }
+#else
+#error "Don't know how to start a thread for your server!"
+#endif
slapi_log_error(SLAPI_LOG_PLUGIN, plugin_description.spd_id,
"plugin startup completed\n");
return 0;
diff --git a/src/plugin.h b/src/plugin.h
index c0c4e60..bce8112 100644
--- a/src/plugin.h
+++ b/src/plugin.h
@@ -23,7 +23,13 @@
#define plugin_h
struct plugin_state {
+#ifdef USE_PTHREADS
pthread_t tid;
+#elif defined(USE_NSPR_THREADS)
+ PRThread *tid;
+#else
+#error "Don't know which threading model to use!"
+#endif
char *plugin_base;
Slapi_ComponentId *plugin_identity;
Slapi_PluginDesc *plugin_desc;