Commit ad762084 by Marcus Winter

added missing signatures and documentation for thread priorities

parent d6cf14ea
......@@ -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,
......
......@@ -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
......
......@@ -28,7 +28,6 @@
#define EMBB_BASE_INTERNAL_THREAD_INL_H_
#include <embb/base/exceptions.h>
#include <embb/base/c/thread.h>
#include <embb/base/internal/thread_closures.h>
#include <embb/base/memory_allocation.h>
#include <iostream>
......@@ -60,6 +59,22 @@ Thread::Thread(CoreSet& core_set, Function function) : rep_() {
CheckThreadCreationErrors(result, closure);
}
template<typename Function>
Thread::Thread(
CoreSet& core_set,
embb_thread_priority_t priority,
Function function) : rep_() {
typedef internal::ThreadClosure<Function> Closure;
Closure* closure = Allocation::New<Closure>(function);
int result = embb_thread_create_with_priority(
&rep_,
&core_set.rep_,
priority,
internal::ThreadClosure<Function>::ThreadStart,
static_cast<void*>(closure));
CheckThreadCreationErrors(result, closure);
}
template<typename Function, typename Arg1>
Thread::Thread(Function function, Arg1 arg1) : rep_() {
typedef internal::ThreadClosureArg1<Function, Arg1> Closure;
......
......@@ -31,6 +31,7 @@
#include <embb/base/internal/thread_closures.h>
#include <embb/base/mutex.h>
#include <embb/base/core_set.h>
#include <embb/base/c/thread.h>
#include <ostream>
namespace embb {
......@@ -177,9 +178,33 @@ class Thread {
* \tparam Function Function object type
*/
template<typename Function>
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<typename Function>
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 */
);
......
......@@ -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;
/**
......
......@@ -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.
......
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