From ad76208472ce9a2875729be62b96612983292856 Mon Sep 17 00:00:00 2001 From: Marcus Winter Date: Thu, 7 Jul 2016 13:27:00 +0200 Subject: [PATCH] added missing signatures and documentation for thread priorities --- base_c/include/embb/base/c/thread.h | 3 +++ base_c/src/thread.c | 6 ------ base_cpp/include/embb/base/internal/thread-inl.h | 17 ++++++++++++++++- base_cpp/include/embb/base/thread.h | 27 ++++++++++++++++++++++++++- mtapi_c/include/embb/mtapi/c/mtapi.h | 18 ++++++++++++++++-- mtapi_cpp/include/embb/mtapi/node_attributes.h | 17 +++++++++++++++++ 6 files changed, 78 insertions(+), 10 deletions(-) diff --git a/base_c/include/embb/base/c/thread.h b/base_c/include/embb/base/c/thread.h index e33c128..7641871 100644 --- a/base_c/include/embb/base/c/thread.h +++ b/base_c/include/embb/base/c/thread.h @@ -56,6 +56,9 @@ extern "C" { typedef opaque_type embb_thread_t; #endif /* DOXYGEN */ +/** + * Thread priority type. + */ typedef enum { EMBB_THREAD_PRIORITY_IDLE, EMBB_THREAD_PRIORITY_LOWEST, diff --git a/base_c/src/thread.c b/base_c/src/thread.c index 14c146d..a3b88ec 100644 --- a/base_c/src/thread.c +++ b/base_c/src/thread.c @@ -207,12 +207,6 @@ int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) { return 0; } -int embb_thread_set_priority( - embb_thread_t* thread, - embb_thread_priority_t priority -) { -} - #endif /* EMBB_PLATFORM_THREADING_WINTHREADS */ #ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS diff --git a/base_cpp/include/embb/base/internal/thread-inl.h b/base_cpp/include/embb/base/internal/thread-inl.h index 8c856f0..80874ac 100644 --- a/base_cpp/include/embb/base/internal/thread-inl.h +++ b/base_cpp/include/embb/base/internal/thread-inl.h @@ -28,7 +28,6 @@ #define EMBB_BASE_INTERNAL_THREAD_INL_H_ #include -#include #include #include #include @@ -60,6 +59,22 @@ Thread::Thread(CoreSet& core_set, Function function) : rep_() { CheckThreadCreationErrors(result, closure); } +template +Thread::Thread( + CoreSet& core_set, + embb_thread_priority_t priority, + Function function) : rep_() { + typedef internal::ThreadClosure Closure; + Closure* closure = Allocation::New(function); + int result = embb_thread_create_with_priority( + &rep_, + &core_set.rep_, + priority, + internal::ThreadClosure::ThreadStart, + static_cast(closure)); + CheckThreadCreationErrors(result, closure); +} + template Thread::Thread(Function function, Arg1 arg1) : rep_() { typedef internal::ThreadClosureArg1 Closure; diff --git a/base_cpp/include/embb/base/thread.h b/base_cpp/include/embb/base/thread.h index 10fe983..25180cc 100644 --- a/base_cpp/include/embb/base/thread.h +++ b/base_cpp/include/embb/base/thread.h @@ -31,6 +31,7 @@ #include #include #include +#include #include namespace embb { @@ -177,9 +178,33 @@ class Thread { * \tparam Function Function object type */ template - explicit Thread( + Thread( + CoreSet& core_set, + /**< [IN] Set of cores on which the thread shall be executed. */ + Function function + /**< [IN] Copyable function object, callable without arguments */ + ); + + /** + * Creates and runs a thread with zero-argument start function. + * + * \note If the function is passed as a temporary object when creating a + * thread, this might be interpreted as a function declaration ("most vexing + * parse"). C++11 resolves this by using curly braces for initialization. + * + * \throws NoMemoryException if not enough memory is available + * \throws ErrorException in case of another error + * \memory A small constant amount of memory to store the function. This + * memory is freed the thread is joined. + * \notthreadsafe + * \tparam Function Function object type + */ + template + Thread( CoreSet& core_set, /**< [IN] Set of cores on which the thread shall be executed. */ + embb_thread_priority_t priority, + /**< [IN] Priority of the new thread. */ Function function /**< [IN] Copyable function object, callable without arguments */ ); diff --git a/mtapi_c/include/embb/mtapi/c/mtapi.h b/mtapi_c/include/embb/mtapi/c/mtapi.h index 896d480..3e27488 100644 --- a/mtapi_c/include/embb/mtapi/c/mtapi.h +++ b/mtapi_c/include/embb/mtapi/c/mtapi.h @@ -530,6 +530,9 @@ enum mtapi_notification_enum { typedef enum mtapi_notification_enum mtapi_notification_t; /**< runtime notification */ +/** + * Enum to select default or specific worker for priority setter + */ enum mtapi_worker_priority_type_enum { MTAPI_WORKER_PRIORITY_END = 0, MTAPI_WORKER_PRIORITY_DEFAULT = 1, @@ -599,12 +602,23 @@ enum mtapi_worker_priority_type_enum { MTAPI_WORKER_PRIORITY_WORKER_62 = MTAPI_WORKER_PRIORITY_WORKER + 62, MTAPI_WORKER_PRIORITY_WORKER_63 = MTAPI_WORKER_PRIORITY_WORKER + 63 }; +/** + * Enum to select default or specific worker for priority setter + */ typedef enum mtapi_worker_priority_type_enum mtapi_worker_priority_type_t; +/** + * Describes the default priority of all workers or the priority of a + * specific worker. + */ struct mtapi_worker_priority_entry_struct { - mtapi_worker_priority_type_t type; - embb_thread_priority_t priority; + mtapi_worker_priority_type_t type; /**< default or specific worker */ + embb_thread_priority_t priority; /**< priority to set */ }; +/** +* Describes the default priority of all workers or the priority of a +* specific worker. +*/ typedef struct mtapi_worker_priority_entry_struct mtapi_worker_priority_entry_t; /** diff --git a/mtapi_cpp/include/embb/mtapi/node_attributes.h b/mtapi_cpp/include/embb/mtapi/node_attributes.h index ae03fa7..9c6c0ab 100644 --- a/mtapi_cpp/include/embb/mtapi/node_attributes.h +++ b/mtapi_cpp/include/embb/mtapi/node_attributes.h @@ -87,6 +87,23 @@ class NodeAttributes { } /** + * Sets the priority of the specified worker threads. + * + * \returns Reference to this object. + * \notthreadsafe + */ + NodeAttributes & SetWorkerPriority( + mtapi_worker_priority_entry_t * worker_priorities + /**< Array of priorities */ + ) { + mtapi_status_t status; + mtapi_nodeattr_set(&attributes_, MTAPI_NODE_WORKER_PRIORITIES, + worker_priorities, MTAPI_NODE_WORKER_PRIORITIES_SIZE, &status); + internal::CheckStatus(status); + return *this; + } + + /** * Sets the maximum number of concurrently active tasks. * * \returns Reference to this object. -- libgit2 0.26.0