node_attributes.h 7.96 KB
Newer Older
1
/*
Marcus Winter committed
2
 * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef EMBB_MTAPI_NODE_ATTRIBUTES_H_
#define EMBB_MTAPI_NODE_ATTRIBUTES_H_

#include <embb/mtapi/c/mtapi.h>
#include <embb/base/core_set.h>
32
#include <embb/mtapi/internal/check_status.h>
33 34 35 36 37 38 39

namespace embb {
namespace mtapi {

/**
 * Contains attributes of a Node.
 *
40
 * \ingroup CPP_MTAPI
41 42
 */
class NodeAttributes {
Marcus Winter committed
43
 public:
44 45
  /**
   * Constructs a NodeAttributes object.
46 47
   *
   * \waitfree
48 49 50 51 52 53 54 55 56
   */
  NodeAttributes() {
    mtapi_status_t status;
    mtapi_nodeattr_init(&attributes_, &status);
    internal::CheckStatus(status);
  }

  /**
   * Copies a NodeAttributes object.
57 58
   *
   * \waitfree
59 60 61 62 63 64 65 66 67 68
   */
  NodeAttributes(
    NodeAttributes const & other       /**< The NodeAttributes to copy. */
    )
    : attributes_(other.attributes_) {
    // empty
  }

  /**
   * Copies a NodeAttributes object.
69 70
   *
   * \waitfree
71 72 73 74 75 76 77
   */
  void operator=(
    NodeAttributes const & other       /**< The NodeAttributes to copy. */
    ) {
    attributes_ = other.attributes_;
  }

78 79 80 81 82
  /**
   * Sets the core affinity of the Node. This also determines the number of
   * worker threads.
   *
   * \returns Reference to this object.
83
   * \notthreadsafe
84 85 86 87
   */
  NodeAttributes & SetCoreAffinity(
    embb::base::CoreSet const & cores  /**< The cores to use. */
    ) {
88 89 90 91 92 93 94
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_CORE_AFFINITY,
      &cores.GetInternal(), sizeof(embb_core_set_t), &status);
    internal::CheckStatus(status);
    return *this;
  }

95
  /**
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
   * 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;
  }

  /**
113 114 115
   * Sets the maximum number of concurrently active tasks.
   *
   * \returns Reference to this object.
116
   * \notthreadsafe
117 118 119 120
   */
  NodeAttributes & SetMaxTasks(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
121 122 123 124 125 126 127
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_TASKS,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

128 129 130 131
  /**
   * Sets the maximum number of actions.
   *
   * \returns Reference to this object.
132
   * \notthreadsafe
133 134 135 136
   */
  NodeAttributes & SetMaxActions(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
137 138 139 140 141 142 143
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_ACTIONS,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

144 145 146 147
  /**
   * Sets the maximum number of groups.
   *
   * \returns Reference to this object.
148
   * \notthreadsafe
149 150 151 152
   */
  NodeAttributes & SetMaxGroups(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
153 154 155 156 157 158 159
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_GROUPS,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

160 161 162 163
  /**
   * Sets the maximum number of queues.
   *
   * \returns Reference to this object.
164
   * \notthreadsafe
165 166 167 168
   */
  NodeAttributes & SetMaxQueues(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
169 170 171 172 173 174 175
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_QUEUES,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

176 177 178 179
  /**
   * Sets the default limit (capacity) of all queues.
   *
   * \returns Reference to this object.
180
   * \notthreadsafe
181 182 183 184
   */
  NodeAttributes & SetQueueLimit(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
185 186 187 188 189 190 191
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_QUEUE_LIMIT,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

192 193 194 195
  /**
   * Sets the maximum number of available jobs.
   *
   * \returns Reference to this object.
196
   * \notthreadsafe
197 198 199 200
   */
  NodeAttributes & SetMaxJobs(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
201 202 203 204 205 206 207
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_JOBS,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

208 209 210 211
  /**
   * Sets the maximum number of actions per job.
   *
   * \returns Reference to this object.
212
   * \notthreadsafe
213 214 215 216
   */
  NodeAttributes & SetMaxActionsPerJob(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
217 218 219 220 221 222 223
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_ACTIONS_PER_JOB,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

224 225 226 227 228
  /**
   * Sets the maximum number of available priorities. The priority values
   * will range from 0 to \c value - 1 with 0 being the highest priority.
   *
   * \returns Reference to this object.
229
   * \notthreadsafe
230 231 232 233
   */
  NodeAttributes & SetMaxPriorities(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
234 235 236 237 238 239 240
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_PRIORITIES,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
#ifdef EMBB_HARD_REALTIME
  /**
   * Sets the scheduling mode which is applied to schedule tasks on this node.
   *
   * \returns Reference to this object.
   * \notthreadsafe
   */
  NodeAttributes & SetSchedulerMode(
    embb_mtapi_scheduler_mode_t value  /**< The value to set. */
    ) {
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_SCHEDULER_MODE,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

#endif /*EMBB_HARD_REALTIME*/
259 260 261 262 263 264
  /**
   * Enables or disables the reuse of the main thread as a worker.
   *
   * \returns Reference to this object.
   * \notthreadsafe
   */
265 266 267 268 269 270 271 272 273 274
  NodeAttributes & SetReuseMainThread(
    mtapi_boolean_t reuse
    ) {
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_REUSE_MAIN_THREAD,
      &reuse, sizeof(reuse), &status);
    internal::CheckStatus(status);
    return *this;
  }

275 276 277 278 279
  /**
   * Returns the internal representation of this object.
   * Allows for interoperability with the C interface.
   *
   * \returns A reference to the internal mtapi_node_attributes_t structure.
280
   * \waitfree
281 282 283 284 285
   */
  mtapi_node_attributes_t const & GetInternal() const {
    return attributes_;
  }

Marcus Winter committed
286
 private:
287 288 289 290 291 292 293
  mtapi_node_attributes_t attributes_;
};

} // namespace mtapi
} // namespace embb

#endif // EMBB_MTAPI_NODE_ATTRIBUTES_H_