Commit ae9bab43 by Marcus Winter

portability: changed all checks for platform specific defines to checks for…

portability: changed all checks for platform specific defines to checks for EMBB_* defines, fixed affinity implementation for FreeBSD
parent 172d4ed3
...@@ -78,6 +78,8 @@ endif() ...@@ -78,6 +78,8 @@ endif()
include(CheckIncludeFiles) # Includes module to perform checks include(CheckIncludeFiles) # Includes module to perform checks
include(CheckSymbolExists) # Includes module to perform symbol checks include(CheckSymbolExists) # Includes module to perform symbol checks
check_include_files("sys/sysinfo.h" EMBB_HAS_HEADER_SYSINFO) check_include_files("sys/sysinfo.h" EMBB_HAS_HEADER_SYSINFO)
check_include_files("sys/types.h;sys/sysctl.h" EMBB_HAS_HEADER_SYSCTL)
check_include_files("sys/param.h;sys/cpuset.h" EMBB_HAS_HEADER_CPUSET)
link_libraries(${link_libraries} ${gnu_libs}) link_libraries(${link_libraries} ${gnu_libs})
set(CMAKE_EXTRA_INCLUDE_FILES sched.h) set(CMAKE_EXTRA_INCLUDE_FILES sched.h)
check_type_size(cpu_set_t EMBB_HAS_GLIB_CPU) check_type_size(cpu_set_t EMBB_HAS_GLIB_CPU)
......
...@@ -39,6 +39,16 @@ ...@@ -39,6 +39,16 @@
#cmakedefine EMBB_HAS_HEADER_SYSINFO #cmakedefine EMBB_HAS_HEADER_SYSINFO
/** /**
* Is used to get the number of cores on certain systems.
*/
#cmakedefine EMBB_HAS_HEADER_SYSCTL
/**
* Is used to set thread affinities on certain systems.
*/
#cmakedefine EMBB_HAS_HEADER_CPUSET
/**
* Is used for Linux thread affinities. * Is used for Linux thread affinities.
*/ */
#cmakedefine EMBB_HAS_GLIB_CPU #cmakedefine EMBB_HAS_GLIB_CPU
......
...@@ -93,8 +93,7 @@ void embb_core_set_init(embb_core_set_t* core_set, int initializer) { ...@@ -93,8 +93,7 @@ void embb_core_set_init(embb_core_set_t* core_set, int initializer) {
#ifdef EMBB_HAS_HEADER_SYSINFO #ifdef EMBB_HAS_HEADER_SYSINFO
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#endif #elif defined EMBB_HAS_HEADER_SYSCTL
#ifdef __FreeBSD__
#include <sys/types.h> #include <sys/types.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif
...@@ -102,7 +101,7 @@ void embb_core_set_init(embb_core_set_t* core_set, int initializer) { ...@@ -102,7 +101,7 @@ void embb_core_set_init(embb_core_set_t* core_set, int initializer) {
unsigned int embb_core_count_available() { unsigned int embb_core_count_available() {
#ifdef EMBB_HAS_HEADER_SYSINFO #ifdef EMBB_HAS_HEADER_SYSINFO
return get_nprocs(); return get_nprocs();
#elif defined __FreeBSD__ #elif defined EMBB_HAS_HEADER_SYSCTL
const size_t kBufferSize = sizeof(unsigned int); const size_t kBufferSize = sizeof(unsigned int);
char buf[kBufferSize]; char buf[kBufferSize];
size_t len = kBufferSize; size_t len = kBufferSize;
......
...@@ -157,6 +157,10 @@ int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) { ...@@ -157,6 +157,10 @@ int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) {
#ifdef EMBB_HAS_GLIB_CPU #ifdef EMBB_HAS_GLIB_CPU
#include <sched.h> #include <sched.h>
#elif defined EMBB_HAS_HEADER_CPUSET
#include <pthread_np.h>
#include <sys/param.h>
#include <sys/cpuset.h>
#endif #endif
#ifdef EMBB_HAS_HEADER_SYSINFO #ifdef EMBB_HAS_HEADER_SYSINFO
...@@ -203,23 +207,26 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, ...@@ -203,23 +207,26 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
int status = pthread_attr_init(&attr); int status = pthread_attr_init(&attr);
if (status != 0) return EMBB_ERROR; if (status != 0) return EMBB_ERROR;
if (core_set != NULL) { if (core_set != NULL) {
#ifdef EMBB_HAS_GLIB_CPU #if defined(EMBB_HAS_GLIB_CPU) || defined(EMBB_HAS_HEADER_CPUSET)
assert(embb_core_count_available() < CPU_SETSIZE && assert(embb_core_count_available() < CPU_SETSIZE &&
"Core sets on Linux systems are only supported up to CPU_SETSIZE " "Core sets are only supported up to CPU_SETSIZE processors!");
"processors!"); #ifdef EMBB_HAS_GLIB_CPU
cpu_set_t cpuset; cpu_set_t cpuset;
#else
cpuset_t cpuset;
#endif
CPU_ZERO(&cpuset); /* Disable all processors */ CPU_ZERO(&cpuset); /* Disable all processors */
for (unsigned int i = 0; i < embb_core_count_available(); i++) { for (unsigned int i = 0; i < embb_core_count_available(); i++) {
if (embb_core_set_contains(core_set, i)) { if (embb_core_set_contains(core_set, i)) {
CPU_SET(i, &cpuset); CPU_SET(i, &cpuset);
} }
} }
status = pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset); status = pthread_attr_setaffinity_np(&attr, sizeof(cpuset), &cpuset);
if (status != 0) return EMBB_ERROR; if (status != 0) return EMBB_ERROR;
#else /* EMBB_HAS_GLIB_CPU */ #else
embb_log_write("base_c", EMBB_LOG_LEVEL_WARNING, "Could not set thread " embb_log_write("base_c", EMBB_LOG_LEVEL_WARNING, "Could not set thread "
"affinity, since no implementation available!\n"); "affinity, since no implementation available!\n");
#endif /* else EMBB_HAS_GLIB_CPU */ #endif
} }
/* Dynamic allocation of thread arguments. Freed on call of join. */ /* Dynamic allocation of thread arguments. Freed on call of join. */
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#ifndef EMBB_CONTAINERS_INTERNAL_LOCK_FREE_MPMC_QUEUE_INL_H_ #ifndef EMBB_CONTAINERS_INTERNAL_LOCK_FREE_MPMC_QUEUE_INL_H_
#define EMBB_CONTAINERS_INTERNAL_LOCK_FREE_MPMC_QUEUE_INL_H_ #define EMBB_CONTAINERS_INTERNAL_LOCK_FREE_MPMC_QUEUE_INL_H_
#include <embb/base/internal/config.h>
/* /*
* The following algorithm uses hazard pointers and a lock-free value pool for * The following algorithm uses hazard pointers and a lock-free value pool for
* memory management. For a description of the algorithm, see * memory management. For a description of the algorithm, see
...@@ -78,13 +80,13 @@ LockFreeMPMCQueue<Type, ValuePool>::LockFreeMPMCQueue(size_t capacity) : ...@@ -78,13 +80,13 @@ LockFreeMPMCQueue<Type, ValuePool>::LockFreeMPMCQueue(size_t capacity) :
capacity(capacity), capacity(capacity),
// Disable "this is used in base member initializer" warning. // Disable "this is used in base member initializer" warning.
// We explicitly want this. // We explicitly want this.
#ifdef _MSC_VER #ifdef EMBB_COMPILER_MSVC
#pragma warning(push) #pragma warning(push)
#pragma warning(disable:4355) #pragma warning(disable:4355)
#endif #endif
delete_pointer_callback(*this, delete_pointer_callback(*this,
&LockFreeMPMCQueue<Type>::DeletePointerCallback), &LockFreeMPMCQueue<Type>::DeletePointerCallback),
#ifdef _MSC_VER #ifdef EMBB_COMPILER_MSVC
#pragma warning(pop) #pragma warning(pop)
#endif #endif
hazardPointer(delete_pointer_callback, NULL, 2), hazardPointer(delete_pointer_callback, NULL, 2),
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#ifndef EMBB_CONTAINERS_INTERNAL_LOCK_FREE_STACK_INL_H_ #ifndef EMBB_CONTAINERS_INTERNAL_LOCK_FREE_STACK_INL_H_
#define EMBB_CONTAINERS_INTERNAL_LOCK_FREE_STACK_INL_H_ #define EMBB_CONTAINERS_INTERNAL_LOCK_FREE_STACK_INL_H_
#include <embb/base/internal/config.h>
/* /*
* The following algorithm uses hazard pointers and a lock-free value pool for * The following algorithm uses hazard pointers and a lock-free value pool for
* memory management. For a description of the algorithm, see * memory management. For a description of the algorithm, see
...@@ -70,13 +72,13 @@ LockFreeStack< Type, ValuePool >::LockFreeStack(size_t capacity) : ...@@ -70,13 +72,13 @@ LockFreeStack< Type, ValuePool >::LockFreeStack(size_t capacity) :
capacity(capacity), capacity(capacity),
// Disable "this is used in base member initializer" warning. // Disable "this is used in base member initializer" warning.
// We explicitly want this. // We explicitly want this.
#ifdef _MSC_VER #ifdef EMBB_COMPILER_MSVC
#pragma warning(push) #pragma warning(push)
#pragma warning(disable:4355) #pragma warning(disable:4355)
#endif #endif
delete_pointer_callback(*this, delete_pointer_callback(*this,
&LockFreeStack<Type>::DeletePointerCallback), &LockFreeStack<Type>::DeletePointerCallback),
#ifdef _MSC_VER #ifdef EMBB_COMPILER_MSVC
#pragma warning(pop) #pragma warning(pop)
#endif #endif
hazardPointer(delete_pointer_callback, NULL, 1), hazardPointer(delete_pointer_callback, NULL, 1),
......
...@@ -26,16 +26,18 @@ ...@@ -26,16 +26,18 @@
#include "./hazard_pointer_test.h" #include "./hazard_pointer_test.h"
#include <embb/base/internal/config.h>
namespace embb { namespace embb {
namespace containers { namespace containers {
namespace test { namespace test {
HazardPointerTest::HazardPointerTest() : HazardPointerTest::HazardPointerTest() :
#ifdef _MSC_VER #ifdef EMBB_COMPILER_MSVC
#pragma warning(push) #pragma warning(push)
#pragma warning(disable:4355) #pragma warning(disable:4355)
#endif #endif
delete_pointer_callback(*this, &HazardPointerTest::DeletePointerCallback), delete_pointer_callback(*this, &HazardPointerTest::DeletePointerCallback),
#ifdef _MSC_VER #ifdef EMBB_COMPILER_MSVC
#pragma warning(pop) #pragma warning(pop)
#endif #endif
object_pool(NULL), object_pool(NULL),
......
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include <embb/base/internal/config.h>
namespace embb { namespace embb {
namespace containers { namespace containers {
namespace test { namespace test {
...@@ -54,13 +56,13 @@ n_threads(static_cast<int> ...@@ -54,13 +56,13 @@ n_threads(static_cast<int>
TOTAL_PRODUCE_CONSUME_COUNT). TOTAL_PRODUCE_CONSUME_COUNT).
Post(&QueueTest::QueueTestSingleProducedSingleConsumer_Post, this); Post(&QueueTest::QueueTestSingleProducedSingleConsumer_Post, this);
#ifdef _MSC_VER #ifdef EMBB_COMPILER_MSVC
#pragma warning(push) #pragma warning(push)
#pragma warning(disable:4127) #pragma warning(disable:4127)
#endif #endif
if (MultipleProducers == true && if (MultipleProducers == true &&
MultipleConsumers == true) { MultipleConsumers == true) {
#ifdef _MSC_VER #ifdef EMBB_COMPILER_MSVC
#pragma warning(pop) #pragma warning(pop)
#endif #endif
CreateUnit("QueueTestMultipleThreadsMultipleProducerMultipleConsumer"). CreateUnit("QueueTestMultipleThreadsMultipleProducerMultipleConsumer").
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment