summaryrefslogtreecommitdiff
path: root/libusb/os/threads_posix.h
diff options
context:
space:
mode:
authorPete Batard <pbatard@gmail.com>2010-02-24 11:29:43 +0000
committerPete Batard <pbatard@gmail.com>2010-02-24 11:29:43 +0000
commitc83b94c78f1cc5c823b677c9963d133a2d408776 (patch)
tree1fbc38157c924eafb8134d863fbe449b52114655 /libusb/os/threads_posix.h
parent1d8a2cc6ae71cc445bc6d1c3f43a803e24a8fbb9 (diff)
downloadlibusb-c83b94c78f1cc5c823b677c9963d133a2d408776.tar.gz
merge abstraction for POSIX Threads and integration changes (Michael Plante, Peter Stuge)r169
v1.0.6 release Darwin: support multiple calls to libusb_init Credit to Orin Eman for finding this bug. Darwin: use logging functions Use usbi_warn, usbi_err, and usbi_info instead of _usbi_log. Darwin: fix memory leak in process_device Credit to Mike Colagrosso for finding this bug. Add internal abstraction for POSIX Threads This prepares for a Windows backend without dependency on pthreads-w32. pthread_* is renamed to usbi_* and PTHREAD_* to USBI_*. A usbi_mutex_static_t and usbi_mutex_static_lock() and _unlock() are introduced for statically initialized mutexes, since they may be implemented using other types when pthreads mutexes aren't used. Move -pthread from libusb/Makefile.am to host-specific AM_CFLAGS in configure.ac. AM_CFLAGS is already used in Makefile.am. (Numerous merge conflicts resolved by Michael Plante) misc fixes to pthreads abstraction * windows_compat.h should not be directly included (use libusbi.h) * windows_usb.c still had some references to pthread_mutex_[un]lock Add libusb_strerror() to get short error message in English from enum (Merge conflicts resolved by Michael Plante) Better cleanup on errors, stricter types and some good casts Avoid various memory leaks in error code paths and remove warnings. Also add usbi_cond_destroy in os/threads_posix.h because it's used for cleanup now. (Merge conflicts resolved by Michael Plante) Rename all interface parameters to usb_interface or interface_number (Merge conflicts resolved by Michael Plante) Add type parameter to the list_for_each_entry() and _safe() macros (Merge conflicts resolved by Michael Plante) VA_ARGS workaround for logging with MSVC6 (Merge conflicts resolved by Michael Plante) Fix context memory leak in libusb_init() * Now holds default_context_lock for duration of libusb_init * Doesn't allocate it if not needed Fix the last MSVC /W3 warning removal of pthreads from MSVC and mingw * removed pthread*.lib from linking in msvc6 (2005/8 not yet edited) * added threads_windows.[ch] to all project files in msvc6 * added usbi_cond_signal to both threading versions, unused * added native windows threading code, now used removed redundant time.h includes removed pthread-win32 informational solution files updated MSVC 2005/2008 for thread abstraction fixed DDK build fixed cygwin's use of POSIX threads fixed dpfp/dpfp_threaded for MinGW compatibility config_msvc.h -> msvc/config.h pthread abstraction for DLL project files fixed bad reference to thread_windows in 2005 DLL vcproj cygwin ifdef is not required in threads_windows.h - removed fixed residuals from previous patches moved thread source detection into autotool scripts
Diffstat (limited to 'libusb/os/threads_posix.h')
-rw-r--r--libusb/os/threads_posix.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/libusb/os/threads_posix.h b/libusb/os/threads_posix.h
new file mode 100644
index 0000000..7e34dc5
--- /dev/null
+++ b/libusb/os/threads_posix.h
@@ -0,0 +1,46 @@
+/*
+ * libusb synchronization using POSIX Threads
+ *
+ * Copyright (C) 2010 Peter Stuge <peter@stuge.se>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __LIBUSB_THREADS_POSIX_H__
+#define __LIBUSB_THREADS_POSIX_H__
+
+#include <pthread.h>
+
+#define usbi_mutex_static_t static pthread_mutex_t
+#define USBI_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+#define usbi_mutex_static_lock pthread_mutex_lock
+#define usbi_mutex_static_unlock pthread_mutex_unlock
+
+#define usbi_mutex_t pthread_mutex_t
+#define usbi_mutex_init pthread_mutex_init
+#define usbi_mutex_lock pthread_mutex_lock
+#define usbi_mutex_unlock pthread_mutex_unlock
+#define usbi_mutex_trylock pthread_mutex_trylock
+#define usbi_mutex_destroy pthread_mutex_destroy
+
+#define usbi_cond_t pthread_cond_t
+#define usbi_cond_init pthread_cond_init
+#define usbi_cond_wait pthread_cond_wait
+#define usbi_cond_timedwait pthread_cond_timedwait
+#define usbi_cond_broadcast pthread_cond_broadcast
+#define usbi_cond_destroy pthread_cond_destroy
+#define usbi_cond_signal pthread_cond_signal
+
+#endif /* __LIBUSB_THREADS_POSIX_H__ */