everybody_busy.patch
  Yield the CPU if all threads are busy or if we didn't get to do any real work

int_to_bools.patch
  Introduce the bool type and do some type changes.

profile-params.patch
  Add some profiling options.

signal_handler.patch
  Handle SIGTERM

lfd_is_minfd.patch
  Remove an ugly constant and replace it with lfd, because we know it's the
  minimum fd.

prerelease_script.patch
  Add a script to run before doing a release.



unchanged:
--- cur-root/net.c	2004-01-17 21:09:20.000000000 -0300
+++ cur-root/net.c	2004-01-17 21:09:32.000000000 -0300
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/types.h>
+#include <stdbool.h>
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <sys/select.h>
@@ -31,7 +32,7 @@
 static int lfd;
 
 /* active file descriptors */
-static char active_fd[MAXCONN];
+static bool active_fd[MAXCONN];
 
 /* orphan locks */
 static struct list *orphans;
@@ -53,13 +54,13 @@
  */
 
 /* thread busy indicators */
-static int thread_busy[MAXTHREADS];
+static bool thread_busy[MAXTHREADS];
 
 /* fd busy indicator */
-static int fd_busy[MAXCONN];
+static bool fd_busy[MAXCONN];
 
 /* temp space used to tell threads which fd to process */
-static int fd_to_process[MAXTHREADS];
+static unsigned int fd_to_process[MAXTHREADS];
 
 /* lock array to 'wake up' idle threads */
 static pthread_mutex_t thread_lock[MAXTHREADS];
@@ -128,8 +129,9 @@
 
 /* main select loop */
 void net_select_loop(int nthreads) {
-	int i, j, rv;
-	int connfd, maxfd;
+	int rv, connfd, maxfd;
+	unsigned int i, j, busycount;
+	bool workdone;
 	fd_set readfds;
 	struct timeval tv;
 	
@@ -161,13 +163,15 @@
 			goto rebuild;
 		}
 		
-		for (i = 3; i <= maxfd; i++) {
-			/* skip the ones not in the set or busy and lfd */
-			if (!FD_ISSET(i, &readfds) || fd_busy[i] || i == lfd)
+		workdone = 0;
+		for (i = lfd + 1; i <= maxfd; i++) {
+			/* skip the ones not in the set or busy */
+			if (!FD_ISSET(i, &readfds) || fd_busy[i])
 				continue;
 			
 			/* loop looking for an idle thread; see
 			 * doc/multithread */
+			busycount = 0;
 			for (j = 0; j < nthreads; j++) {
 				if (!thread_busy[j]) {
 					/* we found one, so mark it busy, tell
@@ -177,9 +181,17 @@
 					fd_busy[i] = 1;
 					fd_to_process[j] = i;
 					pthread_mutex_unlock(&thread_lock[j]);
+					workdone = 1;
 					break;
 				}
+				busycount++;
 			}
+			
+			/* if everybody is busy, yield the cpu */
+			if (unlikely(busycount == nthreads)) {
+				sched_yield();
+			}
+			
 			/* if we didn't find any idle thread to assign the
 			 * job, just loop and go back to select */
 		}
@@ -203,6 +215,12 @@
 				maxfd = connfd;
 			
 			active_fd[connfd] = 1;
+			workdone = 1;
+		}
+
+		/* if we didn't do any work, yield the cpu */
+		if (unlikely(!workdone)) {
+			sched_yield();
 		}
 		
 		/* rebuild the fd sets for select */
@@ -232,7 +250,7 @@
 		pthread_mutex_lock(&thread_lock[tid]);
 		
 		fd = fd_to_process[tid];
-			
+		
 		cmd = net_get_cmd(fd);
 		if (cmd == NULL)
 			goto end_loop;
unchanged:
--- cur/include/hash.h~int_to_bools	2004-01-17 21:09:20.000000000 -0300
+++ cur-root/include/hash.h	2004-01-17 21:09:20.000000000 -0300
@@ -2,12 +2,14 @@
 #ifndef _HASH_H
 #define _HASH_H
 
+#include <stdbool.h>
+
 #include "wqueue.h"
 
 struct hentry {
 	char *objname;
 	unsigned int len;
-	char locked;
+	bool locked;
 	int fd;
 	struct wqentry *wq;
 	struct hentry *next;
unchanged:
--- cur/Make.conf~profile-params	2004-01-17 21:09:26.000000000 -0300
+++ cur-root/Make.conf	2004-01-17 21:09:26.000000000 -0300
@@ -7,7 +7,7 @@ LIBS += -lpthread
 INCLUDES += -I$(PWD)/include
 
 ifdef DEBUG
-CFLAGS += -g -pg
+CFLAGS += -g -pg -fprofile-arcs -ftest-coverage
 endif
 
 
unchanged:
--- cur/Makefile~profile-params	2004-01-17 21:09:26.000000000 -0300
+++ cur-root/Makefile	2004-01-17 21:09:26.000000000 -0300
@@ -42,7 +42,10 @@ man_install:
 cleanobj:
 	rm -f $(OBJS) lib/libold.o
 
-clean: cleanobj
+cleandebug:
+	rm -f *.bb *.bbg *.da *.gcov gmon.out
+
+clean: cleanobj cleandebug
 	rm -rf $(BUILD)
 	$(MAKE) -C lib/ clean
 
unchanged:
--- cur/lib/Makefile~profile-params	2004-01-17 21:09:26.000000000 -0300
+++ cur-root/lib/Makefile	2004-01-17 21:09:26.000000000 -0300
@@ -32,7 +32,10 @@ cleanobj:
 	rm -f oldtest.o
 	rm -f oldtest2.o
 
-clean: cleanobj
+cleandebug:
+	rm -f *.bb *.bbg *.da *.gcov gmon.out
+
+clean: cleanobj cleandebug
 	rm -f $(BUILD)/oldtest
 	rm -f $(BUILD)/oldtest2
 	rm -f $(BUILD)/libold.so
unchanged:
--- cur/main.c~signal_handler	2004-01-17 21:09:29.000000000 -0300
+++ cur-root/main.c	2004-01-17 21:09:29.000000000 -0300
@@ -15,6 +15,11 @@
 #include "lock.h"
 #include "net.h"
 
+
+void sighandler (int s) {
+	exit(0);
+}
+
 int main(int argc, char **argv)
 {
 	int i, nthreads;
@@ -44,6 +49,9 @@ int main(int argc, char **argv)
 	/* ignore SIGPIPE */
 	signal(SIGPIPE, SIG_IGN);
 
+	/* exit on SIGTERM */
+	signal(SIGTERM, &sighandler);
+
 	/* detach */
 	pid = fork();
 	if (pid > 0) {
only in patch2:
unchanged:
--- /dev/null	1969-12-31 21:00:00.000000000 -0300
+++ cur-root/utils/prerelease	2004-01-17 22:42:30.000000000 -0300
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+if [ $# -ne 1 ]; then
+	echo "Usage: prerelease RELNUM"
+	exit
+fi
+
+echo "Creating the full patch"
+patchdesc $(cat ps/series) > ../old-$1.patch
+echo >> ../old-$1.patch
+echo >> ../old-$1.patch
+combine-series ../old-$1.patch-t1
+cat ../old-$1.patch-t1 >> ../old-$1.patch
+rm ../old-$1.patch-t1
+
+echo "Cleaning up"
+make clean
+
+
