[or-cvs] r10656: Bigfixes to sa_evbufferevents, debug mechanism for evbuffer (in libevent-urz/trunk: . sample)

Urz at seul.org Urz at seul.org
Thu Jun 21 09:19:37 UTC 2007


Author: Urz
Date: 2007-06-21 05:19:37 -0400 (Thu, 21 Jun 2007)
New Revision: 10656

Modified:
   libevent-urz/trunk/Makefile.am
   libevent-urz/trunk/Makefile.in
   libevent-urz/trunk/buffer.c
   libevent-urz/trunk/event.h
   libevent-urz/trunk/sa_evbuffer.c
   libevent-urz/trunk/sample/Makefile.am
   libevent-urz/trunk/sample/Makefile.in
   libevent-urz/trunk/sample/sa_evbuffer-test.c
Log:
Bigfixes to sa_evbufferevents, debug mechanism for evbuffer locks

Modified: libevent-urz/trunk/Makefile.am
===================================================================
--- libevent-urz/trunk/Makefile.am	2007-06-20 11:51:46 UTC (rev 10655)
+++ libevent-urz/trunk/Makefile.am	2007-06-21 09:19:37 UTC (rev 10656)
@@ -1,6 +1,5 @@
 AUTOMAKE_OPTIONS = foreign no-dependencies
 
-
 bin_SCRIPTS = event_rpcgen.py
 
 EXTRA_DIST = acconfig.h event.h event-internal.h log.h evsignal.h evdns.3 \
@@ -44,6 +43,7 @@
 	$(SYS_SRC)
 libevent_la_LIBADD = @LTLIBOBJS@ $(SYS_LIBS)
 libevent_la_LDFLAGS = -release @VERSION@ -version-info 1:3:0
+libevent_la_CFLAGS = -g
 
 include_HEADERS = event.h evhttp.h evdns.h
 

Modified: libevent-urz/trunk/Makefile.in
===================================================================
--- libevent-urz/trunk/Makefile.in	2007-06-20 11:51:46 UTC (rev 10655)
+++ libevent-urz/trunk/Makefile.in	2007-06-21 09:19:37 UTC (rev 10656)
@@ -173,6 +173,7 @@
 
 libevent_la_LIBADD = @LTLIBOBJS@ $(SYS_LIBS)
 libevent_la_LDFLAGS = -release @VERSION@ -version-info 1:3:0
+libevent_la_CFLAGS = -g
 
 include_HEADERS = event.h evhttp.h evdns.h
 
@@ -194,11 +195,14 @@
 	log.c event_tagging.c http.c evhttp.h http-internal.h evdns.c \
 	evdns.h strlcpy.c strlcpy-internal.h WIN32-Code/misc.c \
 	WIN32-Code/win32.c
- at BUILD_WIN32_TRUE@am__objects_1 = misc.lo win32.lo
+ at BUILD_WIN32_TRUE@am__objects_1 = libevent_la-misc.lo \
+ at BUILD_WIN32_TRUE@	libevent_la-win32.lo
 @BUILD_WIN32_FALSE at am__objects_1 =
-am_libevent_la_OBJECTS = event.lo buffer.lo sa_evbuffer.lo evbuffer.lo \
-	log.lo event_tagging.lo sa_evbuffer.lo http.lo evdns.lo \
-	strlcpy.lo $(am__objects_1)
+am_libevent_la_OBJECTS = libevent_la-event.lo libevent_la-buffer.lo \
+	libevent_la-sa_evbuffer.lo libevent_la-evbuffer.lo \
+	libevent_la-log.lo libevent_la-event_tagging.lo \
+	libevent_la-sa_evbuffer.lo libevent_la-http.lo \
+	libevent_la-evdns.lo libevent_la-strlcpy.lo $(am__objects_1)
 libevent_la_OBJECTS = $(am_libevent_la_OBJECTS)
 SCRIPTS = $(bin_SCRIPTS)
 
@@ -226,10 +230,10 @@
 	installdirs-recursive install-recursive uninstall-recursive \
 	check-recursive installcheck-recursive
 DIST_COMMON = README $(include_HEADERS) Makefile.am Makefile.in \
-	acconfig.h aclocal.m4 config.guess config.h.in config.sub \
-	configure configure.in devpoll.c epoll.c epoll_sub.c evport.c \
-	install-sh kqueue.c ltmain.sh missing mkinstalldirs poll.c \
-	rtsig.c select.c signal.c
+	acconfig.h aclocal.m4 compile config.guess config.h.in \
+	config.sub configure configure.in devpoll.c epoll.c epoll_sub.c \
+	evport.c install-sh kqueue.c ltmain.sh missing mkinstalldirs \
+	poll.c rtsig.c select.c signal.c
 DIST_SUBDIRS = . sample test
 SOURCES = $(libevent_la_SOURCES)
 
@@ -299,8 +303,17 @@
 	  echo "rm -f \"$${dir}/so_locations\""; \
 	  rm -f "$${dir}/so_locations"; \
 	done
-misc.lo: WIN32-Code/misc.c
-win32.lo: WIN32-Code/win32.c
+libevent_la-event.lo: event.c
+libevent_la-buffer.lo: buffer.c
+libevent_la-sa_evbuffer.lo: sa_evbuffer.c
+libevent_la-evbuffer.lo: evbuffer.c
+libevent_la-log.lo: log.c
+libevent_la-event_tagging.lo: event_tagging.c
+libevent_la-http.lo: http.c
+libevent_la-evdns.lo: evdns.c
+libevent_la-strlcpy.lo: strlcpy.c
+libevent_la-misc.lo: WIN32-Code/misc.c
+libevent_la-win32.lo: WIN32-Code/win32.c
 libevent.la: $(libevent_la_OBJECTS) $(libevent_la_DEPENDENCIES) 
 	$(LINK) -rpath $(libdir) $(libevent_la_LDFLAGS) $(libevent_la_OBJECTS) $(libevent_la_LIBADD) $(LIBS)
 binSCRIPT_INSTALL = $(INSTALL_SCRIPT)
@@ -339,24 +352,105 @@
 .c.lo:
 	$(LTCOMPILE) -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<
 
-misc.o: WIN32-Code/misc.c
-	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o misc.o `test -f 'WIN32-Code/misc.c' || echo '$(srcdir)/'`WIN32-Code/misc.c
+libevent_la-event.o: event.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-event.o `test -f 'event.c' || echo '$(srcdir)/'`event.c
 
-misc.obj: WIN32-Code/misc.c
-	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o misc.obj `if test -f 'WIN32-Code/misc.c'; then $(CYGPATH_W) 'WIN32-Code/misc.c'; else $(CYGPATH_W) '$(srcdir)/WIN32-Code/misc.c'`
+libevent_la-event.obj: event.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-event.obj `if test -f 'event.c'; then $(CYGPATH_W) 'event.c'; else $(CYGPATH_W) '$(srcdir)/event.c'`
 
-misc.lo: WIN32-Code/misc.c
-	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o misc.lo `test -f 'WIN32-Code/misc.c' || echo '$(srcdir)/'`WIN32-Code/misc.c
+libevent_la-event.lo: event.c
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-event.lo `test -f 'event.c' || echo '$(srcdir)/'`event.c
 
-win32.o: WIN32-Code/win32.c
-	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o win32.o `test -f 'WIN32-Code/win32.c' || echo '$(srcdir)/'`WIN32-Code/win32.c
+libevent_la-buffer.o: buffer.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-buffer.o `test -f 'buffer.c' || echo '$(srcdir)/'`buffer.c
 
-win32.obj: WIN32-Code/win32.c
-	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o win32.obj `if test -f 'WIN32-Code/win32.c'; then $(CYGPATH_W) 'WIN32-Code/win32.c'; else $(CYGPATH_W) '$(srcdir)/WIN32-Code/win32.c'`
+libevent_la-buffer.obj: buffer.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-buffer.obj `if test -f 'buffer.c'; then $(CYGPATH_W) 'buffer.c'; else $(CYGPATH_W) '$(srcdir)/buffer.c'`
 
-win32.lo: WIN32-Code/win32.c
-	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o win32.lo `test -f 'WIN32-Code/win32.c' || echo '$(srcdir)/'`WIN32-Code/win32.c
+libevent_la-buffer.lo: buffer.c
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-buffer.lo `test -f 'buffer.c' || echo '$(srcdir)/'`buffer.c
 
+libevent_la-sa_evbuffer.o: sa_evbuffer.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-sa_evbuffer.o `test -f 'sa_evbuffer.c' || echo '$(srcdir)/'`sa_evbuffer.c
+
+libevent_la-sa_evbuffer.obj: sa_evbuffer.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-sa_evbuffer.obj `if test -f 'sa_evbuffer.c'; then $(CYGPATH_W) 'sa_evbuffer.c'; else $(CYGPATH_W) '$(srcdir)/sa_evbuffer.c'`
+
+libevent_la-sa_evbuffer.lo: sa_evbuffer.c
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-sa_evbuffer.lo `test -f 'sa_evbuffer.c' || echo '$(srcdir)/'`sa_evbuffer.c
+
+libevent_la-evbuffer.o: evbuffer.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-evbuffer.o `test -f 'evbuffer.c' || echo '$(srcdir)/'`evbuffer.c
+
+libevent_la-evbuffer.obj: evbuffer.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-evbuffer.obj `if test -f 'evbuffer.c'; then $(CYGPATH_W) 'evbuffer.c'; else $(CYGPATH_W) '$(srcdir)/evbuffer.c'`
+
+libevent_la-evbuffer.lo: evbuffer.c
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-evbuffer.lo `test -f 'evbuffer.c' || echo '$(srcdir)/'`evbuffer.c
+
+libevent_la-log.o: log.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-log.o `test -f 'log.c' || echo '$(srcdir)/'`log.c
+
+libevent_la-log.obj: log.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-log.obj `if test -f 'log.c'; then $(CYGPATH_W) 'log.c'; else $(CYGPATH_W) '$(srcdir)/log.c'`
+
+libevent_la-log.lo: log.c
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-log.lo `test -f 'log.c' || echo '$(srcdir)/'`log.c
+
+libevent_la-event_tagging.o: event_tagging.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-event_tagging.o `test -f 'event_tagging.c' || echo '$(srcdir)/'`event_tagging.c
+
+libevent_la-event_tagging.obj: event_tagging.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-event_tagging.obj `if test -f 'event_tagging.c'; then $(CYGPATH_W) 'event_tagging.c'; else $(CYGPATH_W) '$(srcdir)/event_tagging.c'`
+
+libevent_la-event_tagging.lo: event_tagging.c
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-event_tagging.lo `test -f 'event_tagging.c' || echo '$(srcdir)/'`event_tagging.c
+
+libevent_la-http.o: http.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-http.o `test -f 'http.c' || echo '$(srcdir)/'`http.c
+
+libevent_la-http.obj: http.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-http.obj `if test -f 'http.c'; then $(CYGPATH_W) 'http.c'; else $(CYGPATH_W) '$(srcdir)/http.c'`
+
+libevent_la-http.lo: http.c
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-http.lo `test -f 'http.c' || echo '$(srcdir)/'`http.c
+
+libevent_la-evdns.o: evdns.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-evdns.o `test -f 'evdns.c' || echo '$(srcdir)/'`evdns.c
+
+libevent_la-evdns.obj: evdns.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-evdns.obj `if test -f 'evdns.c'; then $(CYGPATH_W) 'evdns.c'; else $(CYGPATH_W) '$(srcdir)/evdns.c'`
+
+libevent_la-evdns.lo: evdns.c
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-evdns.lo `test -f 'evdns.c' || echo '$(srcdir)/'`evdns.c
+
+libevent_la-strlcpy.o: strlcpy.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-strlcpy.o `test -f 'strlcpy.c' || echo '$(srcdir)/'`strlcpy.c
+
+libevent_la-strlcpy.obj: strlcpy.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-strlcpy.obj `if test -f 'strlcpy.c'; then $(CYGPATH_W) 'strlcpy.c'; else $(CYGPATH_W) '$(srcdir)/strlcpy.c'`
+
+libevent_la-strlcpy.lo: strlcpy.c
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-strlcpy.lo `test -f 'strlcpy.c' || echo '$(srcdir)/'`strlcpy.c
+
+libevent_la-misc.o: WIN32-Code/misc.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-misc.o `test -f 'WIN32-Code/misc.c' || echo '$(srcdir)/'`WIN32-Code/misc.c
+
+libevent_la-misc.obj: WIN32-Code/misc.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-misc.obj `if test -f 'WIN32-Code/misc.c'; then $(CYGPATH_W) 'WIN32-Code/misc.c'; else $(CYGPATH_W) '$(srcdir)/WIN32-Code/misc.c'`
+
+libevent_la-misc.lo: WIN32-Code/misc.c
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-misc.lo `test -f 'WIN32-Code/misc.c' || echo '$(srcdir)/'`WIN32-Code/misc.c
+
+libevent_la-win32.o: WIN32-Code/win32.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-win32.o `test -f 'WIN32-Code/win32.c' || echo '$(srcdir)/'`WIN32-Code/win32.c
+
+libevent_la-win32.obj: WIN32-Code/win32.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-win32.obj `if test -f 'WIN32-Code/win32.c'; then $(CYGPATH_W) 'WIN32-Code/win32.c'; else $(CYGPATH_W) '$(srcdir)/WIN32-Code/win32.c'`
+
+libevent_la-win32.lo: WIN32-Code/win32.c
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libevent_la_CFLAGS) $(CFLAGS) -c -o libevent_la-win32.lo `test -f 'WIN32-Code/win32.c' || echo '$(srcdir)/'`WIN32-Code/win32.c
+
 mostlyclean-libtool:
 	-rm -f *.lo
 

Modified: libevent-urz/trunk/buffer.c
===================================================================
--- libevent-urz/trunk/buffer.c	2007-06-20 11:51:46 UTC (rev 10655)
+++ libevent-urz/trunk/buffer.c	2007-06-21 09:19:37 UTC (rev 10656)
@@ -69,7 +69,7 @@
 #include "event.h"
 #include "event-internal.h"
 
-void evbuffer_lock(struct evbuffer *buffer)
+void evbuffer_lock(struct evbuffer *buffer, const char *from)
 {
 #ifdef WIN32
     /* Code borrowed and changed from Tor's compat.c */
@@ -89,6 +89,8 @@
      * a thread deadlocking itself.
      */
     DWORD ret;
+    
+    printf("LOCK %x %s\n", (int) buffer, from);
     do {
         ret = WaitForSingleObject(buffer->lock, INFINITE);
         if(ret != WAIT_ABANDONED && ret != WAIT_OBJECT_0) {
@@ -98,11 +100,13 @@
 #endif
 }
 
-void evbuffer_unlock(struct evbuffer *buffer)
+void evbuffer_unlock(struct evbuffer *buffer, const char *from)
 {
 #ifdef WIN32
     /* Code borrowed and changed from Tor's compat.c */
     BOOL ret;
+    
+    printf("UNLOCK %x %s\n", (int) buffer, from);
     ret = 0;
     do {
         ret = ReleaseMutex(buffer->lock);
@@ -153,8 +157,8 @@
 {
 	int res;
 
-    evbuffer_lock(outbuf);
-    evbuffer_lock(inbuf);
+    evbuffer_lock(outbuf, __func__);
+    evbuffer_lock(inbuf, __func__);
     
 	/* Short cut for better performance */
 	if (outbuf->off == 0) {
@@ -176,8 +180,8 @@
 		if (oldoff && outbuf->cb != NULL)
 			(*outbuf->cb)(outbuf, 0, oldoff, outbuf->cbarg);
 		
-        evbuffer_unlock(outbuf);
-        evbuffer_unlock(inbuf);
+        evbuffer_unlock(outbuf, __func__);
+        evbuffer_unlock(inbuf, __func__);
         
 		return (0);
 	}
@@ -188,8 +192,8 @@
 		evbuffer_drain(inbuf, inbuf->off);
 	}
 
-    evbuffer_unlock(outbuf);
-    evbuffer_unlock(inbuf);
+    evbuffer_unlock(outbuf, __func__);
+    evbuffer_unlock(inbuf, __func__);
 	return (res);
 }
 
@@ -202,7 +206,7 @@
 	int sz;
 	va_list aq;
     
-    evbuffer_lock(buf);
+    evbuffer_lock(buf, __func__);
 
 	for (;;) {
 		buffer = (char *)buf->buffer + buf->off;
@@ -223,17 +227,17 @@
 		va_end(aq);
 
 		if (sz == -1)
-            evbuffer_unlock(buf);
+            evbuffer_unlock(buf, __func__);
 			return (-1);
 		if (sz < space) {
 			buf->off += sz;
 			if (buf->cb != NULL)
 				(*buf->cb)(buf, oldoff, buf->off, buf->cbarg);
-            evbuffer_unlock(buf);
+            evbuffer_unlock(buf, __func__);
 			return (sz);
 		}
 		if (evbuffer_expand(buf, sz + 1) == -1)
-            evbuffer_unlock(buf);
+            evbuffer_unlock(buf, __func__);
 			return (-1);
 
 	}
@@ -262,7 +266,7 @@
 {
 	size_t nread = datlen;
     
-    evbuffer_lock(buf);
+    evbuffer_lock(buf, __func__);
     
 	if (nread >= buf->off)
 		nread = buf->off;
@@ -270,7 +274,7 @@
 	memcpy(data, buf->buffer, nread);
 	evbuffer_drain(buf, nread);
     
-    evbuffer_unlock(buf);
+    evbuffer_unlock(buf, __func__);
 	
 	return (nread);
 }
@@ -288,7 +292,7 @@
 	char *line;
 	unsigned int i;
     
-    evbuffer_lock(buffer);
+    evbuffer_lock(buffer, __func__);
     
     data = EVBUFFER_DATA(buffer);
     len = EVBUFFER_LENGTH(buffer);
@@ -324,7 +328,7 @@
 
 	evbuffer_drain(buffer, i + 1);
     
-    evbuffer_unlock(buffer);
+    evbuffer_unlock(buffer, __func__);
     
 	return (line);
 }
@@ -334,13 +338,13 @@
 static inline void
 evbuffer_align(struct evbuffer *buf)
 {
-    evbuffer_lock(buf);
+    evbuffer_lock(buf, __func__);
     
 	memmove(buf->orig_buffer, buf->buffer, buf->off);
 	buf->buffer = buf->orig_buffer;
 	buf->misalign = 0;
     
-    evbuffer_unlock(buf);
+    evbuffer_unlock(buf, __func__);
 }
 
 /* Expands the available space in the event buffer to at least datlen */
@@ -350,7 +354,7 @@
 {
 	size_t need;
 
-    evbuffer_lock(buf);
+    evbuffer_lock(buf, __func__);
     
     need = buf->misalign + buf->off + datlen;
 
@@ -376,7 +380,7 @@
 		if (buf->orig_buffer != buf->buffer)
 			evbuffer_align(buf);
 		if ((newbuf = realloc(buf->buffer, length)) == NULL) {
-            evbuffer_unlock(buf);
+            evbuffer_unlock(buf, __func__);
 			return (-1);
         }
 
@@ -384,7 +388,7 @@
 		buf->totallen = length;
 	}
 
-    evbuffer_unlock(buf);
+    evbuffer_unlock(buf, __func__);
 	return (0);
 }
 
@@ -394,14 +398,14 @@
 	size_t need;
 	size_t oldoff;
     
-    evbuffer_lock(buf);
+    evbuffer_lock(buf, __func__);
     
     need = buf->misalign + buf->off + datlen;
     oldoff = buf->off;
 
 	if (buf->totallen < need) {
 		if (evbuffer_expand(buf, datlen) == -1) {
-            evbuffer_unlock(buf);
+            evbuffer_unlock(buf, __func__);
 			return (-1);
         }
 	}
@@ -412,7 +416,7 @@
 	if (datlen && buf->cb != NULL)
 		(*buf->cb)(buf, oldoff, buf->off, buf->cbarg);
 
-    evbuffer_unlock(buf);
+    evbuffer_unlock(buf, __func__);
 	return (0);
 }
 
@@ -421,7 +425,7 @@
 {
 	size_t oldoff;
     
-    evbuffer_lock(buf);
+    evbuffer_lock(buf, __func__);
     
     oldoff = buf->off;
 
@@ -442,7 +446,7 @@
 	if (buf->off != oldoff && buf->cb != NULL)
 		(*buf->cb)(buf, oldoff, buf->off, buf->cbarg);
     
-    evbuffer_unlock(buf);
+    evbuffer_unlock(buf, __func__);
 
 }
 
@@ -461,7 +465,7 @@
 #ifdef WIN32
 	DWORD dwBytesRead;
 #endif
-    evbuffer_lock(buf);
+    evbuffer_lock(buf, __func__);
     
     oldoff = buf->off;
 
@@ -487,7 +491,7 @@
 
 	/* If we don't have FIONREAD, we might waste some space here */
 	if (evbuffer_expand(buf, howmuch) == -1) {
-        evbuffer_unlock(buf);
+        evbuffer_unlock(buf, __func__);
 		return (-1);
     }
 
@@ -497,21 +501,21 @@
 #ifndef WIN32
 	n = read(fd, p, howmuch);
 	if (n == -1) {
-        evbuffer_unlock(buf);
+        evbuffer_unlock(buf, __func__);
 		return (-1);
     }
 	if (n == 0) {
-        evbuffer_unlock(buf);
+        evbuffer_unlock(buf, __func__);
 		return (0);
     }
 #else
 	n = ReadFile((HANDLE)fd, p, howmuch, &dwBytesRead, NULL);
 	if (n == 0) {
-        evbuffer_unlock(buf);
+        evbuffer_unlock(buf, __func__);
 		return (-1);
     }
 	if (dwBytesRead == 0) {
-        evbuffer_lock(buf);
+        evbuffer_lock(buf, __func__);
 		return (0);
     }
 	n = dwBytesRead;
@@ -523,7 +527,7 @@
 	if (buf->off != oldoff && buf->cb != NULL)
 		(*buf->cb)(buf, oldoff, buf->off, buf->cbarg);
     
-    evbuffer_unlock(buf);
+    evbuffer_unlock(buf, __func__);
 
 	return (n);
 }
@@ -536,33 +540,33 @@
 	DWORD dwBytesWritten;
 #endif
 
-    evbuffer_lock(buffer);
+    evbuffer_lock(buffer, __func__);
     
 #ifndef WIN32
 	n = write(fd, buffer->buffer, buffer->off);
 	if (n == -1) {
-        evbuffer_unlock(buffer);
+        evbuffer_unlock(buffer, __func__);
 		return (-1);
     }
 	if (n == 0) {
-        evbuffer_unlock(buffer);
+        evbuffer_unlock(buffer, __func__);
 		return (0);
     }
 #else
 	n = WriteFile((HANDLE)fd, buffer->buffer, buffer->off, &dwBytesWritten, NULL);
 	if (n == 0) {
-        evbuffer_unlock(buffer);
+        evbuffer_unlock(buffer, __func__);
 		return (-1);
     }
 	if (dwBytesWritten == 0) {
-        evbuffer_unlock(buffer);
+        evbuffer_unlock(buffer, __func__);
 		return (0);
     }
 	n = dwBytesWritten;
 #endif
 	evbuffer_drain(buffer, n);
     
-    evbuffer_unlock(buffer);
+    evbuffer_unlock(buffer, __func__);
 
 	return (n);
 }
@@ -574,7 +578,7 @@
 	u_char *search;
 	u_char *p;
     
-    evbuffer_lock(buffer);
+    evbuffer_lock(buffer, __func__);
     
     remain = buffer->off;
     search = buffer->buffer;
@@ -584,13 +588,13 @@
 		if (remain < len)
 			break;
 		if (memcmp(p, what, len) == 0) {
-            evbuffer_unlock(buffer);
+            evbuffer_unlock(buffer, __func__);
 			return (p);
         }
 		search = p + 1;
 	}
 
-    evbuffer_unlock(buffer);
+    evbuffer_unlock(buffer, __func__);
 	return (NULL);
 }
 
@@ -598,10 +602,10 @@
     void (*cb)(struct evbuffer *, size_t, size_t, void *),
     void *cbarg)
 {
-    evbuffer_lock(buffer);
+    evbuffer_lock(buffer, __func__);
     
 	buffer->cb = cb;
 	buffer->cbarg = cbarg;
     
-    evbuffer_unlock(buffer);
+    evbuffer_unlock(buffer, __func__);
 }

Modified: libevent-urz/trunk/event.h
===================================================================
--- libevent-urz/trunk/event.h	2007-06-20 11:51:46 UTC (rev 10655)
+++ libevent-urz/trunk/event.h	2007-06-21 09:19:37 UTC (rev 10656)
@@ -352,8 +352,8 @@
 void evbuffer_setcb(struct evbuffer *, void (*)(struct evbuffer *, size_t, size_t, void *), void *);
 void evbuffer_set_del_read_cb(struct evbuffer *, void (*)(struct evbuffer *, void *), void *);
 void evbuffer_set_del_write_cb(struct evbuffer *, void (*)(struct evbuffer *, void *), void *); 
-void evbuffer_lock(struct evbuffer *buffer);
-void evbuffer_unlock(struct evbuffer *buffer);
+void evbuffer_lock(struct evbuffer *buffer, const char *from);
+void evbuffer_unlock(struct evbuffer *buffer, const char *from);
 /* 
  * Marshaling tagged data - We assume that all tags are inserted in their
  * numeric order - so that unknown tags will always be higher than the

Modified: libevent-urz/trunk/sa_evbuffer.c
===================================================================
--- libevent-urz/trunk/sa_evbuffer.c	2007-06-20 11:51:46 UTC (rev 10655)
+++ libevent-urz/trunk/sa_evbuffer.c	2007-06-21 09:19:37 UTC (rev 10656)
@@ -231,7 +231,7 @@
 {
     size_t copysize;
     
-    evbuffer_lock(bufev->output);
+    evbuffer_lock(bufev->output, __func__);
     
     if(EVBUFFER_LENGTH(bufev->output) < size) {
         copysize = EVBUFFER_LENGTH(bufev->output);
@@ -255,6 +255,8 @@
         notify();
     }
 
+    evbuffer_unlock(bufev->output, __func__);
+    
 	return copysize;
 }
 
@@ -369,7 +371,7 @@
 		return (res);
 
 	/* If everything is okay, we need to schedule a write */
-	if (size > 0 && (bufev->enabled & EV_WRITE)) {
+	if (size > 0 && (bufev->enabled & EV_WRITE) && bufev->writecb != NULL) {
         bufev->del_write_event_set = 1;
         notify();
     }
@@ -382,13 +384,13 @@
 {
 	int res;
 
-    evbuffer_lock(buf);
+    evbuffer_lock(buf, __func__);
     
 	res = sa_bufferevent_write(bufev, buf->buffer, buf->off);
 	if (res != -1)
 		evbuffer_drain(buf, buf->off);
     
-    evbuffer_unlock(buf);
+    evbuffer_unlock(buf, __func__);
 
 	return (res);
 }
@@ -398,7 +400,7 @@
 {
 	struct evbuffer *buf = bufev->input;
     
-    evbuffer_lock(buf);
+    evbuffer_lock(buf, __func__);
 
 	if (buf->off < size)
 		size = buf->off;
@@ -409,7 +411,7 @@
 	if (size)
 		evbuffer_drain(buf, size);
     
-    evbuffer_unlock(buf);
+    evbuffer_unlock(buf, __func__);
 
 	return (size);
 }

Modified: libevent-urz/trunk/sample/Makefile.am
===================================================================
--- libevent-urz/trunk/sample/Makefile.am	2007-06-20 11:51:46 UTC (rev 10655)
+++ libevent-urz/trunk/sample/Makefile.am	2007-06-21 09:19:37 UTC (rev 10656)
@@ -2,7 +2,7 @@
 
 LDADD = ../libevent.la
 CPPFPLAGS = -I.. 
-CFLAGS = -I../compat
+CFLAGS = -I../compat -g
 
 #noinst_PROGRAMS = event-test time-test signal-test
 noinst_PROGRAMS = time-test signal-test sa_evbuffer-test

Modified: libevent-urz/trunk/sample/Makefile.in
===================================================================
--- libevent-urz/trunk/sample/Makefile.in	2007-06-20 11:51:46 UTC (rev 10655)
+++ libevent-urz/trunk/sample/Makefile.in	2007-06-21 09:19:37 UTC (rev 10656)
@@ -48,7 +48,7 @@
 BUILD_WIN32_TRUE = @BUILD_WIN32_TRUE@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
-CFLAGS = -I../compat
+CFLAGS = -I../compat -g
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CXX = @CXX@

Modified: libevent-urz/trunk/sample/sa_evbuffer-test.c
===================================================================
--- libevent-urz/trunk/sample/sa_evbuffer-test.c	2007-06-20 11:51:46 UTC (rev 10655)
+++ libevent-urz/trunk/sample/sa_evbuffer-test.c	2007-06-21 09:19:37 UTC (rev 10656)
@@ -132,6 +132,7 @@
         
         printf("BufPrint:");
         printf(logpipe->input->buffer);
+        printf("W");
     }
     return 0;
 }
@@ -169,12 +170,16 @@
     floating_ptr += len_read;
     
     while(1) {
+        printf("L");
+        
         str_term = indata;
         while(*str_term != '\0' && str_term < floating_ptr) {
             str_term++;
         }
+        
         if(str_term == floating_ptr) {
             /* Did not read entire string */
+            printf("&");
             return;
         }
         /* We now have a string starting at indata and ending at str_term */
@@ -182,10 +187,12 @@
         if(!strncmp(indata, "[IO", 3) || !strncmp(indata, "[UI", 3)) {
             /* We should really check this for errors, but it's a demo, so who cares */
             sa_bufferevent_write(reader, indata, (size_t) (str_term - indata));
-        } else {
-            /* Found a message, that's not IO or UI. Therefore, discard */
-            memmove(indata, str_term+1, (size_t) (floating_ptr - (str_term+1)));
         }
+        /* Move remaining memory to the start of the buffer */
+        memmove(indata, str_term+1, (size_t) (floating_ptr - (str_term+1)));
+        /* Reset the floating pointer to the new end of memory */
+        floating_ptr = indata + (floating_ptr - (str_term+1));
+        /* printf("@"); */
     }
 }
 
@@ -198,6 +205,7 @@
     
     while(1) {
         Sleep(1000);
+        printf("P");
         
         ret = sa_bufferevent_unload(logpipe, data, 1000);
         
@@ -205,13 +213,14 @@
             continue;
         }
         
-        data[ret+1] = '\0';
+        data[ret] = '\0';
         upto = data;
         
-        while(upto <= (data+ret+1)) {
+        while(upto <= (data+ret)) {
             printf(upto);
             upto += strlen(upto);
         }
+     
         
     }
     return 0;
@@ -236,6 +245,8 @@
     Threads[1] = CreateThread(NULL, 0, &printer_thread, NULL, 0, NULL);
     logmgr_thread(NULL);
     
+    printf("Something very bad happened!\n");
+    
     WaitForMultipleObjects(2, Threads, TRUE, INFINITE);
     /* This should never return */
     return 0;



More information about the tor-commits mailing list