Skip to content

Commit

Permalink
svn merge -r5765:5774 svn+ssh://svn3.okws.org/home/max/svnrepos/okws2…
Browse files Browse the repository at this point in the history
…/branches/3.1.14 ; version bump to 3.1.14pre1. With this release, we're reintegrating pthreads for linux and freebsd, for another attempt to retire PTH.

git-svn-id: svn://okws.org/okws2/devel/3.1@5775 7d287422-6eea-da11-b677-00123f2a783a
  • Loading branch information
max committed Sep 13, 2011
1 parent e842db1 commit 7629d1e
Show file tree
Hide file tree
Showing 13 changed files with 599 additions and 149 deletions.
109 changes: 45 additions & 64 deletions acokws.m4
Expand Up @@ -138,6 +138,14 @@ AC_DEFUN([OKWS_MYSQL],
[AC_ARG_WITH(mysql, [AC_ARG_WITH(mysql,
--with-mysql=DIR Specific location of mysqlclient library) --with-mysql=DIR Specific location of mysqlclient library)
if test "$with_mysql" != "no"; then if test "$with_mysql" != "no"; then
libname="mysqlclient"
dnl For true pthread multithreading, we need the threaded
dnl reentrant version of mysqlclient
if test "${ac_do_pthreads}" = "1"; then
libname="mysqlclient_r"
fi
ac_save_CFLAGS=$CFLAGS ac_save_CFLAGS=$CFLAGS
ac_save_LIBS=$LIBS ac_save_LIBS=$LIBS
cdirs="${with_mysql}/include ${with_mysql}/include/mysql \ cdirs="${with_mysql}/include ${with_mysql}/include/mysql \
Expand Down Expand Up @@ -170,8 +178,8 @@ if test "$with_mysql" != "no"; then
[for dir in "" " " $dirs; do [for dir in "" " " $dirs; do
case $dir in case $dir in
"") lflags=" " ;; "") lflags=" " ;;
" ") lflags="-lmysqlclient -lm" ;; " ") lflags="-l$libname -lm" ;;
*) lflags="-L${dir} -lmysqlclient -lm" ;; *) lflags="-L${dir} -l$libname -lm" ;;
esac esac
LIBS="$ac_save_LIBS $lflags" LIBS="$ac_save_LIBS $lflags"
AC_TRY_LINK([#include "mysql.h"], AC_TRY_LINK([#include "mysql.h"],
Expand Down Expand Up @@ -333,57 +341,27 @@ AC_SUBST(LDADD_THR)
dnl dnl
dnl Find pthreads dnl Find pthreads
dnl dnl
AC_DEFUN([OKWS_FIND_PTHREADS], AC_DEFUN([OKWS_DO_PTHREADS],
[AC_ARG_WITH(pthreads, [AC_ARG_ENABLE(pthreads,
--with-pthreads=DIR Specify location of pthreads) --enable-pthreads Allow OKWS to use standard pthreads)
ac_save_CFLAGS=$CFLAGS if test `uname` = "Linux"; then
ac_save_LIBS=$LIBS ac_do_pthreads=1
dirs="$with_pthreads ${prefix} ${prefix}/pthreads" if test "${enable_pthreads}" = "no"; then
dirs="$dirs /usr/local /usr/local/pthreads" ac_do_pthreads=0
AC_CACHE_CHECK(for pthread.h, sfs_cv_pthread_h, fi
[for dir in " " $dirs; do else
case $dir in ac_do_pthreads=0
" ") iflags=" " ;; if test "${enable_pthreads}" = "yes" ; then
*) iflags="-I${dir}/include" ;; ac_do_pthreads=1
esac fi
CFLAGS="${ac_save_CFLAGS} $iflags"
AC_TRY_COMPILE([#include <pthread.h>], 0,
sfs_cv_pthread_h="${iflags}"; break)
done
if test "$sfs_cv_pthread_h" = " "; then
sfs_cv_pthread_h="yes"
fi
])
if test "$sfs_cv_pthread_h" = "yes"; then
sfs_cv_pthread_h=" "
fi
if test "${sfs_cv_pthread_h+set}"; then
AC_CACHE_CHECK(for libpthread, sfs_cv_libpthread,
[for dir in "" " " $dirs; do
case $dir in
"") lflags=" " ;;
" ") lflags="-lpthread" ;;
*) lflags="-L${dir}/lib -lpthread" ;;
esac
LIBS="$ac_save_LIBS $lflags"
AC_TRY_LINK([#include <pthread.h>],
pthread_create (0, 0, 0, 0);,
sfs_cv_libpthread=$lflags; break)
done
if test -z ${sfs_cv_libpthread+set}; then
sfs_cv_libpthread="no"
fi])
fi fi
if test "$sfs_cv_libpthread" != "no" && test "${sfs_cv_libpthread+set}" ; then
CFLAGS=$ac_save_CFLAGS if test $ac_do_pthreads -eq 1 ; then
CPPFLAGS="$CPPFLAGS $sfs_cv_pthread_h" AC_DEFINE(HAVE_PTHREADS, 1, Use pthread support)
LIBS="$ac_save_LIBS $sfs_cv_libpthread"
LDADD_PTHREAD="$sfs_cv_libpthread"
use_pthreads=yes
fi fi
AM_CONDITIONAL(USE_PTHREADS, test "${use_pthreads}" != "no")
LIBS=$ac_save_LIBS AM_CONDITIONAL(USE_PTHREADS, test ${ac_do_pthreads} -eq 1)
CFLAGS=$ac_save_CFLAGS
]) ])


dnl dnl
Expand All @@ -400,19 +378,15 @@ fi])
dnl dnl
dnl Check that some threading exists dnl Check that some threading exists
dnl dnl
AC_DEFUN([OKWS_REQUIRE_THREADS], AC_DEFUN([OKWS_DO_THREADS],
[ [
dnl AC_ARG_ENABLE(pthreads, if test `uname` != "Linux"
dnl --disable-pthreads Disable POSIX pthreads library, []) then
OKWS_FIND_PTH
dnl fi
dnl Either PTH, or nothing, since the other threading doesn't currently OKWS_DO_PTHREADS
dnl work.
dnl
OKWS_FIND_PTH
AC_SUBST(LDADD_THR)
]) ])

#include <unistd.h> #include <unistd.h>
#include <grp.h> #include <grp.h>
int getgrouplist ([$*]); int getgrouplist ([$*]);
Expand Down Expand Up @@ -765,6 +739,9 @@ if test -f ${with_okws}/Makefile -a -f ${with_okws}/okwsconf.h; then
LIBOKXML=${with_okws}/libokxml/libokxml.la LIBOKXML=${with_okws}/libokxml/libokxml.la
LIBWEB=${with_okws}/libweb/libweb.la LIBWEB=${with_okws}/libweb/libweb.la
LIBAMT=${with_okws}/libamt/libamt.la LIBAMT=${with_okws}/libamt/libamt.la
if test "${ac_do_pthreads}" = "1"; then
LIBAMT_PTHREAD=${with_okws}/libamt_pthread/libamt_pthread.la
fi
LIBAHTTP=${with_okws}/libahttp/libahttp.la LIBAHTTP=${with_okws}/libahttp/libahttp.la
LIBAMYSQL=${with_okws}/libamysql/libamysql.la LIBAMYSQL=${with_okws}/libamysql/libamysql.la
LIBOKSSL=${with_okws}/libokssl/libokssl.la LIBOKSSL=${with_okws}/libokssl/libokssl.la
Expand All @@ -788,6 +765,9 @@ elif test -f ${with_okws}/include/${okwsstem}/okwsconf.h \
LIBOKXML=${okwslibdir}/libokxml.la LIBOKXML=${okwslibdir}/libokxml.la
LIBWEB=${okwslibdir}/libweb.la LIBWEB=${okwslibdir}/libweb.la
LIBAMT=${okwslibdir}/libamt.la LIBAMT=${okwslibdir}/libamt.la
if test "${ac_do_pthreads}" = "1"; then
LIBAMT_PTHREAD=${okwslibdir}/libamt_pthread.la
fi
LIBAHTTP=${okwslibdir}/libahttp.la LIBAHTTP=${okwslibdir}/libahttp.la
LIBAMYSQL=${okwslibdir}/libamysql.la LIBAMYSQL=${okwslibdir}/libamysql.la
LIBOKSSL=${okwslibdir}/libokssl.la LIBOKSSL=${okwslibdir}/libokssl.la
Expand Down Expand Up @@ -825,6 +805,7 @@ AC_SUBST(LIBOKXML)
AC_SUBST(LIBAHTTP) AC_SUBST(LIBAHTTP)
AC_SUBST(LIBRFN) AC_SUBST(LIBRFN)
AC_SUBST(LIBAMT) AC_SUBST(LIBAMT)
AC_SUBST(LIBAMT_PTHREAD)
AC_SUBST(LIBWEB) AC_SUBST(LIBWEB)
AC_SUBST(LIBOKSSL) AC_SUBST(LIBOKSSL)
AC_SUBST(LIBAMYSQL) AC_SUBST(LIBAMYSQL)
Expand All @@ -836,9 +817,9 @@ AC_SUBST(OKWS_LIB_MK)
LIBS='$(LIBEXPAT) $(LIBSSL)'"$LIBS" LIBS='$(LIBEXPAT) $(LIBSSL)'"$LIBS"
LDEPS='$(LIBRFN) $(LIBWEB) $(LIBOKSSL) $(LIBAOK) $(LIBOKXML) $(LIBAHTTP) $(LIBPUB)'" $LDEPS" LDEPS='$(LIBRFN) $(LIBWEB) $(LIBOKSSL) $(LIBAOK) $(LIBOKXML) $(LIBAHTTP) $(LIBPUB)'" $LDEPS"
LDEPS_DB='$(LIBAMYSQL) $(LIBAMT) '" $LDEPS" LDEPS_DB='$(LIBAMYSQL) $(LIBAMT) $(LIBAMT_PTHREAD) '" $LDEPS"
LDADD='$(LIBRFN) $(LIBWEB) $(LIBOKSSL) $(LIBAOK) $(LIBAHTTP) $(LIBOKXML) $(LIBPUB)'" $LDADD" LDADD='$(LIBRFN) $(LIBWEB) $(LIBOKSSL) $(LIBAOK) $(LIBAHTTP) $(LIBOKXML) $(LIBPUB)'" $LDADD"
LDADD_DB='$(LIBAMYSQL) $(LIBAMT) '"$LDADD "'$(LDADD_THR) $(LDADD_MYSQL)' LDADD_DB='$(LIBAMYSQL) $(LIBAMT) $(LIBAMT_PTHREAD)'"$LDADD "'$(LDADD_THR) $(LDADD_MYSQL)'
AC_SUBST(LDEPS) AC_SUBST(LDEPS)
AC_SUBST(LDADD) AC_SUBST(LDADD)
Expand Down
35 changes: 15 additions & 20 deletions configure.in
Expand Up @@ -4,10 +4,10 @@ dnl Process this file with autoconf to produce a configure script.
dnl dnl


AC_INIT(config.h.in) AC_INIT(config.h.in)
AM_INIT_AUTOMAKE(okws, 3.1.13.11) AM_INIT_AUTOMAKE(okws, 3.1.14pre1)
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)


SFS_INIT_LDVERSION(2500, SFSLITE_ABI_VERSION) SFS_INIT_LDVERSION(2600, SFSLITE_ABI_VERSION)


AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])


Expand All @@ -31,20 +31,11 @@ AC_PATH_PROGS(M4, gm4 gnum4 m4, '$(top_srcdir)/missing')
AC_PATH_PROGS(UPTIME, uptime, '$(top_srcdir)/missing') AC_PATH_PROGS(UPTIME, uptime, '$(top_srcdir)/missing')


dnl dnl
dnl make sure that some type of threading is available. dnl On FreeBSD, look for PTH by default. However, PTH stopped working
dnl on Linux with hard system calls, so use pthreads by default on
dnl Linux, and don't give the option for PTH.
dnl dnl
dnl SFS_REQUIRE_THREADS OKWS_DO_THREADS

dnl
dnl Pthreads now work on all platforms; but don't interoperate
dnl well with pth.
dnl
OKWS_FIND_PTHREADS

dnl
dnl PTH is still on by default but can be disabled.
dnl
OKWS_FIND_PTH


test "$PUB" || PUB='$(top_builddir)/pub/pub' test "$PUB" || PUB='$(top_builddir)/pub/pub'
test "$XMLRPCC" || XMLRPCC='$(top_builddir)/xmlrpcc/xmlrpcc' test "$XMLRPCC" || XMLRPCC='$(top_builddir)/xmlrpcc/xmlrpcc'
Expand Down Expand Up @@ -129,7 +120,7 @@ done
dnl dnl
dnl library directories dnl library directories
dnl dnl
for lib in libpub libahttp libokxml libaok libamt libamysql libweb libokssl librfn ezdb/libezdb ; do for lib in libpub libahttp libokxml libaok libamt libamt_pthread libamysql libweb libokssl librfn ezdb/libezdb ; do
CPPFLAGS="$CPPFLAGS -I"'$(top_srcdir)'"/$lib" CPPFLAGS="$CPPFLAGS -I"'$(top_srcdir)'"/$lib"
done done


Expand All @@ -141,6 +132,9 @@ LIBAHTTP='$(top_builddir)/libahttp/libahttp.la'
LIBOKXML='$(top_builddir)/libokxml/libokxml.la' LIBOKXML='$(top_builddir)/libokxml/libokxml.la'
LIBAOK='$(top_builddir)/libaok/libaok.la' LIBAOK='$(top_builddir)/libaok/libaok.la'
LIBAMT='$(top_builddir)/libamt/libamt.la' LIBAMT='$(top_builddir)/libamt/libamt.la'
if test "$ac_do_pthreads" = "1"; then
LIBAMT_PTHREAD='$(top_builddir)/libamt_pthread/libamt_pthread.la'
fi
LIBAMYSQL='$(top_builddir)/libamysql/libamysql.la' LIBAMYSQL='$(top_builddir)/libamysql/libamysql.la'
LIBWEB='$(top_builddir)/libweb/libweb.la' LIBWEB='$(top_builddir)/libweb/libweb.la'
LIBEZDB='$(top_builddir)/ezdb/libezdb/libezdb.la' LIBEZDB='$(top_builddir)/ezdb/libezdb/libezdb.la'
Expand All @@ -149,18 +143,18 @@ LIBOKSSL='$(top_builddir)/libokssl/libokssl.la'
LIBRFN='$(top_builddir)/librfn/librfn.la' LIBRFN='$(top_builddir)/librfn/librfn.la'
LDADD_PUB='$(LIBPUB) '"$LDADD" LDADD_PUB='$(LIBPUB) '"$LDADD"
LDADD='$(LIBEZDB) $(LIBAOK) $(LIBRFN) $(LIBWEB) $(LIBOKSSL) $(LIBOKXML) $(LIBAHTTP) $(LIBPUB) '"$LDADD"' $(LIBEXPAT) $(LIBSSL)' LDADD='$(LIBEZDB) $(LIBAOK) $(LIBRFN) $(LIBWEB) $(LIBOKSSL) $(LIBOKXML) $(LIBAHTTP) $(LIBPUB) '"$LDADD"' $(LIBEXPAT) $(LIBSSL)'
LDADD_AMT='$(LIBAMT) '"$LDADD" LDADD_AMT='$(LIBAMT) $(LIBAMT_PTHREAD)'"$LDADD"
if test "$enable_shared" = yes; then if test "$enable_shared" = yes; then
LDEPS= LDEPS=
LDEPS_PUB= LDEPS_PUB=
LDEPS_AMT= LDEPS_AMT=
else else
LDEPS_PUB='$(LIBPUB) '"$LDEPS" LDEPS_PUB='$(LIBPUB) '"$LDEPS"
LDEPS='$(LIBWEB) $(LIBAOK) $(LIBAHTTP) $(LIBOKXML) $(LIBPUB) '"$LDEPS" LDEPS='$(LIBWEB) $(LIBAOK) $(LIBAHTTP) $(LIBOKXML) $(LIBPUB) '"$LDEPS"
LDEPS_AMT='$(LIBAMT) '"$LDEPS" LDEPS_AMT='$(LIBAMT) $(LIBAMT_PTHREAD)'"$LDEPS"
LDEPS_AMYSQL='$(LIBEZDBSRV) $(LIBAMT) $(LIBAMYSQL) '"$LDEPS" LDEPS_AMYSQL='$(LIBEZDBSRV) $(LIBAMT) $(LIBAMT_PTHREAD) $(LIBAMYSQL) '"$LDEPS"
fi fi
LDADD_AMYSQL='$(LIBEZDBSRV) $(LIBAMT) $(LIBAMYSQL) '"$LDADD"' $(LDADD_THR) $(LDADD_MYSQL) ' LDADD_AMYSQL='$(LIBEZDBSRV) $(LIBAMT) $(LIBAMT_PTHREAD) $(LIBAMYSQL) '"$LDADD"' $(LDADD_THR) $(LDADD_MYSQL) '




dnl dnl
Expand Down Expand Up @@ -199,6 +193,7 @@ AC_SUBST(LIBAHTTP)
AC_SUBST(LIBOKXML) AC_SUBST(LIBOKXML)
AC_SUBST(LIBAOK) AC_SUBST(LIBAOK)
AC_SUBST(LIBAMT) AC_SUBST(LIBAMT)
AC_SUBST(LIBAMT_PTHREAD)
AC_SUBST(LIBWEB) AC_SUBST(LIBWEB)
AC_SUBST(LIBOKSSL) AC_SUBST(LIBOKSSL)
AC_SUBST(LIBRFN) AC_SUBST(LIBRFN)
Expand Down
19 changes: 18 additions & 1 deletion libamt/amt.h
Expand Up @@ -72,7 +72,7 @@
fprintf (stderr, "%s", s.cstr ()); \ fprintf (stderr, "%s", s.cstr ()); \
} while (0) } while (0)


typedef enum { MTD_NONE = 0, MTD_PTH = 1 } mtd_thread_typ_t; typedef enum { MTD_NONE = 0, MTD_PTH = 1, MTD_PTHREAD } mtd_thread_typ_t;


// MTD = Mutli-Thread Dispatcher // MTD = Mutli-Thread Dispatcher


Expand Down Expand Up @@ -380,6 +380,23 @@ class ssrv_client_t {
int _port; int _port;
}; };


extern mtdispatch_t *g_mtdispatch;

#define GIANT_LOCK() \
do { \
if (g_mtdispatch) { \
g_mtdispatch->giant_lock (); \
} \
} while (0)

#define GIANT_UNLOCK() \
do { \
if (g_mtdispatch) { \
g_mtdispatch->giant_unlock (); \
} \
} while (0)


class ssrv_t { // Synchronous Server (I.e. its threads can block) class ssrv_t { // Synchronous Server (I.e. its threads can block)
public: public:
ssrv_t (newthrcb_t c, const rpc_program &p, mtd_thread_typ_t typ = MTD_PTH, ssrv_t (newthrcb_t c, const rpc_program &p, mtd_thread_typ_t typ = MTD_PTH,
Expand Down
46 changes: 39 additions & 7 deletions libamt/mtdispatch.C
Expand Up @@ -25,6 +25,9 @@
#include "rxx.h" #include "rxx.h"
#include "parseopt.h" #include "parseopt.h"
#include "rpc_stats.h" #include "rpc_stats.h"
#ifdef HAVE_PTHREADS
#include "amt_pthread.h"
#endif


#define LONG_REPLY_TIME 2 #define LONG_REPLY_TIME 2


Expand Down Expand Up @@ -386,7 +389,11 @@ mtd_thread_t::run ()
{ {
mtd_status_t rc; mtd_status_t rc;


if (!init_phase0 () || !init()) { GIANT_LOCK();
bool ok = init_phase0() && init();
GIANT_UNLOCK();

if (!ok) {
TWARN ("thread could not initialize"); TWARN ("thread could not initialize");
msg_send (MTD_SHUTDOWN); msg_send (MTD_SHUTDOWN);
delete this; delete this;
Expand All @@ -395,7 +402,9 @@ mtd_thread_t::run ()


become_ready (); become_ready ();
do { do {
GIANT_LOCK();
take_svccb (); take_svccb ();
GIANT_UNLOCK();
rc = msg_recv (); rc = msg_recv ();
} while (rc == MTD_CONTINUE); } while (rc == MTD_CONTINUE);


Expand Down Expand Up @@ -643,20 +652,43 @@ ssrv_t::init (mtdispatch_t *m)
mtd->init (); mtd->init ();
} }


mtdispatch_t *g_mtdispatch;

ssrv_t::ssrv_t (newthrcb_t c, const rpc_program &p, ssrv_t::ssrv_t (newthrcb_t c, const rpc_program &p,
mtd_thread_typ_t typ, int n, int m) mtd_thread_typ_t typ, int n, int m)
: mtd (NULL), prog (&p), load_avg (0) : mtd (NULL), prog (&p), load_avg (0)
{ {


bool ok = false;

if (typ == MTD_PTH) {
#ifdef HAVE_PTH #ifdef HAVE_PTH
assert (PTH_SYSCALL_HARD && ! PTH_SYSCALL_SOFT); assert (PTH_SYSCALL_HARD && ! PTH_SYSCALL_SOFT);
mtd = New mgt_dispatch_t (c, n, m, this); mtd = New mgt_dispatch_t (c, n, m, this);
mtd->init (); mtd->init ();
ok = true;
#else /* HAVE_PTH */
panic ("pth is not available with this build; "
"cannot continue without threads\n");
#endif
}

if (typ == MTD_PTHREAD) {
#ifdef HAVE_PTHREADS
mtd = New mpt_dispatch_t (c, n, m, this);
mtd->init ();
ok = true;
#else #else
panic ("pth is not available with this build; " panic ("pthreads is not available; try --enable-pthreads");
"cannot continue without threads\n"); #endif
#endif /* HAVE_PTH */ }

if (!ok) {
panic ("no threading package available!");
}


// Keep a global pointer to it, so that we can
g_mtdispatch = mtd;
} }


bool bool
Expand Down
4 changes: 1 addition & 3 deletions libamt_pthread/amt_pthread.h
@@ -1,8 +1,7 @@
// -*-c++-*- // -*-c++-*-
/* $Id: amt_pthread.h 4522 2009-06-08 19:31:51Z max $ */ /* $Id: amt_pthread.h 4522 2009-06-08 19:31:51Z max $ */


#ifndef _LIBAMT_PTHREAD__AMT_PTHREAD_H_ #pragma once
#define _LIBAMT_PTHREAD__AMT_PTHREAD_H_


#include "amt.h" #include "amt.h"
#include <pthread.h> #include <pthread.h>
Expand All @@ -20,4 +19,3 @@ class mpt_dispatch_t : public mtdispatch_t // Posix Threads
pthread_mutex_t _giant_lock; pthread_mutex_t _giant_lock;
}; };


#endif /* _LIBAMT_PTHREAD__AMT_PTHREAD_H_ */

0 comments on commit 7629d1e

Please sign in to comment.