summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Hjelm <hjelmn@me.com>2016-09-12 21:38:44 -0600
committerNathan Hjelm <hjelmn@me.com>2016-09-12 21:38:44 -0600
commit1e05092aa98d60c717929629ac16590595e08431 (patch)
tree8c3c90a1c1183e108b39ccf5af372ecc6a13f981
parent756cc2b5d1558cb7ef59f73d4246f50c4f18824a (diff)
downloadlibusb-1e05092aa98d60c717929629ac16590595e08431.tar.gz
darwin: do not use deprecated OSAtomicIncrement32Barrier in 10.12
This commit fixes a warning introduced by macOS 10.12 Sierra when using the OS atomics. These atomics have been deprecated in favor of the ones provided by C11 (stdatomic.h). On older versions of OS X we still use the OS atomics (now OSAtomicAdd32Barrier) and on 10.12.0 and newer we use atomic_fetch_add. Signed-off-by: Nathan Hjelm <hjelmn@me.com>
-rw-r--r--libusb/os/darwin_usb.c24
-rw-r--r--libusb/version_nano.h2
2 files changed, 20 insertions, 6 deletions
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index c2b2263..9f5d9d0 100644
--- a/libusb/os/darwin_usb.c
+++ b/libusb/os/darwin_usb.c
@@ -1,7 +1,7 @@
/* -*- Mode: C; indent-tabs-mode:nil -*- */
/*
* darwin backend for libusb 1.0
- * Copyright © 2008-2014 Nathan Hjelm <hjelmn@users.sourceforge.net>
+ * Copyright © 2008-2016 Nathan Hjelm <hjelmn@users.sourceforge.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -29,7 +29,6 @@
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
-#include <libkern/OSAtomic.h>
#include <sys/sysctl.h>
#include <mach/clock.h>
@@ -42,6 +41,22 @@
#include <objc/objc-auto.h>
#endif
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
+/* Apple deprecated the darwin atomics in 10.12 in favor of C11 atomics */
+#include <stdatomic.h>
+#define libusb_darwin_atomic_fetch_add(x, y) atomic_fetch_add(x, y)
+
+_Atomic int32_t initCount = ATOMIC_VAR_INIT(0);
+#else
+/* use darwin atomics if the target is older than 10.12 */
+#include <libkern/OSAtomic.h>
+
+/* OSAtomicAdd32Barrier returns the new value */
+#define libusb_darwin_atomic_fetch_add(x, y) (OSAtomicAdd32Barrier(x, y) - y)
+
+static volatile int32_t initCount = 0;
+#endif
+
#include "darwin_usb.h"
/* async event thread */
@@ -55,7 +70,6 @@ static clock_serv_t clock_monotonic;
static CFRunLoopRef libusb_darwin_acfl = NULL; /* event cf loop */
static CFRunLoopSourceRef libusb_darwin_acfls = NULL; /* shutdown signal for event cf loop */
-static volatile int32_t initCount = 0;
static usbi_mutex_t darwin_cached_devices_lock = PTHREAD_MUTEX_INITIALIZER;
static struct list_head darwin_cached_devices = {&darwin_cached_devices, &darwin_cached_devices};
@@ -511,7 +525,7 @@ static int darwin_init(struct libusb_context *ctx) {
return rc;
}
- if (OSAtomicIncrement32Barrier(&initCount) == 1) {
+ if (libusb_darwin_atomic_fetch_add (&initCount, 1) == 0) {
/* create the clocks that will be used */
host_self = mach_host_self();
@@ -531,7 +545,7 @@ static int darwin_init(struct libusb_context *ctx) {
}
static void darwin_exit (void) {
- if (OSAtomicDecrement32Barrier(&initCount) == 0) {
+ if (libusb_darwin_atomic_fetch_add (&initCount, -1) == 1) {
mach_port_deallocate(mach_task_self(), clock_realtime);
mach_port_deallocate(mach_task_self(), clock_monotonic);
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index d8b7bd4..ae95b50 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11142
+#define LIBUSB_NANO 11143