aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-10 21:09:54 -0800
committerChris Robinson <[email protected]>2018-11-10 21:09:54 -0800
commitf3ce7bc7dcf20275d93974755c42486d812d771f (patch)
treee18bb582b09b658ee6e955e8994a2fddf42fa6d4 /common
parent2f42f74418f079e2ef8f081a7faf915c5eb131b4 (diff)
Move altimespec_get and al_nssleep to examples' common code
Diffstat (limited to 'common')
-rw-r--r--common/threads.c72
-rw-r--r--common/threads.h26
2 files changed, 0 insertions, 98 deletions
diff --git a/common/threads.c b/common/threads.c
index e8301297..de9fc452 100644
--- a/common/threads.c
+++ b/common/threads.c
@@ -174,21 +174,6 @@ int althrd_join(althrd_t thr, int *res)
return althrd_success;
}
-int althrd_sleep(const struct timespec *ts, struct timespec* UNUSED(rem))
-{
- DWORD msec;
-
- if(ts->tv_sec < 0 || ts->tv_sec >= (0x7fffffff / 1000) ||
- ts->tv_nsec < 0 || ts->tv_nsec >= 1000000000)
- return -2;
-
- msec = (DWORD)(ts->tv_sec * 1000);
- msec += (DWORD)((ts->tv_nsec+999999) / 1000000);
- Sleep(msec);
-
- return 0;
-}
-
int almtx_init(almtx_t *mtx, int type)
{
@@ -381,27 +366,6 @@ void altss_delete(altss_t tss_id)
}
-int altimespec_get(struct timespec *ts, int base)
-{
- static_assert(sizeof(FILETIME) == sizeof(ULARGE_INTEGER),
- "Size of FILETIME does not match ULARGE_INTEGER");
- if(base == AL_TIME_UTC)
- {
- union {
- FILETIME ftime;
- ULARGE_INTEGER ulint;
- } systime;
- GetSystemTimeAsFileTime(&systime.ftime);
- /* FILETIME is in 100-nanosecond units, or 1/10th of a microsecond. */
- ts->tv_sec = systime.ulint.QuadPart/10000000;
- ts->tv_nsec = (systime.ulint.QuadPart%10000000) * 100;
- return base;
- }
-
- return 0;
-}
-
-
void alcall_once(alonce_flag *once, void (*callback)(void))
{
LONG ret;
@@ -447,7 +411,6 @@ void althrd_thread_detach(void)
#endif
-extern inline int althrd_sleep(const struct timespec *ts, struct timespec *rem);
extern inline void alcall_once(alonce_flag *once, void (*callback)(void));
extern inline void althrd_deinit(void);
@@ -713,39 +676,4 @@ void altss_delete(altss_t tss_id)
pthread_key_delete(tss_id);
}
-
-int altimespec_get(struct timespec *ts, int base)
-{
- if(base == AL_TIME_UTC)
- {
- int ret;
-#if _POSIX_TIMERS > 0
- ret = clock_gettime(CLOCK_REALTIME, ts);
- if(ret == 0) return base;
-#else /* _POSIX_TIMERS > 0 */
- struct timeval tv;
- ret = gettimeofday(&tv, NULL);
- if(ret == 0)
- {
- ts->tv_sec = tv.tv_sec;
- ts->tv_nsec = tv.tv_usec * 1000;
- return base;
- }
-#endif
- }
-
- return 0;
-}
-
#endif
-
-
-void al_nssleep(unsigned long nsec)
-{
- struct timespec ts, rem;
- ts.tv_sec = nsec / 1000000000ul;
- ts.tv_nsec = nsec % 1000000000ul;
-
- while(althrd_sleep(&ts, &rem) == -1)
- ts = rem;
-}
diff --git a/common/threads.h b/common/threads.h
index 7fbe20cd..c2168cdf 100644
--- a/common/threads.h
+++ b/common/threads.h
@@ -34,21 +34,11 @@ typedef int (*althrd_start_t)(void*);
typedef void (*altss_dtor_t)(void*);
-#define AL_TIME_UTC 1
-
-
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-#ifndef HAVE_STRUCT_TIMESPEC
-struct timespec {
- time_t tv_sec;
- long tv_nsec;
-};
-#endif
-
typedef DWORD althrd_t;
typedef CRITICAL_SECTION almtx_t;
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600
@@ -62,7 +52,6 @@ typedef LONG alonce_flag;
#define AL_ONCE_FLAG_INIT 0
-int althrd_sleep(const struct timespec *ts, struct timespec *rem);
void alcall_once(alonce_flag *once, void (*callback)(void));
void althrd_deinit(void);
@@ -171,17 +160,6 @@ inline void althrd_yield(void)
sched_yield();
}
-inline int althrd_sleep(const struct timespec *ts, struct timespec *rem)
-{
- int ret = nanosleep(ts, rem);
- if(ret != 0)
- {
- ret = ((errno==EINTR) ? -1 : -2);
- errno = 0;
- }
- return ret;
-}
-
inline int almtx_lock(almtx_t *mtx)
{
@@ -257,10 +235,6 @@ int alsem_trywait(alsem_t *sem);
int altss_create(altss_t *tss_id, altss_dtor_t callback);
void altss_delete(altss_t tss_id);
-int altimespec_get(struct timespec *ts, int base);
-
-void al_nssleep(unsigned long nsec);
-
#ifdef __cplusplus
} // extern "C"