Embedded Multicore Building Blocks V1.0.0
task_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_TASK_ATTRIBUTES_H_
28 #define EMBB_MTAPI_TASK_ATTRIBUTES_H_
29 
30 #include <embb/mtapi/c/mtapi.h>
31 #include <embb/mtapi/internal/check_status.h>
32 #include <embb/mtapi/execution_policy.h>
33 
34 namespace embb {
35 namespace mtapi {
36 
43  public:
49  mtapi_status_t status;
50  mtapi_taskattr_init(&attributes_, &status);
51  internal::CheckStatus(status);
52  }
53 
63  bool state
64  ) {
65  mtapi_status_t status;
66  mtapi_boolean_t st = state ? MTAPI_TRUE : MTAPI_FALSE;
67  mtapi_taskattr_set(&attributes_, MTAPI_TASK_DETACHED,
68  &st, sizeof(st), &status);
69  internal::CheckStatus(status);
70  return *this;
71  }
72 
81  mtapi_uint_t priority
82  ) {
83  mtapi_status_t status;
84  mtapi_taskattr_set(&attributes_, MTAPI_TASK_PRIORITY,
85  &priority, sizeof(priority), &status);
86  internal::CheckStatus(status);
87  return *this;
88  }
89 
98  mtapi_affinity_t affinity
99  ) {
100  mtapi_status_t status;
101  mtapi_taskattr_set(&attributes_, MTAPI_TASK_AFFINITY,
102  &affinity, sizeof(affinity), &status);
103  internal::CheckStatus(status);
104  return *this;
105  }
106 
115  ExecutionPolicy const & policy
116  ) {
117  SetPriority(policy.GetPriority());
118  SetAffinity(policy.GetAffinity());
119  return *this;
120  }
121 
132  mtapi_uint_t instances
133  ) {
134  mtapi_status_t status;
135  mtapi_taskattr_set(&attributes_, MTAPI_TASK_INSTANCES,
136  &instances, sizeof(instances), &status);
137  internal::CheckStatus(status);
138  return *this;
139  }
140 
148  mtapi_task_attributes_t const & GetInternal() const {
149  return attributes_;
150  }
151 
152  private:
153  mtapi_task_attributes_t attributes_;
154 };
155 
156 } // namespace mtapi
157 } // namespace embb
158 
159 #endif // EMBB_MTAPI_TASK_ATTRIBUTES_H_
Definition: lock_free_mpmc_queue.h:40
TaskAttributes & SetPriority(mtapi_uint_t priority)
Sets the priority of a Task.
Definition: task_attributes.h:80
mtapi_uint64_t mtapi_affinity_t
Core affinity type.
Definition: mtapi.h:350
TaskAttributes & SetInstances(mtapi_uint_t instances)
Sets the number of instances in a Task.
Definition: task_attributes.h:131
mtapi_task_attributes_t const & GetInternal() const
Returns the internal representation of this object.
Definition: task_attributes.h:148
mtapi_uint_t GetPriority() const
Returns the priority.
TaskAttributes & SetAffinity(mtapi_affinity_t affinity)
Sets the affinity of a Task.
Definition: task_attributes.h:97
Contains attributes of a Task.
Definition: task_attributes.h:42
TaskAttributes & SetDetached(bool state)
Sets the detached property of a Task.
Definition: task_attributes.h:62
TaskAttributes()
Constructs a TaskAttributes object.
Definition: task_attributes.h:48
Describes the execution policy of a parallel algorithm.
Definition: execution_policy.h:48
TaskAttributes & SetPolicy(ExecutionPolicy const &policy)
Sets the ExecutionPolicy of a Task.
Definition: task_attributes.h:114
mtapi_affinity_t GetAffinity() const
Returns the affinity.