Skip to content
This repository has been archived by the owner on Jan 16, 2021. It is now read-only.

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
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ AC_DEFUN([OKWS_MYSQL],
[AC_ARG_WITH(mysql,
--with-mysql=DIR Specific location of mysqlclient library)
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_LIBS=$LIBS
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
case $dir in
"") lflags=" " ;;
" ") lflags="-lmysqlclient -lm" ;;
*) lflags="-L${dir} -lmysqlclient -lm" ;;
" ") lflags="-l$libname -lm" ;;
*) lflags="-L${dir} -l$libname -lm" ;;
esac
LIBS="$ac_save_LIBS $lflags"
AC_TRY_LINK([#include "mysql.h"],
Expand Down Expand Up @@ -333,57 +341,27 @@ AC_SUBST(LDADD_THR)
dnl
dnl Find pthreads
dnl
AC_DEFUN([OKWS_FIND_PTHREADS],
[AC_ARG_WITH(pthreads,
--with-pthreads=DIR Specify location of pthreads)
ac_save_CFLAGS=$CFLAGS
ac_save_LIBS=$LIBS
dirs="$with_pthreads ${prefix} ${prefix}/pthreads"
dirs="$dirs /usr/local /usr/local/pthreads"
AC_CACHE_CHECK(for pthread.h, sfs_cv_pthread_h,
[for dir in " " $dirs; do
case $dir in
" ") iflags=" " ;;
*) iflags="-I${dir}/include" ;;
esac
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])
AC_DEFUN([OKWS_DO_PTHREADS],
[AC_ARG_ENABLE(pthreads,
--enable-pthreads Allow OKWS to use standard pthreads)
if test `uname` = "Linux"; then
ac_do_pthreads=1
if test "${enable_pthreads}" = "no"; then
ac_do_pthreads=0
fi
else
ac_do_pthreads=0
if test "${enable_pthreads}" = "yes" ; then
ac_do_pthreads=1
fi
fi
if test "$sfs_cv_libpthread" != "no" && test "${sfs_cv_libpthread+set}" ; then
CFLAGS=$ac_save_CFLAGS
CPPFLAGS="$CPPFLAGS $sfs_cv_pthread_h"
LIBS="$ac_save_LIBS $sfs_cv_libpthread"
LDADD_PTHREAD="$sfs_cv_libpthread"
use_pthreads=yes
if test $ac_do_pthreads -eq 1 ; then
AC_DEFINE(HAVE_PTHREADS, 1, Use pthread support)
fi
AM_CONDITIONAL(USE_PTHREADS, test "${use_pthreads}" != "no")
LIBS=$ac_save_LIBS
CFLAGS=$ac_save_CFLAGS
AM_CONDITIONAL(USE_PTHREADS, test ${ac_do_pthreads} -eq 1)
])

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

#include <unistd.h>
#include <grp.h>
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
LIBWEB=${with_okws}/libweb/libweb.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
LIBAMYSQL=${with_okws}/libamysql/libamysql.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
LIBWEB=${okwslibdir}/libweb.la
LIBAMT=${okwslibdir}/libamt.la
if test "${ac_do_pthreads}" = "1"; then
LIBAMT_PTHREAD=${okwslibdir}/libamt_pthread.la
fi
LIBAHTTP=${okwslibdir}/libahttp.la
LIBAMYSQL=${okwslibdir}/libamysql.la
LIBOKSSL=${okwslibdir}/libokssl.la
Expand Down Expand Up @@ -825,6 +805,7 @@ AC_SUBST(LIBOKXML)
AC_SUBST(LIBAHTTP)
AC_SUBST(LIBRFN)
AC_SUBST(LIBAMT)
AC_SUBST(LIBAMT_PTHREAD)
AC_SUBST(LIBWEB)
AC_SUBST(LIBOKSSL)
AC_SUBST(LIBAMYSQL)
Expand All @@ -836,9 +817,9 @@ AC_SUBST(OKWS_LIB_MK)
LIBS='$(LIBEXPAT) $(LIBSSL)'"$LIBS"
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_DB='$(LIBAMYSQL) $(LIBAMT) '"$LDADD "'$(LDADD_THR) $(LDADD_MYSQL)'
LDADD_DB='$(LIBAMYSQL) $(LIBAMT) $(LIBAMT_PTHREAD)'"$LDADD "'$(LDADD_THR) $(LDADD_MYSQL)'
AC_SUBST(LDEPS)
AC_SUBST(LDADD)
Expand Down
35 changes: 15 additions & 20 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ dnl Process this file with autoconf to produce a configure script.
dnl

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)

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

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')

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 SFS_REQUIRE_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
OKWS_DO_THREADS

test "$PUB" || PUB='$(top_builddir)/pub/pub'
test "$XMLRPCC" || XMLRPCC='$(top_builddir)/xmlrpcc/xmlrpcc'
Expand Down Expand Up @@ -129,7 +120,7 @@ done
dnl
dnl library directories
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"
done

Expand All @@ -141,6 +132,9 @@ LIBAHTTP='$(top_builddir)/libahttp/libahttp.la'
LIBOKXML='$(top_builddir)/libokxml/libokxml.la'
LIBAOK='$(top_builddir)/libaok/libaok.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'
LIBWEB='$(top_builddir)/libweb/libweb.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'
LDADD_PUB='$(LIBPUB) '"$LDADD"
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
LDEPS=
LDEPS_PUB=
LDEPS_AMT=
else
LDEPS_PUB='$(LIBPUB) '"$LDEPS"
LDEPS='$(LIBWEB) $(LIBAOK) $(LIBAHTTP) $(LIBOKXML) $(LIBPUB) '"$LDEPS"
LDEPS_AMT='$(LIBAMT) '"$LDEPS"
LDEPS_AMYSQL='$(LIBEZDBSRV) $(LIBAMT) $(LIBAMYSQL) '"$LDEPS"
LDEPS_AMT='$(LIBAMT) $(LIBAMT_PTHREAD)'"$LDEPS"
LDEPS_AMYSQL='$(LIBEZDBSRV) $(LIBAMT) $(LIBAMT_PTHREAD) $(LIBAMYSQL) '"$LDEPS"
fi
LDADD_AMYSQL='$(LIBEZDBSRV) $(LIBAMT) $(LIBAMYSQL) '"$LDADD"' $(LDADD_THR) $(LDADD_MYSQL) '
LDADD_AMYSQL='$(LIBEZDBSRV) $(LIBAMT) $(LIBAMT_PTHREAD) $(LIBAMYSQL) '"$LDADD"' $(LDADD_THR) $(LDADD_MYSQL) '


dnl
Expand Down Expand Up @@ -199,6 +193,7 @@ AC_SUBST(LIBAHTTP)
AC_SUBST(LIBOKXML)
AC_SUBST(LIBAOK)
AC_SUBST(LIBAMT)
AC_SUBST(LIBAMT_PTHREAD)
AC_SUBST(LIBWEB)
AC_SUBST(LIBOKSSL)
AC_SUBST(LIBRFN)
Expand Down
19 changes: 18 additions & 1 deletion libamt/amt.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
fprintf (stderr, "%s", s.cstr ()); \
} 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

Expand Down Expand Up @@ -380,6 +380,23 @@ class ssrv_client_t {
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)
public:
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include "rxx.h"
#include "parseopt.h"
#include "rpc_stats.h"
#ifdef HAVE_PTHREADS
#include "amt_pthread.h"
#endif

#define LONG_REPLY_TIME 2

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

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

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

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

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

mtdispatch_t *g_mtdispatch;

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

bool ok = false;

if (typ == MTD_PTH) {
#ifdef HAVE_PTH
assert (PTH_SYSCALL_HARD && ! PTH_SYSCALL_SOFT);
mtd = New mgt_dispatch_t (c, n, m, this);
mtd->init ();
assert (PTH_SYSCALL_HARD && ! PTH_SYSCALL_SOFT);
mtd = New mgt_dispatch_t (c, n, m, this);
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
panic ("pth is not available with this build; "
"cannot continue without threads\n");
#endif /* HAVE_PTH */
panic ("pthreads is not available; try --enable-pthreads");
#endif
}

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

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

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

#ifndef _LIBAMT_PTHREAD__AMT_PTHREAD_H_
#define _LIBAMT_PTHREAD__AMT_PTHREAD_H_
#pragma once

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

#endif /* _LIBAMT_PTHREAD__AMT_PTHREAD_H_ */
Loading

0 comments on commit 7629d1e

Please sign in to comment.