deps.labjack: support building for windows
The only pthread functionality this seems to use is mutexes, which are (fortunately) theoretically trivial to wrap for windows. This compiles, though it is not clear if it actually works correctly.
This commit is contained in:
parent
7275d1c30e
commit
c32390f7c1
4
deps/labjack/ljacklm/build.zig
vendored
4
deps/labjack/ljacklm/build.zig
vendored
@ -17,6 +17,10 @@ pub fn build(b: *std.Build) !void {
|
||||
.link_libc = true,
|
||||
});
|
||||
|
||||
if (target.result.os.tag == .windows) {
|
||||
libljacklm.defineCMacro("LJACKLM_USE_WINDOWS_MUTEX_SHIM", "1");
|
||||
}
|
||||
|
||||
libljacklm.addCSourceFile(.{ .file = b.path("libljacklm/ljacklm.c") });
|
||||
libljacklm.installHeader(b.path("libljacklm/ljacklm.h"), "ljacklm.h");
|
||||
|
||||
|
13
deps/labjack/ljacklm/libljacklm/ljacklm.c
vendored
13
deps/labjack/ljacklm/libljacklm/ljacklm.c
vendored
@ -23,7 +23,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#if defined(LJACKLM_USE_WINDOWS_MUTEX_SHIM)
|
||||
#include <windows.h>
|
||||
#include "windows_mutex_shim.h"
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#endif // LJACKLM_USE_WINDOWS_MUTEX_SHIM
|
||||
|
||||
#include "labjackusb.h"
|
||||
|
||||
|
||||
@ -286,7 +293,9 @@ long GetU12Information( HANDLE hDevice,
|
||||
long *fcddMaxSize,
|
||||
long *hvcMaxSize);
|
||||
|
||||
#if !defined(LJACKLM_USE_WINDOWS_MUTEX_SHIM)
|
||||
unsigned long GetTickCount( void);
|
||||
#endif
|
||||
|
||||
|
||||
__attribute__((constructor))
|
||||
@ -7266,6 +7275,7 @@ long GetU12Information( HANDLE hDevice,
|
||||
}
|
||||
|
||||
|
||||
#if !defined(LJACKLM_USE_WINDOWS_MUTEX_SHIM)
|
||||
//======================================================================
|
||||
//GetTickCount: Implementation of GetTickCount() for Unix. Returns the
|
||||
// current time, expressed as millisconds since the Epoch
|
||||
@ -7276,3 +7286,4 @@ unsigned long GetTickCount( void)
|
||||
gettimeofday(&tv, NULL);
|
||||
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
|
||||
}
|
||||
#endif
|
||||
|
28
deps/labjack/ljacklm/libljacklm/windows_mutex_shim.h
vendored
Normal file
28
deps/labjack/ljacklm/libljacklm/windows_mutex_shim.h
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef LJACKLM_WIN_MUTEX
|
||||
#define LJACKLM_WIN_MUTEX
|
||||
|
||||
typedef CRITICAL_SECTION pthread_mutex_t;
|
||||
|
||||
static inline int pthread_mutex_init(pthread_mutex_t *mutex, void *attr) {
|
||||
InitializeCriticalSection(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void pthread_mutex_lock(pthread_mutex_t *mutex) {
|
||||
EnterCriticalSection(mutex);
|
||||
}
|
||||
|
||||
static inline int pthread_mutex_unlock(pthread_mutex_t *mutex) {
|
||||
LeaveCriticalSection(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int pthread_mutex_trylock(pthread_mutex_t *mutex) {
|
||||
return TryEnterCriticalSection(mutex) == 0;
|
||||
}
|
||||
|
||||
static inline void pthread_mutex_destroy(pthread_mutex_t *mutex) {
|
||||
DeleteCriticalSection(mutex);
|
||||
}
|
||||
|
||||
#endif // LJACKLM_WIN_MUTEX
|
Loading…
x
Reference in New Issue
Block a user