diff options
| author | Sergey Polovko <[email protected]> | 2022-02-10 16:47:03 +0300 |
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:47:03 +0300 |
| commit | 2e714b5ebd40a1f4cc31c27f1ad6e49ca6d895f5 (patch) | |
| tree | b83306b6e37edeea782e9eed673d89286c4fef35 /contrib/libs/hdr_histogram/src/hdr_thread.c | |
| parent | 3e0b762a82514bac89c1dd6ea7211e381d8aa248 (diff) | |
Restoring authorship annotation for Sergey Polovko <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/hdr_histogram/src/hdr_thread.c')
| -rw-r--r-- | contrib/libs/hdr_histogram/src/hdr_thread.c | 204 |
1 files changed, 102 insertions, 102 deletions
diff --git a/contrib/libs/hdr_histogram/src/hdr_thread.c b/contrib/libs/hdr_histogram/src/hdr_thread.c index a38e64f2ad3..721780edb9e 100644 --- a/contrib/libs/hdr_histogram/src/hdr_thread.c +++ b/contrib/libs/hdr_histogram/src/hdr_thread.c @@ -1,102 +1,102 @@ -/** -* hdr_thread.c -* Written by Philip Orwig and released to the public domain, -* as explained at http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -#include <stdlib.h> -#include "hdr_thread.h" - -struct hdr_mutex* hdr_mutex_alloc(void) -{ - return malloc(sizeof(hdr_mutex)); -} - -void hdr_mutex_free(struct hdr_mutex* mutex) -{ - free(mutex); -} - -#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) - -#if !defined(WIN32_LEAN_AND_MEAN) -#define WIN32_LEAN_AND_MEAN -#endif - -#include <windows.h> -#include <WinSock2.h> - -int hdr_mutex_init(struct hdr_mutex* mutex) -{ - InitializeCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section)); - return 0; -} - -void hdr_mutex_destroy(struct hdr_mutex* mutex) -{ - DeleteCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section)); -} - -void hdr_mutex_lock(struct hdr_mutex* mutex) -{ - EnterCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section)); -} - -void hdr_mutex_unlock(struct hdr_mutex* mutex) -{ - LeaveCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section)); -} - -void hdr_yield() -{ - Sleep(0); -} - -int hdr_usleep(unsigned int useconds) -{ - struct timeval tv; - - tv.tv_sec = (long)useconds / 1000000; - tv.tv_usec = useconds % 1000000; - select(0, NULL, NULL, NULL, &tv); - - return 0; -} - - -#else -#include <pthread.h> -#include <unistd.h> - -int hdr_mutex_init(struct hdr_mutex* mutex) -{ - return pthread_mutex_init(&mutex->_mutex, NULL); -} - -void hdr_mutex_destroy(struct hdr_mutex* mutex) -{ - pthread_mutex_destroy(&mutex->_mutex); -} - -void hdr_mutex_lock(struct hdr_mutex* mutex) -{ - pthread_mutex_lock(&mutex->_mutex); -} - -void hdr_mutex_unlock(struct hdr_mutex* mutex) -{ - pthread_mutex_unlock(&mutex->_mutex); -} - -void hdr_yield() -{ - sched_yield(); -} - -int hdr_usleep(unsigned int useconds) -{ - return usleep(useconds); -} - - -#endif +/** +* hdr_thread.c +* Written by Philip Orwig and released to the public domain, +* as explained at http://creativecommons.org/publicdomain/zero/1.0/ +*/ + +#include <stdlib.h> +#include "hdr_thread.h" + +struct hdr_mutex* hdr_mutex_alloc(void) +{ + return malloc(sizeof(hdr_mutex)); +} + +void hdr_mutex_free(struct hdr_mutex* mutex) +{ + free(mutex); +} + +#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) + +#if !defined(WIN32_LEAN_AND_MEAN) +#define WIN32_LEAN_AND_MEAN +#endif + +#include <windows.h> +#include <WinSock2.h> + +int hdr_mutex_init(struct hdr_mutex* mutex) +{ + InitializeCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section)); + return 0; +} + +void hdr_mutex_destroy(struct hdr_mutex* mutex) +{ + DeleteCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section)); +} + +void hdr_mutex_lock(struct hdr_mutex* mutex) +{ + EnterCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section)); +} + +void hdr_mutex_unlock(struct hdr_mutex* mutex) +{ + LeaveCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section)); +} + +void hdr_yield() +{ + Sleep(0); +} + +int hdr_usleep(unsigned int useconds) +{ + struct timeval tv; + + tv.tv_sec = (long)useconds / 1000000; + tv.tv_usec = useconds % 1000000; + select(0, NULL, NULL, NULL, &tv); + + return 0; +} + + +#else +#include <pthread.h> +#include <unistd.h> + +int hdr_mutex_init(struct hdr_mutex* mutex) +{ + return pthread_mutex_init(&mutex->_mutex, NULL); +} + +void hdr_mutex_destroy(struct hdr_mutex* mutex) +{ + pthread_mutex_destroy(&mutex->_mutex); +} + +void hdr_mutex_lock(struct hdr_mutex* mutex) +{ + pthread_mutex_lock(&mutex->_mutex); +} + +void hdr_mutex_unlock(struct hdr_mutex* mutex) +{ + pthread_mutex_unlock(&mutex->_mutex); +} + +void hdr_yield() +{ + sched_yield(); +} + +int hdr_usleep(unsigned int useconds) +{ + return usleep(useconds); +} + + +#endif |
