Added defines YAZ_GNU_THREADS, YAZ_POSIX_THREADS in code and yaz-config
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 5 Oct 2001 13:55:17 +0000 (13:55 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 5 Oct 2001 13:55:17 +0000 (13:55 +0000)
configure.in
lib/Makefile.am
server/eventl.c
server/statserv.c
util/nmem.c
yaz-config.in
ztest/Makefile.am

index 9da2915..cdb3556 100644 (file)
@@ -1,6 +1,6 @@
 dnl YAZ Toolkit, Index Data 1994-2001
 dnl See the file LICENSE for details.
 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
 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)
 fi
 dnl
 AC_SUBST(LIBTHREAD)
+AC_SUBST(CFLAGSTHREADS)
 HAVETHREADS=0
 HAVETHREADS=0
+CFLAGSTHREADS=""
 LIBTHREAD=""
 dnl
 AC_ARG_ENABLE(pth, [  --enable-pth            enable GNU threads],[enable_pth=$enableval],[enable_pth=no])
 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"
                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      
                        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)
        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)
                HAVETHREADS=1
        else
                AC_MSG_RESULT(no)
index 226ad61..a6a4f57 100644 (file)
@@ -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
 
 if ISTHR
 extra=libyazthread.la
@@ -13,7 +13,7 @@ EXTRA_libyaz_la_SOURCES=x.c
 # No real sources
 libyaz_la_SOURCES=
 
 # 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)
 
 $(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)/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
 
 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
 
 
 bin_SCRIPTS = yaz-config
 
index 6ad0ef3..a2d7871 100644 (file)
@@ -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 $
  * 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
  * Improved installation. Moved header files to include/yaz.
  *
  * Revision 1.28  1999/08/27 09:40:32  adam
 #include "session.h"
 #include <yaz/statserv.h>
 
 #include "session.h"
 #include <yaz/statserv.h>
 
+#if YAZ_GNU_THREADS
+#include <pth.h>
+#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;
 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 (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;
        {
            if (errno == EINTR)
                continue;
index 60fc8d3..35ef6ac 100644 (file)
@@ -7,7 +7,10 @@
  *   Chas Woodfield, Fretwell Downing Informatics.
  *
  * $Log: statserv.c,v $
  *   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
  * Fixes for GNU threads (not working yet).
  *
  * Revision 1.74  2001/10/03 23:55:18  adam
 #include <direct.h>
 #include "service.h"
 #else
 #include <direct.h>
 #include "service.h"
 #else
+#include <unistd.h>
+#include <pwd.h>
+#endif
 
 
-#ifdef _REENTRANT
-#if HAVE_PTHREAD_H
+#if YAZ_POSIX_THREADS
 #include <pthread.h>
 #include <pthread.h>
-#elif HAVE_PTH_H
+#elif YAZ_GNU_THREADS
 #include <pth.h>
 #endif
 #include <pth.h>
 #endif
-#endif
 
 
-#include <unistd.h>
-#include <pwd.h>
-#endif
 #include <fcntl.h>
 #include <signal.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <errno.h>
@@ -718,8 +719,7 @@ static void listener(IOCHAN h, int event)
            iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */
            ++no_sessions;
        }
            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;
        if (control_block.threads)
        {
            pthread_t child_thread;
@@ -728,7 +728,7 @@ static void listener(IOCHAN h, int event)
        }
        else
            new_session(new_line);
        }
        else
            new_session(new_line);
-#elif HAVE_PTH_H
+#elif YAZ_GNU_THREADS
        if (control_block.threads)
        {
            pth_attr_t attr;
        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");
             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);
            child_thread = pth_spawn (attr, new_session, new_line);
-#if 0
+            yaz_log (LOG_LOG, "pth_spawn finish");
             pth_attr_destroy (attr);
             pth_attr_destroy (attr);
-#endif
        }
        else
            new_session(new_line);
        }
        else
            new_session(new_line);
-#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':
            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
            control_block.dynamic = 0;
            control_block.threads = 1;
 #else
index 1b191c4..131ab1e 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: nmem.c,v $
  * 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
  * Fixes for GNU threads (not working yet).
  *
  * Revision 1.28  2001/10/03 23:55:18  adam
 #include <windows.h>
 #endif
 
 #include <windows.h>
 #endif
 
-#ifdef _REENTRANT
-#if HAVE_PTHREAD_H
+#if YAZ_POSIX_THREADS
 #include <pthread.h>
 #include <pthread.h>
-#elif HAVE_PTH_H
-#include <pth.h>
 #endif
 
 #endif
 
+#if YAZ_GNU_THREADS
+#include <pth.h>
 #endif
 
 #define NMEM_CHUNK (4*1024)
 #endif
 
 #define NMEM_CHUNK (4*1024)
 static CRITICAL_SECTION critical_section;
 #define NMEM_ENTER EnterCriticalSection(&critical_section)
 #define NMEM_LEAVE LeaveCriticalSection(&critical_section)
 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);
 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)
 #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
 #else
 #define NMEM_ENTER
 #define NMEM_LEAVE
-#endif
-
 struct nmem_mutex {
 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)
 {
 
 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);
        *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);
        pthread_mutex_init (&(*p)->m_handle, 0);
+#elif YAZ_GNU_THREADS
+        pth_mutex_init (&(*p)->m_handle);
 #endif
     }
     NMEM_LEAVE;
 #endif
     }
     NMEM_LEAVE;
@@ -190,7 +184,7 @@ YAZ_EXPORT void nmem_mutex_enter(NMEM_MUTEX p)
     {
 #ifdef WIN32
        EnterCriticalSection(&p->m_handle);
     {
 #ifdef WIN32
        EnterCriticalSection(&p->m_handle);
-#elif _REENTRANT
+#elif YAZ_POSIX_THREADS
        pthread_mutex_lock(&p->m_handle);
 #endif
     }
        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);
     {
 #ifdef WIN32
        LeaveCriticalSection(&p->m_handle);
-#elif _REENTRANT
+#elif YAZ_POSIX_THREADS
        pthread_mutex_unlock(&p->m_handle);
 #endif
     }
        pthread_mutex_unlock(&p->m_handle);
 #endif
     }
@@ -481,14 +475,9 @@ void nmem_init (void)
     {
 #ifdef WIN32
        InitializeCriticalSection(&critical_section);
     {
 #ifdef WIN32
        InitializeCriticalSection(&critical_section);
-#endif
-
-#ifdef _REENTRANT
-#if HAVE_PTH_H
+#elif YAZ_GNU_THREADS
        yaz_log (LOG_LOG, "pth_init");
         pth_init ();
        yaz_log (LOG_LOG, "pth_init");
         pth_init ();
-        pth_mutex_init (&nmem_mutex);
-#endif
 #endif
        nmem_active_no = 0;
        freelist = NULL;
 #endif
        nmem_active_no = 0;
        freelist = NULL;
index 1ccd01b..53578bb 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh
 #!/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
 yazprefix=@prefix@
 yaz_echo_cflags=no
 yaz_echo_libs=no
@@ -115,7 +115,7 @@ else
 fi
 
 if test "$lib_thread" = "yes"; then
 fi
 
 if test "$lib_thread" = "yes"; then
-    YAZINC="$YAZINC -D_REENTRANT"
+    YAZINC="$YAZINC @CFLAGSTHREADS@"
 fi
 
 if test "$yaz_echo_help" = "yes"; then
 fi
 
 if test "$yaz_echo_help" = "yes"; then
index 0fd4142..46ef046 100644 (file)
@@ -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
 
 
 bin_PROGRAMS=yaz-ztest
 
@@ -11,4 +11,4 @@ extra=../lib/libyazthread.la
 endif
 yaz_ztest_LDADD=$(extra) ../lib/libyaz.la $(LIBTHREAD)
 
 endif
 yaz_ztest_LDADD=$(extra) ../lib/libyaz.la $(LIBTHREAD)
 
-INCLUDES=-I$(top_srcdir)/include
+INCLUDES=-I$(top_srcdir)/include @CFLAGSTHREADS@