diff options
author | Pete Batard <pbatard@gmail.com> | 2010-02-24 11:29:43 +0000 |
---|---|---|
committer | Pete Batard <pbatard@gmail.com> | 2010-02-24 11:29:43 +0000 |
commit | c83b94c78f1cc5c823b677c9963d133a2d408776 (patch) | |
tree | 1fbc38157c924eafb8134d863fbe449b52114655 /examples | |
parent | 1d8a2cc6ae71cc445bc6d1c3f43a803e24a8fbb9 (diff) | |
download | libusb-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 'examples')
-rw-r--r-- | examples/Makefile.am | 3 | ||||
-rw-r--r-- | examples/dpfp.c | 7 | ||||
-rw-r--r-- | examples/dpfp_threaded.c | 9 | ||||
-rw-r--r-- | examples/lsusb.dsp | 4 | ||||
-rw-r--r-- | examples/lsusb_2005.vcproj | 8 | ||||
-rw-r--r-- | examples/lsusb_2008.vcproj | 8 | ||||
-rw-r--r-- | examples/lsusb_sources | 15 | ||||
-rw-r--r-- | examples/xusb.c | 4 | ||||
-rw-r--r-- | examples/xusb.dsp | 4 | ||||
-rw-r--r-- | examples/xusb_2005.vcproj | 8 | ||||
-rw-r--r-- | examples/xusb_2008.vcproj | 8 | ||||
-rw-r--r-- | examples/xusb_sources | 15 |
12 files changed, 38 insertions, 55 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am index fe6cae4..d178d07 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,6 +1,5 @@ INCLUDES = -I$(top_srcdir) -noinst_PROGRAMS = xusb lsusb -#dpfp dpfp_threaded +noinst_PROGRAMS = xusb lsusb dpfp dpfp_threaded lsusb_SOURCES = lsusb.c lsusb_LDADD = ../libusb/libusb-1.0.la -lusb-1.0 diff --git a/examples/dpfp.c b/examples/dpfp.c index bd9702a..e218246 100644 --- a/examples/dpfp.c +++ b/examples/dpfp.c @@ -416,7 +416,9 @@ static void sighandler(int signum) int main(void) { +#ifndef __MINGW32__ struct sigaction sigact; +#endif int r = 1; r = libusb_init(NULL); @@ -456,12 +458,17 @@ int main(void) if (r < 0) goto out_deinit; +#ifndef __MINGW32__ sigact.sa_handler = sighandler; sigemptyset(&sigact.sa_mask); sigact.sa_flags = 0; sigaction(SIGINT, &sigact, NULL); sigaction(SIGTERM, &sigact, NULL); sigaction(SIGQUIT, &sigact, NULL); +#else + signal(SIGINT, sighandler); + signal(SIGTERM, sighandler); +#endif while (!do_exit) { r = libusb_handle_events(NULL); diff --git a/examples/dpfp_threaded.c b/examples/dpfp_threaded.c index 59540e3..6ae59ef 100644 --- a/examples/dpfp_threaded.c +++ b/examples/dpfp_threaded.c @@ -92,6 +92,7 @@ static void *poll_thread_main(void *arg) printf("poll thread shutting down\n"); pthread_exit(NULL); + return NULL; } static int find_dpfp_device(void) @@ -443,7 +444,9 @@ static void sighandler(int signum) int main(void) { +#ifndef __MINGW32__ struct sigaction sigact; +#endif int r = 1; r = libusb_init(NULL); @@ -474,13 +477,17 @@ int main(void) goto out_deinit; /* async from here onwards */ - +#ifndef __MINGW32__ sigact.sa_handler = sighandler; sigemptyset(&sigact.sa_mask); sigact.sa_flags = 0; sigaction(SIGINT, &sigact, NULL); sigaction(SIGTERM, &sigact, NULL); sigaction(SIGQUIT, &sigact, NULL); +#else + signal(SIGINT, sighandler); + signal(SIGTERM, sighandler); +#endif r = pthread_create(&poll_thread, NULL, poll_thread_main, NULL); if (r) diff --git a/examples/lsusb.dsp b/examples/lsusb.dsp index 96841be..b598ffa 100644 --- a/examples/lsusb.dsp +++ b/examples/lsusb.dsp @@ -50,7 +50,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 pthreadVC2.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "D:/Program Files/Microsoft SDK/Lib/setupapi.lib" /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "D:/Program Files/Microsoft SDK/Lib/setupapi.lib" /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "lsusb - Win32 Debug" @@ -74,7 +74,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo /n "../Win32/Debug/dll/core.sbr" "../Win32/Debug/dll/descriptor.sbr" "../Win32/Debug/dll/io.sbr" "../Win32/Debug/dll/sync.sbr" "../Win32/Debug/dll/windows_compat.sbr" "../Win32/Debug/dll/windows_usb.sbr" LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 pthreadVC2d.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "D:/Program Files/Microsoft SDK/Lib/setupapi.lib" /nologo /subsystem:console /debug /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "D:/Program Files/Microsoft SDK/Lib/setupapi.lib" /nologo /subsystem:console /debug /machine:I386 # SUBTRACT LINK32 /pdb:none !ENDIF diff --git a/examples/lsusb_2005.vcproj b/examples/lsusb_2005.vcproj index 0b46e40..453b2a2 100644 --- a/examples/lsusb_2005.vcproj +++ b/examples/lsusb_2005.vcproj @@ -64,7 +64,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2.lib ole32.lib advapi32.lib" + AdditionalDependencies="setupapi.lib ole32.lib advapi32.lib" LinkIncremental="2" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" @@ -140,7 +140,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2.lib ole32.lib advapi32.lib" + AdditionalDependencies="setupapi.lib ole32.lib advapi32.lib" LinkIncremental="1" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" @@ -221,7 +221,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2_x64.lib" + AdditionalDependencies="setupapi.lib" LinkIncremental="2" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" @@ -298,7 +298,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2_x64.lib" + AdditionalDependencies="setupapi.lib" LinkIncremental="1" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" diff --git a/examples/lsusb_2008.vcproj b/examples/lsusb_2008.vcproj index 8316fe9..560f296 100644 --- a/examples/lsusb_2008.vcproj +++ b/examples/lsusb_2008.vcproj @@ -65,7 +65,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2.lib" + AdditionalDependencies="setupapi.lib" LinkIncremental="2" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" @@ -142,7 +142,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2_x64.lib" + AdditionalDependencies="setupapi.lib" LinkIncremental="2" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" @@ -219,7 +219,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2.lib" + AdditionalDependencies="setupapi.lib" LinkIncremental="1" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" @@ -299,7 +299,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2_x64.lib" + AdditionalDependencies="setupapi.lib" LinkIncremental="1" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" diff --git a/examples/lsusb_sources b/examples/lsusb_sources index fcb4c4d..82ea935 100644 --- a/examples/lsusb_sources +++ b/examples/lsusb_sources @@ -11,26 +11,13 @@ MSC_WARNING_LEVEL=/W3 -!IF "$(_BUILDARCH)"=="AMD64" - -PTHREAD_LIB=pthreadVC2_x64.lib - -!ELSE - -PTHREAD_LIB=pthreadVC2.lib - -!ENDIF - - - USE_MSVCRT=1 UMTYPE=console INCLUDES=..\..\msvc;..\..;$(DDK_INC_PATH) -UMLIBS=..\..\msvc\$(PTHREAD_LIB) \ - ..\..\libusb\os\obj$(BUILD_ALT_DIR)\*\libusb-1.0.lib +UMLIBS=..\..\libusb\os\obj$(BUILD_ALT_DIR)\*\libusb-1.0.lib SOURCES=..\lsusb.c diff --git a/examples/xusb.c b/examples/xusb.c index 1639523..74735ef 100644 --- a/examples/xusb.c +++ b/examples/xusb.c @@ -22,11 +22,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifdef _MSC_VER -#include <config_msvc.h> -#else #include <config.h> -#endif #include <stdio.h> #include <sys/types.h> #include <inttypes.h> diff --git a/examples/xusb.dsp b/examples/xusb.dsp index 15081c6..b47b8c0 100644 --- a/examples/xusb.dsp +++ b/examples/xusb.dsp @@ -50,7 +50,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 pthreadVC2.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "D:/Program Files/Microsoft SDK/Lib/setupapi.lib" /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "D:/Program Files/Microsoft SDK/Lib/setupapi.lib" /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "xusb - Win32 Debug" @@ -74,7 +74,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo /n "../Win32/Debug/dll/core.sbr" "../Win32/Debug/dll/descriptor.sbr" "../Win32/Debug/dll/io.sbr" "../Win32/Debug/dll/sync.sbr" "../Win32/Debug/dll/windows_compat.sbr" "../Win32/Debug/dll/windows_usb.sbr" LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 pthreadVC2d.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "D:/Program Files/Microsoft SDK/Lib/setupapi.lib" /nologo /subsystem:console /debug /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "D:/Program Files/Microsoft SDK/Lib/setupapi.lib" /nologo /subsystem:console /debug /machine:I386 !ENDIF diff --git a/examples/xusb_2005.vcproj b/examples/xusb_2005.vcproj index 0554e05..19e771a 100644 --- a/examples/xusb_2005.vcproj +++ b/examples/xusb_2005.vcproj @@ -64,7 +64,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2.lib ole32.lib advapi32.lib" + AdditionalDependencies="setupapi.lib ole32.lib advapi32.lib" LinkIncremental="2" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" @@ -140,7 +140,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2.lib ole32.lib advapi32.lib" + AdditionalDependencies="setupapi.lib ole32.lib advapi32.lib" LinkIncremental="1" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" @@ -221,7 +221,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2_x64.lib" + AdditionalDependencies="setupapi.lib" LinkIncremental="2" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" @@ -298,7 +298,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2_x64.lib" + AdditionalDependencies="setupapi.lib" LinkIncremental="1" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" diff --git a/examples/xusb_2008.vcproj b/examples/xusb_2008.vcproj index 4cd9b13..224249a 100644 --- a/examples/xusb_2008.vcproj +++ b/examples/xusb_2008.vcproj @@ -65,7 +65,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2.lib" + AdditionalDependencies="setupapi.lib" LinkIncremental="2" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" @@ -142,7 +142,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2_x64.lib" + AdditionalDependencies="setupapi.lib" LinkIncremental="2" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" @@ -219,7 +219,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2.lib" + AdditionalDependencies="setupapi.lib" LinkIncremental="1" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" @@ -299,7 +299,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="setupapi.lib pthreadVC2_x64.lib" + AdditionalDependencies="setupapi.lib" LinkIncremental="1" AdditionalLibraryDirectories="..\msvc" GenerateDebugInformation="true" diff --git a/examples/xusb_sources b/examples/xusb_sources index 609f369..f69b9e0 100644 --- a/examples/xusb_sources +++ b/examples/xusb_sources @@ -11,26 +11,13 @@ MSC_WARNING_LEVEL=/W3 -!IF "$(_BUILDARCH)"=="AMD64" - -PTHREAD_LIB=pthreadVC2_x64.lib - -!ELSE - -PTHREAD_LIB=pthreadVC2.lib - -!ENDIF - - - USE_MSVCRT=1 UMTYPE=console INCLUDES=..\..\msvc;..\..;$(DDK_INC_PATH) -UMLIBS=..\..\msvc\$(PTHREAD_LIB) \ - ..\..\libusb\os\obj$(BUILD_ALT_DIR)\*\libusb-1.0.lib +UMLIBS=..\..\libusb\os\obj$(BUILD_ALT_DIR)\*\libusb-1.0.lib SOURCES=..\xusb.c |