From: Adam Dickmeiss Date: Fri, 5 Oct 2001 13:55:17 +0000 (+0000) Subject: Added defines YAZ_GNU_THREADS, YAZ_POSIX_THREADS in code and yaz-config X-Git-Tag: YAZ.1.8~32 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=9158f8e318f25cb16171433742950236cae96d36;p=yaz-moved-to-github.git Added defines YAZ_GNU_THREADS, YAZ_POSIX_THREADS in code and yaz-config --- diff --git a/configure.in b/configure.in index 9da2915..cdb3556 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl YAZ Toolkit, Index Data 1994-2001 dnl See the file LICENSE for details. -dnl $Id: configure.in,v 1.47 2001-10-04 00:37:58 adam Exp $ +dnl $Id: configure.in,v 1.48 2001-10-05 13:55:17 adam Exp $ AC_INIT(include/yaz/yaz-version.h) AM_INIT_AUTOMAKE(yaz, 1.7) dnl @@ -123,7 +123,9 @@ if test "$ac_cv_header_stdc" = "no"; then fi dnl AC_SUBST(LIBTHREAD) +AC_SUBST(CFLAGSTHREADS) HAVETHREADS=0 +CFLAGSTHREADS="" LIBTHREAD="" dnl AC_ARG_ENABLE(pth, [ --enable-pth enable GNU threads],[enable_pth=$enableval],[enable_pth=no]) @@ -135,6 +137,7 @@ if test "$enable_pth" = "yes"; then AC_CHECK_HEADERS(pth.h) if test "$ac_cv_header_pth_h" = "yes"; then LIBTHREAD="-lpth" + CFLAGSTHREADS="-DYAZ_GNU_THREADS=1" HAVETHREADS=1 fi fi @@ -156,7 +159,7 @@ if test "$enable_threads" = "yes" -a "$HAVETHREADS" = "0"; then if test "$thread_ok" = "yes"; then LIBTHREAD=-lpthread AC_MSG_RESULT(yes) - AC_CHECK_HEADERS(pthread.h) + CFLAGSTHREADS="-DYAZ_POSIX_THREADS=1 -D_REENTRANT" HAVETHREADS=1 else AC_MSG_RESULT(no) diff --git a/lib/Makefile.am b/lib/Makefile.am index 226ad61..a6a4f57 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.13 2001-10-03 23:55:18 adam Exp $ +## $Id: Makefile.am,v 1.14 2001-10-05 13:55:17 adam Exp $ if ISTHR extra=libyazthread.la @@ -13,7 +13,7 @@ EXTRA_libyaz_la_SOURCES=x.c # No real sources libyaz_la_SOURCES= -libyazthread_la_SOURCES=nmem.c statserv.c +libyazthread_la_SOURCES=nmem.c statserv.c eventl.c $(srcdir)/nmem.c: $(top_srcdir)/util/nmem.c cp $(top_srcdir)/util/nmem.c $(srcdir) @@ -21,9 +21,12 @@ $(srcdir)/nmem.c: $(top_srcdir)/util/nmem.c $(srcdir)/statserv.c: $(top_srcdir)/server/statserv.c cp $(top_srcdir)/server/statserv.c $(srcdir) +$(srcdir)/eventl.c: $(top_srcdir)/server/eventl.c + cp $(top_srcdir)/server/eventl.c $(srcdir) + LDFLAGS=-version-info 1:0:0 -INCLUDES =-I$(top_srcdir)/include -I$(top_srcdir)/server -D_REENTRANT=1 +INCLUDES =-I$(top_srcdir)/include -I$(top_srcdir)/server @CFLAGSTHREADS@ bin_SCRIPTS = yaz-config diff --git a/server/eventl.c b/server/eventl.c index 6ad0ef3..a2d7871 100644 --- a/server/eventl.c +++ b/server/eventl.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995-1999, Index Data + * Copyright (c) 1995-2001, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: eventl.c,v $ - * Revision 1.29 1999-11-30 13:47:12 adam + * Revision 1.30 2001-10-05 13:55:17 adam + * Added defines YAZ_GNU_THREADS, YAZ_POSIX_THREADS in code and yaz-config + * + * Revision 1.29 1999/11/30 13:47:12 adam * Improved installation. Moved header files to include/yaz. * * Revision 1.28 1999/08/27 09:40:32 adam @@ -116,6 +119,15 @@ #include "session.h" #include +#if YAZ_GNU_THREADS +#include +#define YAZ_EV_SELECT pth_select +#endif + +#ifndef YAZ_EV_SELECT +#define YAZ_EV_SELECT select +#endif + IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags) { IOCHAN new_iochan; @@ -162,7 +174,8 @@ int event_loop(IOCHAN *iochans) if (p->fd > max) max = p->fd; } - if ((res = select(max + 1, &in, &out, &except, timeout)) < 0) + res = YAZ_EV_SELECT(max + 1, &in, &out, &except, timeout); + if (res < 0) { if (errno == EINTR) continue; diff --git a/server/statserv.c b/server/statserv.c index 60fc8d3..35ef6ac 100644 --- a/server/statserv.c +++ b/server/statserv.c @@ -7,7 +7,10 @@ * Chas Woodfield, Fretwell Downing Informatics. * * $Log: statserv.c,v $ - * Revision 1.75 2001-10-04 00:37:58 adam + * Revision 1.76 2001-10-05 13:55:17 adam + * Added defines YAZ_GNU_THREADS, YAZ_POSIX_THREADS in code and yaz-config + * + * Revision 1.75 2001/10/04 00:37:58 adam * Fixes for GNU threads (not working yet). * * Revision 1.74 2001/10/03 23:55:18 adam @@ -265,18 +268,16 @@ #include #include "service.h" #else +#include +#include +#endif -#ifdef _REENTRANT -#if HAVE_PTHREAD_H +#if YAZ_POSIX_THREADS #include -#elif HAVE_PTH_H +#elif YAZ_GNU_THREADS #include #endif -#endif -#include -#include -#endif #include #include #include @@ -718,8 +719,7 @@ static void listener(IOCHAN h, int event) iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */ ++no_sessions; } -#ifdef _REENTRANT -#if HAVE_PTHREAD_H +#if YAZ_POSIX_THREADS if (control_block.threads) { pthread_t child_thread; @@ -728,7 +728,7 @@ static void listener(IOCHAN h, int event) } else new_session(new_line); -#elif HAVE_PTH_H +#elif YAZ_GNU_THREADS if (control_block.threads) { pth_attr_t attr; @@ -738,16 +738,13 @@ static void listener(IOCHAN h, int event) pth_attr_set (attr, PTH_ATTR_JOINABLE, FALSE); pth_attr_set (attr, PTH_ATTR_STACK_SIZE, 32*1024); pth_attr_set (attr, PTH_ATTR_NAME, "session"); - yaz_log (LOG_LOG, "pth_spawn"); + yaz_log (LOG_LOG, "pth_spawn begin"); child_thread = pth_spawn (attr, new_session, new_line); -#if 0 + yaz_log (LOG_LOG, "pth_spawn finish"); pth_attr_destroy (attr); -#endif } else new_session(new_line); -#endif - #else new_session(new_line); #endif @@ -1022,7 +1019,10 @@ int check_options(int argc, char **argv) control_block.dynamic = 0; break; case 'T': -#if _REENTRANT +#if YAZ_POSIX_THREADS + control_block.dynamic = 0; + control_block.threads = 1; +#elif YAZ_GNU_THREADS control_block.dynamic = 0; control_block.threads = 1; #else diff --git a/util/nmem.c b/util/nmem.c index 1b191c4..131ab1e 100644 --- a/util/nmem.c +++ b/util/nmem.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: nmem.c,v $ - * Revision 1.29 2001-10-04 00:37:58 adam + * Revision 1.30 2001-10-05 13:55:17 adam + * Added defines YAZ_GNU_THREADS, YAZ_POSIX_THREADS in code and yaz-config + * + * Revision 1.29 2001/10/04 00:37:58 adam * Fixes for GNU threads (not working yet). * * Revision 1.28 2001/10/03 23:55:18 adam @@ -119,13 +122,12 @@ #include #endif -#ifdef _REENTRANT -#if HAVE_PTHREAD_H +#if YAZ_POSIX_THREADS #include -#elif HAVE_PTH_H -#include #endif +#if YAZ_GNU_THREADS +#include #endif #define NMEM_CHUNK (4*1024) @@ -134,40 +136,30 @@ static CRITICAL_SECTION critical_section; #define NMEM_ENTER EnterCriticalSection(&critical_section) #define NMEM_LEAVE LeaveCriticalSection(&critical_section) -#endif - -#ifdef _REENTRANT -#if HAVE_PTHREAD_H +struct nmem_mutex { + CRITICAL_SECTION m_handle; +}; +#elif YAZ_POSIX_THREADS static pthread_mutex_t nmem_mutex = PTHREAD_MUTEX_INITIALIZER; #define NMEM_ENTER pthread_mutex_lock(&nmem_mutex); #define NMEM_LEAVE pthread_mutex_unlock(&nmem_mutex); -#elif HAVE_PTH_H -static pth_mutex_t nmem_mutex; +struct nmem_mutex { + pthread_mutex_t m_handle; +}; +#elif YAZ_GNU_THREADS +static pth_mutex_t nmem_mutex = PTH_MUTEX_INIT; #define NMEM_ENTER pth_mutex_acquire(&nmem_mutex, 0, 0) #define NMEM_LEAVE pth_mutex_release(&nmem_mutex) -#else -#error x -#endif +struct nmem_mutex { + pth_mutex_t m_handle; +}; #else #define NMEM_ENTER #define NMEM_LEAVE -#endif - struct nmem_mutex { -#ifdef WIN32 - CRITICAL_SECTION m_handle; -#elif _REENTRANT - -#if HAVE_PTHREAD_H - pthread_mutex_t m_handle; -#elif HAVE_PTH_H - pth_mutex_t m_handle; -#endif - -#else - int m_handle; -#endif + int dummy; }; +#endif YAZ_EXPORT void nmem_mutex_create(NMEM_MUTEX *p) { @@ -177,8 +169,10 @@ YAZ_EXPORT void nmem_mutex_create(NMEM_MUTEX *p) *p = (NMEM_MUTEX) malloc (sizeof(**p)); #ifdef WIN32 InitializeCriticalSection(&(*p)->m_handle); -#elif _REENTRANT +#elif YAZ_POSIX_THREADS pthread_mutex_init (&(*p)->m_handle, 0); +#elif YAZ_GNU_THREADS + pth_mutex_init (&(*p)->m_handle); #endif } NMEM_LEAVE; @@ -190,7 +184,7 @@ YAZ_EXPORT void nmem_mutex_enter(NMEM_MUTEX p) { #ifdef WIN32 EnterCriticalSection(&p->m_handle); -#elif _REENTRANT +#elif YAZ_POSIX_THREADS pthread_mutex_lock(&p->m_handle); #endif } @@ -202,7 +196,7 @@ YAZ_EXPORT void nmem_mutex_leave(NMEM_MUTEX p) { #ifdef WIN32 LeaveCriticalSection(&p->m_handle); -#elif _REENTRANT +#elif YAZ_POSIX_THREADS pthread_mutex_unlock(&p->m_handle); #endif } @@ -481,14 +475,9 @@ void nmem_init (void) { #ifdef WIN32 InitializeCriticalSection(&critical_section); -#endif - -#ifdef _REENTRANT -#if HAVE_PTH_H +#elif YAZ_GNU_THREADS yaz_log (LOG_LOG, "pth_init"); pth_init (); - pth_mutex_init (&nmem_mutex); -#endif #endif nmem_active_no = 0; freelist = NULL; diff --git a/yaz-config.in b/yaz-config.in index 1ccd01b..53578bb 100644 --- a/yaz-config.in +++ b/yaz-config.in @@ -1,5 +1,5 @@ #!/bin/sh -# $Id: yaz-config.in,v 1.8 2001-09-28 10:42:28 adam Exp $ +# $Id: yaz-config.in,v 1.9 2001-10-05 13:55:17 adam Exp $ yazprefix=@prefix@ yaz_echo_cflags=no yaz_echo_libs=no @@ -115,7 +115,7 @@ else fi if test "$lib_thread" = "yes"; then - YAZINC="$YAZINC -D_REENTRANT" + YAZINC="$YAZINC @CFLAGSTHREADS@" fi if test "$yaz_echo_help" = "yes"; then diff --git a/ztest/Makefile.am b/ztest/Makefile.am index 0fd4142..46ef046 100644 --- a/ztest/Makefile.am +++ b/ztest/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.5 2001-03-21 15:02:39 adam Exp $ +## $Id: Makefile.am,v 1.6 2001-10-05 13:55:17 adam Exp $ bin_PROGRAMS=yaz-ztest @@ -11,4 +11,4 @@ extra=../lib/libyazthread.la endif yaz_ztest_LDADD=$(extra) ../lib/libyaz.la $(LIBTHREAD) -INCLUDES=-I$(top_srcdir)/include +INCLUDES=-I$(top_srcdir)/include @CFLAGSTHREADS@