node_attributes.h 6.49 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
  /**
   * Constructs a NodeAttributes object.
   */
  NodeAttributes() {
    mtapi_status_t status;
    mtapi_nodeattr_init(&attributes_, &status);
    internal::CheckStatus(status);
  }

  /**
   * Copies a NodeAttributes object.
   */
  NodeAttributes(
    NodeAttributes const & other       /**< The NodeAttributes to copy. */
    )
    : attributes_(other.attributes_) {
    // empty
  }

  /**
   * Copies a NodeAttributes object.
   */
  void operator=(
    NodeAttributes const & other       /**< The NodeAttributes to copy. */
    ) {
    attributes_ = other.attributes_;
  }

72 73 74 75 76
  /**
   * Sets the core affinity of the Node. This also determines the number of
   * worker threads.
   *
   * \returns Reference to this object.
77
   * \notthreadsafe
78 79 80 81
   */
  NodeAttributes & SetCoreAffinity(
    embb::base::CoreSet const & cores  /**< The cores to use. */
    ) {
82 83 84 85 86 87 88
    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;
  }

89 90 91 92
  /**
   * Sets the maximum number of concurrently active tasks.
   *
   * \returns Reference to this object.
93
   * \notthreadsafe
94 95 96 97
   */
  NodeAttributes & SetMaxTasks(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
98 99 100 101 102 103 104
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_TASKS,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

105 106 107 108
  /**
   * Sets the maximum number of actions.
   *
   * \returns Reference to this object.
109
   * \notthreadsafe
110 111 112 113
   */
  NodeAttributes & SetMaxActions(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
114 115 116 117 118 119 120
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_ACTIONS,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

121 122 123 124
  /**
   * Sets the maximum number of groups.
   *
   * \returns Reference to this object.
125
   * \notthreadsafe
126 127 128 129
   */
  NodeAttributes & SetMaxGroups(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
130 131 132 133 134 135 136
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_GROUPS,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

137 138 139 140
  /**
   * Sets the maximum number of queues.
   *
   * \returns Reference to this object.
141
   * \notthreadsafe
142 143 144 145
   */
  NodeAttributes & SetMaxQueues(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
146 147 148 149 150 151 152
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_QUEUES,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

153 154 155 156
  /**
   * Sets the default limit (capacity) of all queues.
   *
   * \returns Reference to this object.
157
   * \notthreadsafe
158 159 160 161
   */
  NodeAttributes & SetQueueLimit(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
162 163 164 165 166 167 168
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_QUEUE_LIMIT,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

169 170 171 172
  /**
   * Sets the maximum number of available jobs.
   *
   * \returns Reference to this object.
173
   * \notthreadsafe
174 175 176 177
   */
  NodeAttributes & SetMaxJobs(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
178 179 180 181 182 183 184
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_JOBS,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

185 186 187 188
  /**
   * Sets the maximum number of actions per job.
   *
   * \returns Reference to this object.
189
   * \notthreadsafe
190 191 192 193
   */
  NodeAttributes & SetMaxActionsPerJob(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
194 195 196 197 198 199 200
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_ACTIONS_PER_JOB,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

201 202 203 204 205
  /**
   * 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.
206
   * \notthreadsafe
207 208 209 210
   */
  NodeAttributes & SetMaxPriorities(
    mtapi_uint_t value                 /**< The value to set. */
    ) {
211 212 213 214 215 216 217 218 219 220 221 222
    mtapi_status_t status;
    mtapi_nodeattr_set(&attributes_, MTAPI_NODE_MAX_PRIORITIES,
      &value, sizeof(value), &status);
    internal::CheckStatus(status);
    return *this;
  }

  /**
   * 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.
223
   * \waitfree
224 225 226 227 228
   */
  mtapi_node_attributes_t const & GetInternal() const {
    return attributes_;
  }

Marcus Winter committed
229
 private:
230 231 232 233 234 235 236
  mtapi_node_attributes_t attributes_;
};

} // namespace mtapi
} // namespace embb

#endif // EMBB_MTAPI_NODE_ATTRIBUTES_H_