summaryrefslogtreecommitdiff
path: root/lib/avtp_pipeline/platform/Linux/openavb_os_services_osal.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/avtp_pipeline/platform/Linux/openavb_os_services_osal.h')
-rw-r--r--lib/avtp_pipeline/platform/Linux/openavb_os_services_osal.h35
1 files changed, 32 insertions, 3 deletions
diff --git a/lib/avtp_pipeline/platform/Linux/openavb_os_services_osal.h b/lib/avtp_pipeline/platform/Linux/openavb_os_services_osal.h
index e3833f0d..a0d399d0 100644
--- a/lib/avtp_pipeline/platform/Linux/openavb_os_services_osal.h
+++ b/lib/avtp_pipeline/platform/Linux/openavb_os_services_osal.h
@@ -1,5 +1,6 @@
/*************************************************************************************************************
Copyright (c) 2012-2015, Symphony Teleca Corporation, a Harman International Industries, Incorporated company
+Copyright (c) 2016-2017, Harman International Industries, Incorporated
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -64,7 +65,7 @@ https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175.
#define SLEEP(sec) sleep(sec)
#define SLEEP_MSEC(mSec) usleep(mSec * 1000)
-#define SLEEP_NSEC(nSec) usleep(nSec)
+#define SLEEP_NSEC(nSec) usleep(nSec / 1000)
#define SLEEP_UNTIL_NSEC(nSec) xSleepUntilNSec(nSec)
inline static void xSleepUntilNSec(U64 nSec)
{
@@ -74,7 +75,17 @@ inline static void xSleepUntilNSec(U64 nSec)
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &tmpTime, NULL);
}
-
+#define SPIN_UNTIL_NSEC(nsec) xSpinUntilNSec(nsec)
+inline static void xSpinUntilNSec(U64 nSec)
+{
+ do {
+ U64 spinNowNS;
+ CLOCK_GETTIME64(OPENAVB_CLOCK_WALLTIME, &spinNowNS);
+ if (spinNowNS > nSec)
+ break;
+ }
+ while (1);
+}
#define RAND() random()
#define SRAND(seed) srandom(seed)
@@ -119,6 +130,24 @@ thread##_type thread##_ThreadData
pthread_attr_destroy(&thread_attr); \
}
+#define THREAD_SET_RT_PRIORITY(threadhandle, priority) \
+ { \
+ struct sched_param param; \
+ param.__sched_priority = priority; \
+ pthread_setschedparam(threadhandle##_ThreadData.pthread, SCHED_RR, &param); \
+ }
+
+#define THREAD_PIN(threadhandle, affinity) \
+ { \
+ cpu_set_t cpuset; \
+ int i1; \
+ CPU_ZERO(&cpuset); \
+ for (i1 = 0; i1 < 32; i1++) { \
+ if (affinity & (1 << i1)) CPU_SET(i1, &cpuset); \
+ } \
+ pthread_setaffinity_np(threadhandle##_ThreadData.pthread, sizeof(cpu_set_t), &cpuset); \
+ }
+
#define THREAD_CHECK_ERROR(threadhandle, message, error) \
do { \
error=FALSE; \
@@ -151,7 +180,7 @@ thread##_type thread##_ThreadData
#define SEM_POST(sem, err) err = sem_post(&sem);
#define SEM_DESTROY(sem, err) err = sem_destroy(&sem);
#define SEM_IS_ERR_NONE(err) (0 == err)
-#define SEM_IS_ERR_TIMEOUT(err) (ETIMEDOUT == err)
+#define SEM_IS_ERR_TIMEOUT(err) (ETIMEDOUT == err || ((-1 == err) && (ETIMEDOUT == errno)))
#define SEM_LOG_ERR(err) if (0 != err) AVB_LOGF_ERROR("Semaphore error code: %d", err);