Embedded Multicore Building Blocks V1.0.0
node_attributes.h
1 /*
2  * Copyright (c) 2014-2017, Siemens AG. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  * POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef EMBB_MTAPI_NODE_ATTRIBUTES_H_
28 #define EMBB_MTAPI_NODE_ATTRIBUTES_H_
29 
30 #include <embb/mtapi/c/mtapi.h>
31 #include <embb/base/core_set.h>
32 #include <embb/mtapi/internal/check_status.h>
33 
34 namespace embb {
35 namespace mtapi {
36 
43  public:
49  mtapi_status_t status;
50  mtapi_nodeattr_init(&attributes_, &status);
51  internal::CheckStatus(status);
52  }
53 
59  NodeAttributes const & other
60  )
61  : attributes_(other.attributes_) {
62  // empty
63  }
64 
69  void operator=(
70  NodeAttributes const & other
71  ) {
72  attributes_ = other.attributes_;
73  }
74 
83  embb::base::CoreSet const & cores
84  ) {
85  mtapi_status_t status;
86  mtapi_nodeattr_set(&attributes_, MTAPI_NODE_CORE_AFFINITY,
87  &cores.GetInternal(), sizeof(embb_core_set_t), &status);
88  internal::CheckStatus(status);
89  return *this;
90  }
91 
99  mtapi_worker_priority_entry_t * worker_priorities
101  ) {
102  mtapi_status_t status;
103  mtapi_nodeattr_set(&attributes_, MTAPI_NODE_WORKER_PRIORITIES,
104  worker_priorities, MTAPI_NODE_WORKER_PRIORITIES_SIZE, &status);
105  internal::CheckStatus(status);
106  return *this;
107  }
108 
116  mtapi_uint_t value
117  ) {
118  mtapi_status_t status;
119  mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_TASKS,
120  &value, sizeof(value), &status);
121  internal::CheckStatus(status);
122  return *this;
123  }
124 
132  mtapi_uint_t value
133  ) {
134  mtapi_status_t status;
135  mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_ACTIONS,
136  &value, sizeof(value), &status);
137  internal::CheckStatus(status);
138  return *this;
139  }
140 
148  mtapi_uint_t value
149  ) {
150  mtapi_status_t status;
151  mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_GROUPS,
152  &value, sizeof(value), &status);
153  internal::CheckStatus(status);
154  return *this;
155  }
156 
164  mtapi_uint_t value
165  ) {
166  mtapi_status_t status;
167  mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_QUEUES,
168  &value, sizeof(value), &status);
169  internal::CheckStatus(status);
170  return *this;
171  }
172 
180  mtapi_uint_t value
181  ) {
182  mtapi_status_t status;
183  mtapi_nodeattr_set(&attributes_, MTAPI_NODE_QUEUE_LIMIT,
184  &value, sizeof(value), &status);
185  internal::CheckStatus(status);
186  return *this;
187  }
188 
196  mtapi_uint_t value
197  ) {
198  mtapi_status_t status;
199  mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_JOBS,
200  &value, sizeof(value), &status);
201  internal::CheckStatus(status);
202  return *this;
203  }
204 
212  mtapi_uint_t value
213  ) {
214  mtapi_status_t status;
215  mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_ACTIONS_PER_JOB,
216  &value, sizeof(value), &status);
217  internal::CheckStatus(status);
218  return *this;
219  }
220 
229  mtapi_uint_t value
230  ) {
231  mtapi_status_t status;
232  mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_PRIORITIES,
233  &value, sizeof(value), &status);
234  internal::CheckStatus(status);
235  return *this;
236  }
237 
245  mtapi_boolean_t reuse
246  ) {
247  mtapi_status_t status;
248  mtapi_nodeattr_set(&attributes_, MTAPI_NODE_REUSE_MAIN_THREAD,
249  &reuse, sizeof(reuse), &status);
250  internal::CheckStatus(status);
251  return *this;
252  }
253 
261  mtapi_node_attributes_t const & GetInternal() const {
262  return attributes_;
263  }
264 
265  private:
266  mtapi_node_attributes_t attributes_;
267 };
268 
269 } // namespace mtapi
270 } // namespace embb
271 
272 #endif // EMBB_MTAPI_NODE_ATTRIBUTES_H_
Definition: lock_free_mpmc_queue.h:40
opaque_type embb_core_set_t
Opaque type representing a set of processor cores.
Definition: core_set.h:59
Represents a set of processor cores, used to set thread-to-core affinities.
Definition: core_set.h:58
Contains attributes of a Node.
Definition: node_attributes.h:42
NodeAttributes & SetMaxActionsPerJob(mtapi_uint_t value)
Sets the maximum number of actions per job.
Definition: node_attributes.h:211
embb_core_set_t const & GetInternal() const
Provides access to internal representation to use it with C API.
Definition: core_set.h:192
NodeAttributes & SetMaxTasks(mtapi_uint_t value)
Sets the maximum number of concurrently active tasks.
Definition: node_attributes.h:115
NodeAttributes & SetMaxJobs(mtapi_uint_t value)
Sets the maximum number of available jobs.
Definition: node_attributes.h:195
NodeAttributes & SetMaxGroups(mtapi_uint_t value)
Sets the maximum number of groups.
Definition: node_attributes.h:147
NodeAttributes & SetMaxActions(mtapi_uint_t value)
Sets the maximum number of actions.
Definition: node_attributes.h:131
mtapi_node_attributes_t const & GetInternal() const
Returns the internal representation of this object.
Definition: node_attributes.h:261
NodeAttributes & SetReuseMainThread(mtapi_boolean_t reuse)
Enables or disables the reuse of the main thread as a worker.
Definition: node_attributes.h:244
NodeAttributes & SetMaxPriorities(mtapi_uint_t value)
Sets the maximum number of available priorities.
Definition: node_attributes.h:228
NodeAttributes & SetQueueLimit(mtapi_uint_t value)
Sets the default limit (capacity) of all queues.
Definition: node_attributes.h:179
NodeAttributes()
Constructs a NodeAttributes object.
Definition: node_attributes.h:48
NodeAttributes & SetWorkerPriority(mtapi_worker_priority_entry_t *worker_priorities)
Sets the priority of the specified worker threads.
Definition: node_attributes.h:98
NodeAttributes & SetCoreAffinity(embb::base::CoreSet const &cores)
Sets the core affinity of the Node.
Definition: node_attributes.h:82
void operator=(NodeAttributes const &other)
Copies a NodeAttributes object.
Definition: node_attributes.h:69
NodeAttributes(NodeAttributes const &other)
Copies a NodeAttributes object.
Definition: node_attributes.h:58
Describes the default priority of all workers or the priority of a specific worker.
Definition: mtapi.h:617
NodeAttributes & SetMaxQueues(mtapi_uint_t value)
Sets the maximum number of queues.
Definition: node_attributes.h:163