summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Hjelm <hjelmn@me.com>2014-02-26 08:02:40 -0700
committerNathan Hjelm <hjelmn@me.com>2014-02-26 08:02:40 -0700
commit8facad00ea66e0609d93ad8aa4e174a6e7be8b3c (patch)
treefdcafe0d0a1abce9e339f4695d6d99a895d95c1c
parent886decee7a33270cc55db11f3a1c22dc45270168 (diff)
downloadlibusb-8facad00ea66e0609d93ad8aa4e174a6e7be8b3c.tar.gz
darwin: use destructor function instead of atexit to cleanup state
Using an atexit function to cleanup the state could cause weird interactions with other atexit functions. Ensure the darwin cleanup function is called last by making it a destructor function instead. Signed-off-by: Nathan Hjelm <hjelmn@me.com>
-rw-r--r--libusb/os/darwin_usb.c9
-rw-r--r--libusb/version_nano.h2
2 files changed, 3 insertions, 8 deletions
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index d1092ec..beba158 100644
--- a/libusb/os/darwin_usb.c
+++ b/libusb/os/darwin_usb.c
@@ -401,7 +401,8 @@ static void *darwin_event_thread_main (void *arg0) {
pthread_exit (NULL);
}
-static void _darwin_finalize(void) {
+/* cleanup function to destroy cached devices */
+static void __attribute__((destructor)) _darwin_finalize(void) {
struct darwin_cached_device *dev, *next;
usbi_mutex_lock(&darwin_cached_devices_lock);
@@ -413,7 +414,6 @@ static void _darwin_finalize(void) {
static int darwin_init(struct libusb_context *ctx) {
host_name_port_t host_self;
- static int initted = 0;
int rc;
rc = darwin_scan_devices (ctx);
@@ -424,11 +424,6 @@ static int darwin_init(struct libusb_context *ctx) {
if (OSAtomicIncrement32Barrier(&initCount) == 1) {
/* create the clocks that will be used */
- if (!initted) {
- initted = 1;
- atexit(_darwin_finalize);
- }
-
host_self = mach_host_self();
host_get_clock_service(host_self, CALENDAR_CLOCK, &clock_realtime);
host_get_clock_service(host_self, SYSTEM_CLOCK, &clock_monotonic);
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 227e258..fb49a5f 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 10869
+#define LIBUSB_NANO 10870