From: Nathan Hjelm Date: Tue, 13 Sep 2016 03:38:44 +0000 (-0600) Subject: darwin: do not use deprecated OSAtomicIncrement32Barrier in 10.12 X-Git-Tag: upstream/1.0.21~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1e05092aa98d60c717929629ac16590595e08431;p=platform%2Fupstream%2Flibusb.git 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 --- 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 + * Copyright © 2008-2016 Nathan Hjelm * * 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 #include #include -#include #include #include @@ -42,6 +41,22 @@ #include #endif +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101300 +/* Apple deprecated the darwin atomics in 10.12 in favor of C11 atomics */ +#include +#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 + +/* 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