summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McBride <sean@rogue-research.com>2011-09-06 10:31:00 +0000
committerVitali Lovich <vlovich@aliph.com>2011-09-06 10:31:26 +0100
commit2934cf3604b2e173bc9cb93b873065e776441e1b (patch)
treed02ccd5baf999b6586f161975245f2733a81a816
parent71b380b0b0046c9442ee3bdfd6e9cc6b1f8ba3aa (diff)
downloadlibusb-2934cf3604b2e173bc9cb93b873065e776441e1b.tar.gz
Darwin: Fix #63 error when apps use Objective-C garbage collection
-rw-r--r--configure.ac1
-rw-r--r--libusb/os/darwin_usb.c15
2 files changed, 15 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 1aa606b..74e15a0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -60,6 +60,7 @@ case $host in
AC_MSG_RESULT([Darwin/Mac OS X])
backend="darwin"
threads="posix"
+ LIBS="${LIBS} -lobjc"
PC_LIBS_PRIVATE="-Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
LTLDFLAGS="${LTLDFLAGS} -Wl,-prebind"
AC_CHECK_HEADERS([poll.h])
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index ae5f0dd..aa4fe36 100644
--- a/libusb/os/darwin_usb.c
+++ b/libusb/os/darwin_usb.c
@@ -34,8 +34,13 @@
#include <mach/clock.h>
#include <mach/clock_types.h>
#include <mach/mach_host.h>
-
#include <mach/mach_port.h>
+
+#include <AvailabilityMacros.h>
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+ #include <objc/objc-auto.h>
+#endif
+
#include <IOKit/IOCFBundle.h>
#include <IOKit/usb/IOUSBLib.h>
#include <IOKit/IOCFPlugIn.h>
@@ -274,6 +279,14 @@ static void *event_thread_main (void *arg0) {
struct libusb_context *ctx = (struct libusb_context *)arg0;
CFRunLoopRef runloop;
+ /* Tell the Objective-C garbage collector about this thread.
+ This is required because, unlike NSThreads, pthreads are
+ not automatically registered. Although we don't use
+ Objective-C, we use CoreFoundation, which does. */
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+ objc_registerThreadWithCollector();
+#endif
+
/* hotplug (device removal) source */
CFRunLoopSourceRef libusb_notification_cfsource;
io_notification_port_t libusb_notification_port;