X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fperformance-thread%2Fpthread_shim%2Fpthread_shim.c;h=113bafa00b6974fdcd14354b635597b64cbb295a;hb=dce8a093de6b70219287be3e4ed59628d19770fe;hp=30cd68a566e3b6adae9cb1249d8b26a060ca7770;hpb=433ba6228f9a77a9b5f4561258930a46d096b3c4;p=dpdk.git diff --git a/examples/performance-thread/pthread_shim/pthread_shim.c b/examples/performance-thread/pthread_shim/pthread_shim.c index 30cd68a566..113bafa00b 100644 --- a/examples/performance-thread/pthread_shim/pthread_shim.c +++ b/examples/performance-thread/pthread_shim/pthread_shim.c @@ -39,7 +39,6 @@ #include #include -#include #include #include "lthread_api.h" @@ -49,6 +48,21 @@ #define POSIX_ERRNO(x) (x) +/* some releases of FreeBSD 10, e.g. 10.0, don't have CPU_COUNT macro */ +#ifndef CPU_COUNT +#define CPU_COUNT(x) __cpu_count(x) + +static inline unsigned int +__cpu_count(const rte_cpuset_t *cpuset) +{ + unsigned int i, count = 0; + for (i = 0; i < RTE_MAX_LCORE; i++) + if (CPU_ISSET(i, cpuset)) + count++; + return count; +} +#endif + /* * this flag determines at run time if we override pthread * calls and map then to equivalent lthread calls @@ -160,7 +174,7 @@ int (*f_pthread_setschedparam) int (*f_pthread_yield) (void); int (*f_pthread_setaffinity_np) - (pthread_t thread, size_t cpusetsize, const cpu_set_t *cpuset); + (pthread_t thread, size_t cpusetsize, const rte_cpuset_t *cpuset); int (*f_nanosleep) (const struct timespec *req, struct timespec *rem); } _sys_pthread_funcs = { @@ -327,17 +341,24 @@ int pthread_cond_broadcast(pthread_cond_t *cond) return _sys_pthread_funcs.f_pthread_cond_broadcast(cond); } +int pthread_mutex_destroy(pthread_mutex_t *mutex) +{ + if (override) + return lthread_mutex_destroy(*(struct lthread_mutex **)mutex); + return _sys_pthread_funcs.f_pthread_mutex_destroy(mutex); +} + int pthread_cond_destroy(pthread_cond_t *cond) { if (override) - return -lthread_cond_destroy(*(struct lthread_cond **)cond); + return lthread_cond_destroy(*(struct lthread_cond **)cond); return _sys_pthread_funcs.f_pthread_cond_destroy(cond); } int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) { if (override) - return -lthread_cond_init(NULL, + return lthread_cond_init(NULL, (struct lthread_cond **)cond, (const struct lthread_condattr *) attr); return _sys_pthread_funcs.f_pthread_cond_init(cond, attr); @@ -384,11 +405,11 @@ pthread_create(pthread_t *__restrict tid, if (attr != NULL) { /* determine CPU being requested */ - cpu_set_t cpuset; + rte_cpuset_t cpuset; CPU_ZERO(&cpuset); pthread_attr_getaffinity_np(attr, - sizeof(cpu_set_t), + sizeof(rte_cpuset_t), &cpuset); if (CPU_COUNT(&cpuset) != 1) @@ -411,9 +432,10 @@ int pthread_detach(pthread_t tid) if (override) { struct lthread *lt = (struct lthread *)tid; - if (lt == lthread_current()) + if (lt == lthread_current()) { lthread_detach(); return 0; + } NOT_IMPLEMENTED; } return _sys_pthread_funcs.f_pthread_detach(tid); @@ -569,15 +591,26 @@ int pthread_rwlock_wrlock(pthread_rwlock_t *a) return _sys_pthread_funcs.f_pthread_rwlock_wrlock(a); } -int pthread_yield(void) +#ifdef RTE_EXEC_ENV_LINUXAPP +int +pthread_yield(void) { if (override) { lthread_yield(); return 0; } return _sys_pthread_funcs.f_pthread_yield(); - } +#else +void +pthread_yield(void) +{ + if (override) + lthread_yield(); + else + _sys_pthread_funcs.f_pthread_yield(); +} +#endif pthread_t pthread_self(void) { @@ -679,7 +712,7 @@ int nanosleep(const struct timespec *req, struct timespec *rem) int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, - const cpu_set_t *cpuset) + const rte_cpuset_t *cpuset) { if (override) { /* we only allow affinity with a single CPU */