Blame SOURCES/ElectricFence-2.2.2-pthread.patch

15f68b
--- ElectricFence-2.2.2/efence.c.jj	1999-04-12 21:00:49.000000000 -0400
15f68b
+++ ElectricFence-2.2.2/efence.c	2003-02-03 11:20:18.000000000 -0500
15f68b
@@ -174,6 +174,15 @@ static int		internalUse = 0;
15f68b
 static int		noAllocationListProtection = 0;
15f68b
 
15f68b
 #ifdef USE_SEMAPHORE
15f68b
+
15f68b
+#include <stdbool.h>
15f68b
+
15f68b
+#pragma weak sem_init
15f68b
+#pragma weak sem_post
15f68b
+#pragma weak sem_wait
15f68b
+
15f68b
+static int		pthread_initialization = 0;
15f68b
+
15f68b
 /*
15f68b
  * EF_sem is a semaphore used to allow one thread at a time into
15f68b
  * these routines.
15f68b
@@ -274,7 +283,7 @@ initialize(void)
15f68b
 	EF_Print(version);
15f68b
 
15f68b
 #ifdef USE_SEMAPHORE
15f68b
-	if (sem_init(&EF_sem, 0, 1) >= 0) {
15f68b
+	if (sem_init != NULL && !pthread_initialization && sem_init(&EF_sem, 0, 1) >= 0) {
15f68b
 		semEnabled = 1;
15f68b
 	}
15f68b
 #endif
15f68b
@@ -397,6 +406,21 @@ initialize(void)
15f68b
 	release();
15f68b
 }
15f68b
 
15f68b
+#ifdef USE_SEMAPHORE
15f68b
+void
15f68b
+__libc_malloc_pthread_startup (bool first_time)
15f68b
+{
15f68b
+	if (first_time) {
15f68b
+		pthread_initialization = 1;
15f68b
+		initialize ();
15f68b
+	} else {
15f68b
+		pthread_initialization = 0;
15f68b
+		if (!semEnabled && sem_init != NULL && sem_init(&EF_sem, 0, 1) >= 0)
15f68b
+			semEnabled = 1;
15f68b
+	}
15f68b
+}
15f68b
+#endif
15f68b
+
15f68b
 /*
15f68b
  * allocateMoreSlots is called when there are only enough slot structures
15f68b
  * left to support the allocation of a single malloc buffer.
15f68b
--- ElectricFence-2.2.2/Makefile.jj	1999-04-13 13:22:49.000000000 -0400
15f68b
+++ ElectricFence-2.2.2/Makefile	2003-02-03 11:27:06.000000000 -0500
15f68b
@@ -1,6 +1,6 @@
15f68b
 PIC= -fPIC
15f68b
 CFLAGS= -g -DUSE_SEMAPHORE $(PIC)
15f68b
-LIBS= -lpthread
15f68b
+LIBS=
15f68b
 
15f68b
 prefix=/usr
15f68b
 BIN_INSTALL_DIR= $(prefix)/bin
15f68b
@@ -54,8 +54,8 @@ libefence.a: $(OBJECTS)
15f68b
 	$(AR) crv libefence.a $(OBJECTS)
15f68b
 
15f68b
 libefence.so.0.0: $(OBJECTS)
15f68b
-	gcc -g -shared -Wl,-soname,libefence.so.0 -o libefence.so.0.0 \
15f68b
-		$(OBJECTS) -lpthread -lc 
15f68b
+	gcc -shared -Wl,-soname,libefence.so.0 -o libefence.so.0.0 \
15f68b
+		$(CFLAGS) $(OBJECTS) 
15f68b
 
15f68b
 tstheap: libefence.a tstheap.o
15f68b
 	- rm -f tstheap