Răsfoiți Sursa

- added futex based locking, used by default on linux 2.5.70+
(to turn it off compile with make use_futex=no)
- moved get_sys_ver from io_wait.c into ut.c

Andrei Pelinescu-Onciul 18 ani în urmă
părinte
comite
8b8fc486bd
12 a modificat fișierele cu 332 adăugiri și 44 ștergeri
  1. 19 2
      Makefile.defs
  2. 124 0
      futexlock.h
  3. 1 36
      io_wait.c
  4. 52 0
      lock_ops.c
  5. 22 4
      lock_ops.h
  6. 33 0
      lock_ops_init.h
  7. 5 0
      main.c
  8. 3 0
      test/locking/Makefile
  9. 17 1
      test/locking/locking_test.c
  10. 40 0
      ut.c
  11. 8 0
      ut.h
  12. 8 1
      version.h

+ 19 - 2
Makefile.defs

@@ -55,6 +55,8 @@
 #              added TLS_EXTRA_LIBS (andrei)
 #              added TLS_EXTRA_LIBS (andrei)
 #  2007-03-16  added LIB building options: LIB_LDFLAGS, LIB_SONAME, LIB_RPATH,
 #  2007-03-16  added LIB building options: LIB_LDFLAGS, LIB_SONAME, LIB_RPATH,
 #                INSTALL_LIB, libraries install paths (andrei)
 #                INSTALL_LIB, libraries install paths (andrei)
+#  2007-05-14  futex support if linux 2.5.70+ and 
+#               use_futex=yes (default) (andrei)
 
 
 
 
 # check if already included/exported
 # check if already included/exported
@@ -71,7 +73,7 @@ MAIN_NAME=ser
 VERSION = 2
 VERSION = 2
 PATCHLEVEL = 1
 PATCHLEVEL = 1
 SUBLEVEL =  0
 SUBLEVEL =  0
-EXTRAVERSION = -dev2
+EXTRAVERSION = -dev3
 
 
 SER_VER = $(shell expr $(VERSION) \* 1000000 + $(PATCHLEVEL) \* 1000 + \
 SER_VER = $(shell expr $(VERSION) \* 1000000 + $(PATCHLEVEL) \* 1000 + \
 			$(SUBLEVEL) )
 			$(SUBLEVEL) )
@@ -323,6 +325,8 @@ endif
 #		work on all systems inter-processes (e.g. linux)
 #		work on all systems inter-processes (e.g. linux)
 # -DUSE_POSIX_SEM
 # -DUSE_POSIX_SEM
 #		uses posix semaphores for locking (faster than sys v)
 #		uses posix semaphores for locking (faster than sys v)
+# -DUSE_FUTEX
+#		uses futexes for locking (linux 2.6+)
 # -DBUSY_WAIT
 # -DBUSY_WAIT
 #		uses busy waiting on the lock (FAST_LOCK)
 #		uses busy waiting on the lock (FAST_LOCK)
 # -DADAPTIVE_WAIT
 # -DADAPTIVE_WAIT
@@ -405,6 +409,7 @@ DEFS+= $(extra_defs) \
 	 -DUSE_DNS_FAILOVER \
 	 -DUSE_DNS_FAILOVER \
 	 -DUSE_DST_BLACKLIST \
 	 -DUSE_DST_BLACKLIST \
 	 -DDBG_QM_MALLOC \
 	 -DDBG_QM_MALLOC \
+	 #-DF_MALLOC
 	 #-DDBG_F_MALLOC \
 	 #-DDBG_F_MALLOC \
 	 #-DNO_DEBUG \
 	 #-DNO_DEBUG \
 	 #-DEXTRA_DEBUG \
 	 #-DEXTRA_DEBUG \
@@ -550,6 +555,7 @@ endif
 
 
 ifeq ($(ARCH), alpha)
 ifeq ($(ARCH), alpha)
 	use_fast_lock=yes
 	use_fast_lock=yes
+	DEFS+=-DNOSMP # very likely
 endif
 endif
 
 
 ifeq ($(use_fast_lock), yes)
 ifeq ($(use_fast_lock), yes)
@@ -1272,11 +1278,16 @@ LIB_SUFFIX:=.so
 
 
 #os specific stuff
 #os specific stuff
 ifeq ($(OS), linux)
 ifeq ($(OS), linux)
+# by default use futexes if available
+	use_futex= yes
 	DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
 	DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
 			-DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H \
 			-DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H \
 			-DHAVE_TIMEGM
 			-DHAVE_TIMEGM
 	ifneq ($(found_lock_method), yes)
 	ifneq ($(found_lock_method), yes)
-		DEFS+= -DUSE_SYSV_SEM  # try posix sems
+		#DEFS+= -DUSE_POSIX_SEM
+		DEFS+=-DUSE_PTHREAD_MUTEX
+		LIBS+= -lpthread
+		#DEFS+= -DUSE_SYSV_SEM  # try posix sems
 		found_lock_method=yes
 		found_lock_method=yes
 	else
 	else
 		ifneq (,$(findstring -DUSE_POSIX_SEM, $(DEFS)))
 		ifneq (,$(findstring -DUSE_POSIX_SEM, $(DEFS)))
@@ -1300,6 +1311,12 @@ ifeq ($(OS), linux)
 			DEFS+=-DHAVE_SIGIO_RT -DSIGINFO64_WORKARROUND
 			DEFS+=-DHAVE_SIGIO_RT -DSIGINFO64_WORKARROUND
 		endif
 		endif
 	endif
 	endif
+	# check for >= 2.5.70
+	ifeq ($(shell [ $(OSREL_N) -ge 2005070 ] && echo has_futex), has_futex)
+		ifeq ($(use_futex), yes)
+			DEFS+=-DUSE_FUTEX
+		endif
+	endif
 	ifeq ($(NO_SELECT),)
 	ifeq ($(NO_SELECT),)
 		DEFS+=-DHAVE_SELECT
 		DEFS+=-DHAVE_SELECT
 	endif
 	endif

+ 124 - 0
futexlock.h

@@ -0,0 +1,124 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2007 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
+ * futex based lock (mutex) implementation  (linux 2.6+ only)
+ * based on Ulrich Drepper implementation in "Futexes Are Tricky"
+ * (http://people.redhat.com/drepper/futex.pdf)
+ *
+ * Implements:
+ *   void futex_get(futex_lock_t* lock);     - mutex lock
+ *   void futex_release(futex_lock_t* lock); - unlock
+ *   int  futex_try(futex_lock_t* lock);     - tries to get lock, returns 0
+ *                                              on success and !=0 on failure
+ *                                              (1 or 2)
+ *
+ *  Config defines:
+ */
+/* 
+ * History:
+ * --------
+ *  2007-05-13  created by andrei
+ */
+
+#ifndef _futexlock_h
+#define _futexlock_h
+
+
+#include "atomic/atomic_common.h"
+#include "atomic/atomic_native.h"
+
+#ifdef HAVE_ASM_INLINE_ATOMIC_OPS
+#define HAVE_FUTEX
+#include <linux/futex.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include "compiler_opt.h"
+
+
+#define sys_futex(addr, op, val, timeout, addr2, val3) \
+	syscall(__NR_futex , (addr), (op), (val), (timeout), (addr2), (val3))
+
+typedef atomic_t futex_lock_t;
+
+/* the mutex has 3 states: 0 - free/unlocked and nobody waiting
+ *                         1 - locked and nobody waiting for it
+ *                         2 - locked w/ 0 or more waiting processes/threads
+ */
+
+inline static futex_lock_t* futex_init(futex_lock_t* lock)
+{
+	atomic_set(lock, 0);
+	return lock;
+}
+
+
+inline static void futex_get(futex_lock_t* lock)
+{
+	int v;
+	
+	v=atomic_cmpxchg(lock, 0, 1); /* lock if 0 */
+	if (likely(v==0)){  /* optimize for the uncontended case */
+		/* success */
+		membar_enter_lock();
+		return;
+	}else if (likely(v==2)){ /* if contended, optimize for the several waiters
+								case */
+		/* waiting processes/threads => add ourselves to the queue */
+		do{
+			sys_futex(&(lock)->val, FUTEX_WAIT, 2, 0, 0, 0);
+			v=atomic_get_and_set(lock, 2);
+		}while(v);
+	}else{
+		/* v==1 */
+		v=atomic_get_and_set(lock, 2);
+		while(v){
+			sys_futex(&(lock)->val, FUTEX_WAIT, 2, 0, 0, 0);
+			v=atomic_get_and_set(lock, 2);
+		}
+	}
+	membar_enter_lock();
+}
+
+
+inline static void futex_release(futex_lock_t* lock)
+{
+	int v;
+	
+	membar_leave_lock();
+	v=atomic_get_and_set(lock, 0);
+	if (unlikely(v==2)){ /* optimize for the uncontended case */
+		sys_futex(&(lock)->val, FUTEX_WAKE, 1, 0, 0, 0);
+	}
+}
+
+
+static inline int futex_try(futex_lock_t* lock)
+{
+	int c;
+	c=atomic_cmpxchg(lock, 0, 1);
+	if (likely(c))
+		membar_enter_lock();
+	return c;
+}
+
+
+#else /*HAVE_ASM_INLINE_ATOMIC_OPS*/
+#undef USE_FUTEX
+#endif /*HAVE_ASM_INLINE_ATOMIC_OPS*/
+
+#endif /* _futexlocks_h*/

+ 1 - 36
io_wait.c

@@ -50,9 +50,9 @@
 #include <unistd.h> /* close, ioctl */
 #include <unistd.h> /* close, ioctl */
 #endif
 #endif
 
 
-#include <sys/utsname.h> /* uname() */
 #include <stdlib.h> /* strtol() */
 #include <stdlib.h> /* strtol() */
 #include "io_wait.h"
 #include "io_wait.h"
+#include "ut.h" /* get_sys_ver() */
 
 
 
 
 #include "mem/mem.h"
 #include "mem/mem.h"
@@ -295,41 +295,6 @@ static int init_select(io_wait_h* h)
 #endif
 #endif
 
 
 
 
-
-/* return system version (major.minor.minor2) as
- *  (major<<16)|(minor)<<8|(minor2)
- * (if some of them are missing, they are set to 0)
- * if the parameters are not null they are set to the coresp. part 
- */
-static unsigned int get_sys_version(int* major, int* minor, int* minor2)
-{
-	struct utsname un;
-	int m1;
-	int m2;
-	int m3;
-	char* p;
-	
-	memset (&un, 0, sizeof(un));
-	m1=m2=m3=0;
-	/* get sys version */
-	uname(&un);
-	m1=strtol(un.release, &p, 10);
-	if (*p=='.'){
-		p++;
-		m2=strtol(p, &p, 10);
-		if (*p=='.'){
-			p++;
-			m3=strtol(p, &p, 10);
-		}
-	}
-	if (major) *major=m1;
-	if (minor) *minor=m2;
-	if (minor2) *minor2=m3;
-	return ((m1<<16)|(m2<<8)|(m3));
-}
-
-
-
 /*
 /*
  * returns 0 on success, and an error message on error
  * returns 0 on success, and an error message on error
  */
  */

+ 52 - 0
lock_ops.c

@@ -0,0 +1,52 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2007 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
+ *  lock operations init
+ */
+/* 
+ * History:
+ * --------
+ *  2007-05-14  created by andrei
+ */
+
+#include "lock_ops.h"
+#include "ut.h"
+#include "dprint.h"
+
+/* returns 0 on success, -1 on error */
+int init_lock_ops()
+{
+#ifdef USE_FUTEX
+	int os_ver;
+	
+	os_ver=get_sys_version(0, 0, 0);
+	if (os_ver < 0x020546 ){ /* if ver < 2.5.70 */
+		LOG(L_CRIT, "ERROR: init_lock_ops: old kernel:"
+				" compiled with FUTEX support which is not present in the"
+				" running kernel (try  2.6+)\n");
+		return -1;
+	}
+#endif
+	return 0;
+}
+
+
+
+void destroy_lock_ops()
+{
+}

+ 22 - 4
lock_ops.h

@@ -34,6 +34,7 @@
  *  2004-07-28  s/lock_set_t/gen_lock_set_t/ because of a type conflict
  *  2004-07-28  s/lock_set_t/gen_lock_set_t/ because of a type conflict
  *              on darwin (andrei)
  *              on darwin (andrei)
  *  2006-04-04  added lock_try(lock) and lock_set_try(s,i) (andrei)
  *  2006-04-04  added lock_try(lock) and lock_set_try(s,i) (andrei)
+ *  2007-05-13  added futex support (andrei)
  *
  *
 Implements:
 Implements:
 
 
@@ -44,7 +45,7 @@ Implements:
 	void    lock_get(gen_lock_t* lock);      - lock (mutex down)
 	void    lock_get(gen_lock_t* lock);      - lock (mutex down)
 	void    lock_release(gen_lock_t* lock);  - unlock (mutex up)
 	void    lock_release(gen_lock_t* lock);  - unlock (mutex up)
 	int     lock_try(gen_lock_t* lock);      - tries to get the lock, returns
 	int     lock_try(gen_lock_t* lock);      - tries to get the lock, returns
-	                                            0 on success and -1 on failure
+	                                            0 on success and !=0 on failure
 	
 	
 	lock sets: 
 	lock sets: 
 	----------
 	----------
@@ -55,7 +56,7 @@ Implements:
 	                                                   set
 	                                                   set
 	int  lock_set_try(gen_lock_set_t* s, int i);    - tries to lock the sem i,
 	int  lock_set_try(gen_lock_set_t* s, int i);    - tries to lock the sem i,
 	                                                  returns 0 on success and
 	                                                  returns 0 on success and
-	                                                  -1 on failure
+	                                                  !=0 on failure
 	
 	
 	defines:
 	defines:
 	--------
 	--------
@@ -80,8 +81,24 @@ WARNING: - lock_set_init may fail for large number of sems (e.g. sysv).
 #ifndef _lock_ops_h
 #ifndef _lock_ops_h
 #define _lock_ops_h
 #define _lock_ops_h
 
 
+#ifdef USE_FUTEX
+#include "futexlock.h"
+/* if no native atomic ops support => USE_FUTEX will be undefined */
+#endif
+
+
+#ifdef USE_FUTEX
+
+typedef futex_lock_t gen_lock_t;
+
+#define lock_destroy(lock) /* do nothing */
+#define lock_init(lock) futex_init(lock)
+#define lock_try(lock)  futex_try(lock)
+#define lock_get(lock)  futex_get(lock)
+#define lock_release(lock) futex_release(lock)
+
 
 
-#ifdef FAST_LOCK
+#elif defined FAST_LOCK
 #include "fastlock.h"
 #include "fastlock.h"
 
 
 typedef fl_lock_t gen_lock_t;
 typedef fl_lock_t gen_lock_t;
@@ -263,7 +280,8 @@ tryagain:
 
 
 /* lock sets */
 /* lock sets */
 
 
-#if defined(FAST_LOCK) || defined(USE_PTHREAD_MUTEX) || defined(USE_POSIX_SEM)
+#if defined(FAST_LOCK) || defined(USE_PTHREAD_MUTEX) || \
+	defined(USE_POSIX_SEM) || defined(USE_FUTEX)
 #define GEN_LOCK_T_PREFERRED
 #define GEN_LOCK_T_PREFERRED
 #define GEN_LOCK_T_PREFERED  /* backwards compat. */
 #define GEN_LOCK_T_PREFERED  /* backwards compat. */
 #define GEN_LOCK_T_UNLIMITED
 #define GEN_LOCK_T_UNLIMITED

+ 33 - 0
lock_ops_init.h

@@ -0,0 +1,33 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2007 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
+ * lock_ops init functions
+ */
+/* 
+ * History:
+ * --------
+ *  2007-05-14  created by andrei
+ */
+
+#ifndef __lock_ops_init_h
+#define __lock_ops_init_h
+
+int init_lock_ops();
+void destroy_lock_ops();
+
+#endif

+ 5 - 0
main.c

@@ -144,6 +144,7 @@
 #include "usr_avp.h"
 #include "usr_avp.h"
 #include "core_cmd.h"
 #include "core_cmd.h"
 #include "flags.h"
 #include "flags.h"
+#include "lock_ops_init.h"
 #include "atomic_ops_init.h"
 #include "atomic_ops_init.h"
 #ifdef USE_DNS_CACHE
 #ifdef USE_DNS_CACHE
 #include "dns_cache.h"
 #include "dns_cache.h"
@@ -470,6 +471,7 @@ void cleanup(show_status)
 	/* zero all shmem alloc vars that we still use */
 	/* zero all shmem alloc vars that we still use */
 	shm_mem_destroy();
 	shm_mem_destroy();
 #endif
 #endif
+	destroy_lock_ops();
 	if (pid_file) unlink(pid_file);
 	if (pid_file) unlink(pid_file);
 	if (pgid_file) unlink(pgid_file);
 	if (pgid_file) unlink(pgid_file);
 }
 }
@@ -1429,6 +1431,9 @@ try_again:
 		dont_daemonize = dont_fork == 2;
 		dont_daemonize = dont_fork == 2;
 		dont_fork = dont_fork == 1;
 		dont_fork = dont_fork == 1;
 	}
 	}
+	/* init locks first */
+	if (init_lock_ops()!=0)
+		goto error;
 	/* init the resolver, before fixing the config */
 	/* init the resolver, before fixing the config */
 	resolv_init();
 	resolv_init();
 	/* fix parameters */
 	/* fix parameters */

+ 3 - 0
test/locking/Makefile

@@ -46,6 +46,9 @@ $(NAME)_pmutex: $(NAME).c
 $(NAME)_fastlock: $(NAME).c
 $(NAME)_fastlock: $(NAME).c
 	gcc $(CFLAGS) $(DEFS) -DFAST_LOCK -o $@ $(INCLUDE) $< $(LIBS) 
 	gcc $(CFLAGS) $(DEFS) -DFAST_LOCK -o $@ $(INCLUDE) $< $(LIBS) 
 
 
+$(NAME)_futex: $(NAME).c
+	gcc $(CFLAGS) $(DEFS) -DFUTEX -o $@ $(INCLUDE) $< $(LIBS) 
+
 all: $(NAME) $(NAME)_sysv  $(NAME)_posix $(NAME)_pmutex \
 all: $(NAME) $(NAME)_sysv  $(NAME)_posix $(NAME)_pmutex \
 		$(NAME)_fastlock
 		$(NAME)_fastlock
 
 

+ 17 - 1
test/locking/locking_test.c

@@ -58,6 +58,12 @@ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 fl_lock_t lock;
 fl_lock_t lock;
 #endif
 #endif
 
 
+#ifdef FUTEX
+#define USE_FUTEX
+#include "../../futexlock.h"
+futex_lock_t lock;
+#endif
+
 #ifdef SYSV_SEM
 #ifdef SYSV_SEM
 #include <sys/ipc.h>
 #include <sys/ipc.h>
 #include <sys/sem.h>
 #include <sys/sem.h>
@@ -123,6 +129,11 @@ static int semid=-1;
 		get_lock(&lock)
 		get_lock(&lock)
 	#define UNLOCK() \
 	#define UNLOCK() \
 		release_lock(&lock)
 		release_lock(&lock)
+#elif defined FUTEX
+	#define LOCK() \
+		futex_get(&lock)
+	#define UNLOCK() \
+		futex_release(&lock)
 #endif
 #endif
 
 
 
 
@@ -139,9 +150,11 @@ static char *version="locking_test 0.1-"
 #elif defined POSIX_SEM
 #elif defined POSIX_SEM
  "posix_sem"
  "posix_sem"
 #elif defined PTHREAD_MUTEX
 #elif defined PTHREAD_MUTEX
- "pthread_mutext"
+ "pthread_mutex"
 #elif defined FAST_LOCK
 #elif defined FAST_LOCK
  "fast_lock"
  "fast_lock"
+#elif defined FUTEX
+ "futex"
 #endif
 #endif
 ;
 ;
 
 
@@ -263,6 +276,9 @@ int main (int argc, char** argv)
 #elif defined FAST_LOCK
 #elif defined FAST_LOCK
 	puts("Initializing fast lock\n");
 	puts("Initializing fast lock\n");
 	init_lock(lock);
 	init_lock(lock);
+#elif defined FUTEX
+	puts("Initializing futex lock\n");
+	futex_init(&lock);
 #endif
 #endif
 
 
 
 

+ 40 - 0
ut.c

@@ -35,6 +35,9 @@
 #include <grp.h>
 #include <grp.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <time.h>
 #include <time.h>
+#include <sys/utsname.h> /* uname() */
+
+
 #include "ut.h"
 #include "ut.h"
 #include "mem/mem.h"
 #include "mem/mem.h"
 
 
@@ -141,3 +144,40 @@ char* as_asciiz(str* s)
     r[s->len] = '\0';
     r[s->len] = '\0';
     return r;
     return r;
 }
 }
+
+
+
+/* return system version (major.minor.minor2) as
+ *  (major<<16)|(minor)<<8|(minor2)
+ * (if some of them are missing, they are set to 0)
+ * if the parameters are not null they are set to the coresp. part 
+ */
+unsigned int get_sys_version(int* major, int* minor, int* minor2)
+{
+	struct utsname un;
+	int m1;
+	int m2;
+	int m3;
+	char* p;
+	
+	memset (&un, 0, sizeof(un));
+	m1=m2=m3=0;
+	/* get sys version */
+	uname(&un);
+	m1=strtol(un.release, &p, 10);
+	if (*p=='.'){
+		p++;
+		m2=strtol(p, &p, 10);
+		if (*p=='.'){
+			p++;
+			m3=strtol(p, &p, 10);
+		}
+	}
+	if (major) *major=m1;
+	if (minor) *minor=m2;
+	if (minor2) *minor2=m3;
+	return ((m1<<16)|(m2<<8)|(m3));
+}
+
+
+

+ 8 - 0
ut.h

@@ -39,6 +39,7 @@
  * 2004-03-08 updated int2str (64 bits, INT2STR_MAX_LEN used) (andrei)
  * 2004-03-08 updated int2str (64 bits, INT2STR_MAX_LEN used) (andrei)
  * 2005-11-29 reverse_hex2int/int2reverse_hex switched to unsigned int (andrei)
  * 2005-11-29 reverse_hex2int/int2reverse_hex switched to unsigned int (andrei)
  * 2005-12-09 added msgid_var (andrei)
  * 2005-12-09 added msgid_var (andrei)
+ * 2007-05-14 added get_sys_ver() (andrei)
  */
  */
 
 
 
 
@@ -510,4 +511,11 @@ time_t _timegm(struct tm* t);
  */
  */
 char* as_asciiz(str* s);
 char* as_asciiz(str* s);
 
 
+
+/* return system version (major.minor.minor2) as
+ *  (major<<16)|(minor)<<8|(minor2)
+ * (if some of them are missing, they are set to 0)
+ * if the parameters are not null they are set to the coresp. part */
+unsigned int get_sys_version(int* major, int* minor, int* minor2);
+
 #endif
 #endif

+ 8 - 1
version.h

@@ -167,6 +167,13 @@
 #define TIMER_DEBUG_STR ""
 #define TIMER_DEBUG_STR ""
 #endif
 #endif
 
 
+#ifdef USE_FUTEX
+#define USE_FUTEX_STR ", USE_FUTEX"
+#else
+#define USE_FUTEX_STR ""
+#endif
+
+
 #ifdef FAST_LOCK
 #ifdef FAST_LOCK
 #ifdef BUSY_WAIT
 #ifdef BUSY_WAIT
 #define FAST_LOCK_STR ", FAST_LOCK-BUSY_WAIT"
 #define FAST_LOCK_STR ", FAST_LOCK-BUSY_WAIT"
@@ -247,7 +254,7 @@
 	USE_STUN_STR DISABLE_NAGLE_STR USE_MCAST_STR NO_DEBUG_STR NO_LOG_STR \
 	USE_STUN_STR DISABLE_NAGLE_STR USE_MCAST_STR NO_DEBUG_STR NO_LOG_STR \
 	NO_SIG_DEBUG_STR DNS_IP_HACK_STR  SHM_MEM_STR SHM_MMAP_STR PKG_MALLOC_STR \
 	NO_SIG_DEBUG_STR DNS_IP_HACK_STR  SHM_MEM_STR SHM_MMAP_STR PKG_MALLOC_STR \
 	VQ_MALLOC_STR F_MALLOC_STR USE_SHM_MEM_STR DBG_QM_MALLOC_STR \
 	VQ_MALLOC_STR F_MALLOC_STR USE_SHM_MEM_STR DBG_QM_MALLOC_STR \
-	DBG_F_MALLOC_STR DEBUG_DMALLOC_STR TIMER_DEBUG_STR \
+	DBG_F_MALLOC_STR DEBUG_DMALLOC_STR TIMER_DEBUG_STR USE_FUTEX_STR \
 	FAST_LOCK_STR NOSMP_STR USE_PTHREAD_MUTEX_STR USE_POSIX_SEM_STR \
 	FAST_LOCK_STR NOSMP_STR USE_PTHREAD_MUTEX_STR USE_POSIX_SEM_STR \
 	USE_SYSV_SEM_STR USE_COMP_STR USE_DNS_CACHE_STR USE_DNS_FAILOVER_STR \
 	USE_SYSV_SEM_STR USE_COMP_STR USE_DNS_CACHE_STR USE_DNS_FAILOVER_STR \
 	USE_DST_BLACKLIST_STR
 	USE_DST_BLACKLIST_STR