summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-03-22 12:17:30 -0400
committerNick Mathewson <nickm@torproject.org>2012-03-22 12:17:30 -0400
commit3e9612cd81c8a9881ef298fa59c40af343e4f126 (patch)
tree7c49e7b12dff949d15784dc4cc5150727a820a20
parent24dab0b3597a4062d479ce8ee38dc6abf81b9e57 (diff)
parent041ca00c754eed316b7e3066613abee620aae9b5 (diff)
downloadlibevent-3e9612cd81c8a9881ef298fa59c40af343e4f126.tar.gz
Merge branch 'global_shutdown_rebased_v2'
-rw-r--r--event.c45
-rw-r--r--evsignal-internal.h1
-rw-r--r--evutil.c5
-rw-r--r--evutil_rand.c18
-rw-r--r--include/event2/event.h16
-rw-r--r--sample/event-read-fifo.c1
-rw-r--r--signal.c18
-rw-r--r--util-internal.h3
8 files changed, 107 insertions, 0 deletions
diff --git a/event.c b/event.c
index 830dacbf..a1695fff 100644
--- a/event.c
+++ b/event.c
@@ -3124,6 +3124,51 @@ event_base_del_virtual_(struct event_base *base)
EVBASE_RELEASE_LOCK(base, th_base_lock);
}
+static void
+event_free_debug_globals_locks(void)
+{
+#ifndef EVENT__DISABLE_THREAD_SUPPORT
+#ifndef EVENT__DISABLE_DEBUG_MODE
+ if (event_debug_map_lock_ != NULL) {
+ EVTHREAD_FREE_LOCK(event_debug_map_lock_, 0);
+ }
+#endif /* EVENT__DISABLE_DEBUG_MODE */
+#endif /* EVENT__DISABLE_THREAD_SUPPORT */
+ return;
+}
+
+static void
+event_free_debug_globals(void)
+{
+ event_free_debug_globals_locks();
+}
+
+static void
+event_free_evsig_globals(void)
+{
+ evsig_free_globals_();
+}
+
+static void
+event_free_evutil_globals(void)
+{
+ evutil_free_globals_();
+}
+
+static void
+event_free_globals(void)
+{
+ event_free_debug_globals();
+ event_free_evsig_globals();
+ event_free_evutil_globals();
+}
+
+void
+libevent_global_shutdown(void)
+{
+ event_free_globals();
+}
+
#ifndef EVENT__DISABLE_THREAD_SUPPORT
int
event_global_setup_locks_(const int enable_locks)
diff --git a/evsignal-internal.h b/evsignal-internal.h
index e1b1109f..5cff03b5 100644
--- a/evsignal-internal.h
+++ b/evsignal-internal.h
@@ -60,5 +60,6 @@ int evsig_init_(struct event_base *);
void evsig_dealloc_(struct event_base *);
void evsig_set_base_(struct event_base *base);
+void evsig_free_globals_(void);
#endif /* EVSIGNAL_INTERNAL_H_INCLUDED_ */
diff --git a/evutil.c b/evutil.c
index a16d0beb..4fa3754c 100644
--- a/evutil.c
+++ b/evutil.c
@@ -2543,3 +2543,8 @@ evutil_eventfd_(unsigned initval, int flags)
#endif
}
+void
+evutil_free_globals_(void)
+{
+ evutil_free_secure_rng_globals_();
+}
diff --git a/evutil_rand.c b/evutil_rand.c
index 58d8bd9e..fbb0ed43 100644
--- a/evutil_rand.c
+++ b/evutil_rand.c
@@ -50,11 +50,13 @@ evutil_secure_rng_init(void)
(void) arc4random();
return 0;
}
+#ifndef EVENT__DISABLE_THREAD_SUPPORT
int
evutil_secure_rng_global_setup_locks_(const int enable_locks)
{
return 0;
}
+#endif
static void
ev_arc4random_buf(void *buf, size_t n)
@@ -112,6 +114,22 @@ evutil_secure_rng_global_setup_locks_(const int enable_locks)
}
#endif
+static void
+evutil_free_secure_rng_globals_locks(void)
+{
+#ifndef EVENT__DISABLE_THREAD_SUPPORT
+ if (arc4rand_lock != NULL) {
+ EVTHREAD_FREE_LOCK(arc4rand_lock, 0);
+ }
+#endif
+ return;
+}
+void
+evutil_free_secure_rng_globals_(void) {
+{
+ evutil_free_secure_rng_globals_locks();
+}
+
int
evutil_secure_rng_init(void)
{
diff --git a/include/event2/event.h b/include/event2/event.h
index 41df727f..d209c815 100644
--- a/include/event2/event.h
+++ b/include/event2/event.h
@@ -1310,6 +1310,22 @@ int event_base_gettimeofday_cached(struct event_base *base,
*/
int event_base_update_cache_time(struct event_base *base);
+/** Release up all globally-allocated resources allocated by Libevent.
+
+ This function does not free developer-controlled resources like
+ event_bases, events, bufferevents, listeners, and so on. It only releases
+ resources like global locks that there is no other way to free.
+
+ It is not actually necessary to call this function before exit: every
+ resource that it frees would be released anyway on exit. It mainly exists
+ so that resource-leak debugging tools don't see Libevent as holding
+ resources at exit.
+
+ You should only call this function when no other Libevent functions will
+ be invoked -- e.g., when cleanly exiting a program.
+ */
+void libevent_global_shutdown(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/sample/event-read-fifo.c b/sample/event-read-fifo.c
index a07ab111..8ed26560 100644
--- a/sample/event-read-fifo.c
+++ b/sample/event-read-fifo.c
@@ -156,6 +156,7 @@ main(int argc, char **argv)
close(socket);
unlink(fifo);
#endif
+ libevent_global_shutdown();
return (0);
}
diff --git a/signal.c b/signal.c
index 6872a1d0..c8ae5c22 100644
--- a/signal.c
+++ b/signal.c
@@ -449,6 +449,23 @@ evsig_dealloc_(struct event_base *base)
}
}
+static void
+evsig_free_globals_locks(void)
+{
+#ifndef EVENT__DISABLE_THREAD_SUPPORT
+ if (evsig_base_lock != NULL) {
+ EVTHREAD_FREE_LOCK(evsig_base_lock, 0);
+ }
+#endif
+ return;
+}
+
+void
+evsig_free_globals_(void)
+{
+ evsig_free_globals_locks();
+}
+
#ifndef EVENT__DISABLE_THREAD_SUPPORT
int
evsig_global_setup_locks_(const int enable_locks)
@@ -456,4 +473,5 @@ evsig_global_setup_locks_(const int enable_locks)
EVTHREAD_SETUP_GLOBAL_LOCK(evsig_base_lock, 0);
return 0;
}
+
#endif
diff --git a/util-internal.h b/util-internal.h
index 7117460c..508eae92 100644
--- a/util-internal.h
+++ b/util-internal.h
@@ -347,6 +347,9 @@ int evutil_hex_char_to_int_(char c);
void evutil_usleep_(const struct timeval *tv);
+void evutil_free_secure_rng_globals_(void);
+void evutil_free_globals_(void);
+
#ifdef _WIN32
HANDLE evutil_load_windows_system_library_(const TCHAR *library_name);
#endif