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>
This commit is contained in:
Nathan Hjelm
2014-02-26 08:02:40 -07:00
parent 886decee7a
commit 8facad00ea
2 changed files with 3 additions and 8 deletions
+2 -7
View File
@@ -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);
+1 -1
View File
@@ -1 +1 @@
#define LIBUSB_NANO 10869
#define LIBUSB_NANO 10870