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()
include(CheckIncludeFiles) # Includes module to perform checks
include(CheckSymbolExists) # Includes module to perform symbol checks
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})
set(CMAKE_EXTRA_INCLUDE_FILES sched.h)
check_type_size(cpu_set_t EMBB_HAS_GLIB_CPU)
......
......@@ -39,6 +39,16 @@
#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.
*/
#cmakedefine EMBB_HAS_GLIB_CPU
......
......@@ -93,8 +93,7 @@ void embb_core_set_init(embb_core_set_t* core_set, int initializer) {
#ifdef EMBB_HAS_HEADER_SYSINFO
#include <sys/sysinfo.h>
#endif
#ifdef __FreeBSD__
#elif defined EMBB_HAS_HEADER_SYSCTL
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
......@@ -102,7 +101,7 @@ void embb_core_set_init(embb_core_set_t* core_set, int initializer) {
unsigned int embb_core_count_available() {
#ifdef EMBB_HAS_HEADER_SYSINFO
return get_nprocs();
#elif defined __FreeBSD__
#elif defined EMBB_HAS_HEADER_SYSCTL
const size_t kBufferSize = sizeof(unsigned int);
char buf[kBufferSize];
size_t len = kBufferSize;
......
......@@ -157,6 +157,10 @@ int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) {
#ifdef EMBB_HAS_GLIB_CPU
#include <sched.h>
#elif defined EMBB_HAS_HEADER_CPUSET
#include <pthread_np.h>
#include <sys/param.h>
#include <sys/cpuset.h>
#endif
#ifdef EMBB_HAS_HEADER_SYSINFO
......@@ -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);
if (status != 0) return EMBB_ERROR;
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 &&
"Core sets on Linux systems are only supported up to CPU_SETSIZE "
"processors!");
"Core sets are only supported up to CPU_SETSIZE processors!");
#ifdef EMBB_HAS_GLIB_CPU
cpu_set_t cpuset;
#else
cpuset_t cpuset;
#endif
CPU_ZERO(&cpuset); /* Disable all processors */
for (unsigned int i = 0; i < embb_core_count_available(); i++) {
if (embb_core_set_contains(core_set, i)) {
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;
#else /* EMBB_HAS_GLIB_CPU */
#else
embb_log_write("base_c", EMBB_LOG_LEVEL_WARNING, "Could not set thread "
"affinity, since no implementation available!\n");
#endif /* else EMBB_HAS_GLIB_CPU */
#endif
}
/* Dynamic allocation of thread arguments. Freed on call of join. */
......
......@@ -27,6 +27,8 @@
#ifndef 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
* memory management. For a description of the algorithm, see
......@@ -78,13 +80,13 @@ LockFreeMPMCQueue<Type, ValuePool>::LockFreeMPMCQueue(size_t capacity) :
capacity(capacity),
// Disable "this is used in base member initializer" warning.
// We explicitly want this.
#ifdef _MSC_VER
#ifdef EMBB_COMPILER_MSVC
#pragma warning(push)
#pragma warning(disable:4355)
#endif
delete_pointer_callback(*this,
&LockFreeMPMCQueue<Type>::DeletePointerCallback),
#ifdef _MSC_VER
#ifdef EMBB_COMPILER_MSVC
#pragma warning(pop)
#endif
hazardPointer(delete_pointer_callback, NULL, 2),
......
......@@ -27,6 +27,8 @@
#ifndef 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
* memory management. For a description of the algorithm, see
......@@ -70,13 +72,13 @@ LockFreeStack< Type, ValuePool >::LockFreeStack(size_t capacity) :
capacity(capacity),
// Disable "this is used in base member initializer" warning.
// We explicitly want this.
#ifdef _MSC_VER
#ifdef EMBB_COMPILER_MSVC
#pragma warning(push)
#pragma warning(disable:4355)
#endif
delete_pointer_callback(*this,
&LockFreeStack<Type>::DeletePointerCallback),
#ifdef _MSC_VER
#ifdef EMBB_COMPILER_MSVC
#pragma warning(pop)
#endif
hazardPointer(delete_pointer_callback, NULL, 1),
......
......@@ -26,16 +26,18 @@
#include "./hazard_pointer_test.h"
#include <embb/base/internal/config.h>
namespace embb {
namespace containers {
namespace test {
HazardPointerTest::HazardPointerTest() :
#ifdef _MSC_VER
#ifdef EMBB_COMPILER_MSVC
#pragma warning(push)
#pragma warning(disable:4355)
#endif
delete_pointer_callback(*this, &HazardPointerTest::DeletePointerCallback),
#ifdef _MSC_VER
#ifdef EMBB_COMPILER_MSVC
#pragma warning(pop)
#endif
object_pool(NULL),
......
......@@ -30,6 +30,8 @@
#include <algorithm>
#include <vector>
#include <embb/base/internal/config.h>
namespace embb {
namespace containers {
namespace test {
......@@ -54,13 +56,13 @@ n_threads(static_cast<int>
TOTAL_PRODUCE_CONSUME_COUNT).
Post(&QueueTest::QueueTestSingleProducedSingleConsumer_Post, this);
#ifdef _MSC_VER
#ifdef EMBB_COMPILER_MSVC
#pragma warning(push)
#pragma warning(disable:4127)
#endif
if (MultipleProducers == true &&
MultipleConsumers == true) {
#ifdef _MSC_VER
#ifdef EMBB_COMPILER_MSVC
#pragma warning(pop)
#endif
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