Simple Directmedia Layer
fork

Configure Feed

Select the types of activity you want to include in your feed.

Updated with upstream suggestions in https://github.com/libusb/hidapi/pull/582

+30 -24
+2 -7
src/hidapi/libusb/hid.c
··· 1672 1672 else if (milliseconds > 0) { 1673 1673 /* Non-blocking, but called with timeout. */ 1674 1674 int res; 1675 - struct timespec ts; 1675 + hidapi_timespec ts; 1676 1676 hidapi_thread_gettime(&ts); 1677 - ts.tv_sec += milliseconds / 1000; 1678 - ts.tv_nsec += (milliseconds % 1000) * 1000000; 1679 - if (ts.tv_nsec >= 1000000000L) { 1680 - ts.tv_sec++; 1681 - ts.tv_nsec -= 1000000000L; 1682 - } 1677 + hidapi_thread_addtime(&ts, milliseconds); 1683 1678 1684 1679 while (!dev->input_reports && !dev->shutdown_thread) { 1685 1680 res = hidapi_thread_cond_timedwait(&dev->thread_state, &ts);
+18 -7
src/hidapi/libusb/hidapi_thread_pthread.h
··· 7 7 8 8 libusb/hidapi Team 9 9 10 - Copyright 2022, All Rights Reserved. 10 + Sam Lantinga 11 + 12 + Copyright 2023, All Rights Reserved. 11 13 12 14 At the discretion of the user of this library, 13 15 this software may be licensed under the terms of the ··· 66 68 { 67 69 pthread_mutex_lock(&barrier->mutex); 68 70 ++(barrier->count); 69 - if(barrier->count >= barrier->trip_count) 70 - { 71 + if(barrier->count >= barrier->trip_count) { 71 72 barrier->count = 0; 72 73 pthread_cond_broadcast(&barrier->cond); 73 74 pthread_mutex_unlock(&barrier->mutex); 74 75 return 1; 75 76 } 76 - else 77 - { 77 + else { 78 78 pthread_cond_wait(&barrier->cond, &(barrier->mutex)); 79 79 pthread_mutex_unlock(&barrier->mutex); 80 80 return 0; ··· 84 84 #endif 85 85 86 86 #define HIDAPI_THREAD_TIMED_OUT ETIMEDOUT 87 + 88 + typedef struct timespec hidapi_timespec; 87 89 88 90 typedef struct 89 91 { ··· 126 128 pthread_cond_wait(&state->condition, &state->mutex); 127 129 } 128 130 129 - static int hidapi_thread_cond_timedwait(hidapi_thread_state *state, struct timespec *ts) 131 + static int hidapi_thread_cond_timedwait(hidapi_thread_state *state, hidapi_timespec *ts) 130 132 { 131 133 return pthread_cond_timedwait(&state->condition, &state->mutex, ts); 132 134 } ··· 156 158 pthread_join(state->thread, NULL); 157 159 } 158 160 159 - static void hidapi_thread_gettime(struct timespec *ts) 161 + static void hidapi_thread_gettime(hidapi_timespec *ts) 160 162 { 161 163 clock_gettime(CLOCK_REALTIME, ts); 162 164 } 163 165 166 + static void hidapi_thread_addtime(hidapi_timespec *ts, int milliseconds) 167 + { 168 + ts->tv_sec += milliseconds / 1000; 169 + ts->tv_nsec += (milliseconds % 1000) * 1000000; 170 + if (ts->tv_nsec >= 1000000000L) { 171 + ts->tv_sec++; 172 + ts->tv_nsec -= 1000000000L; 173 + } 174 + }
+10 -10
src/hidapi/libusb/hidapi_thread_sdl.h
··· 76 76 77 77 #define HIDAPI_THREAD_TIMED_OUT SDL_MUTEX_TIMEDOUT 78 78 79 + typedef Uint64 hidapi_timespec; 80 + 79 81 typedef struct 80 82 { 81 83 SDL_Thread *thread; ··· 123 125 SDL_WaitCondition(state->condition, state->mutex); 124 126 } 125 127 126 - static int hidapi_thread_cond_timedwait(hidapi_thread_state *state, struct timespec *ts) 128 + static int hidapi_thread_cond_timedwait(hidapi_thread_state *state, hidapi_timespec *ts) 127 129 { 128 - Uint64 end_time; 129 130 Sint64 timeout_ns; 130 131 Sint32 timeout_ms; 131 132 132 - end_time = ts->tv_sec; 133 - end_time *= 1000000000L; 134 - end_time += ts->tv_nsec; 135 - timeout_ns = (Sint64)(end_time - SDL_GetTicksNS()); 133 + timeout_ns = (Sint64)(*ts - SDL_GetTicksNS()); 136 134 if (timeout_ns <= 0) { 137 135 timeout_ms = 0; 138 136 } else { ··· 189 187 SDL_WaitThread(state->thread, NULL); 190 188 } 191 189 192 - static void hidapi_thread_gettime(struct timespec *ts) 190 + static void hidapi_thread_gettime(hidapi_timespec *ts) 193 191 { 194 - Uint64 ns = SDL_GetTicksNS(); 192 + *ts = SDL_GetTicksNS(); 193 + } 195 194 196 - ts->tv_sec = ns / 1000000000L; 197 - ts->tv_nsec = ns % 1000000000L; 195 + static void hidapi_thread_addtime(hidapi_timespec *ts, int milliseconds) 196 + { 197 + *ts += SDL_MS_TO_NS(milliseconds); 198 198 }