Embedded Multicore Building Blocks V1.0.0
core_set.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_BASE_CORE_SET_H_
28 #define EMBB_BASE_CORE_SET_H_
29 
30 #include <embb/base/c/core_set.h>
31 
32 namespace embb {
33 namespace base {
34 
58 class CoreSet {
59  public:
68  static unsigned int CountAvailable();
69 
73  CoreSet();
74 
78  explicit CoreSet(
79  bool value
81  );
82 
86  CoreSet(
87  const CoreSet& to_copy
89  );
90 
97  const CoreSet& to_assign
99  );
100 
104  void Reset(
105  bool value
107  );
108 
112  void Add(
113  unsigned int core
115  );
116 
120  void Remove(
121  unsigned int core
123  );
124 
130  bool IsContained(
131  unsigned int core
133  ) const;
134 
140  unsigned int Count() const;
141 
150  const CoreSet& rhs
152  ) const;
153 
162  const CoreSet& rhs
164  ) const;
165 
173  const CoreSet& rhs
175  );
176 
183  const CoreSet& rhs
185  );
186 
192  embb_core_set_t const & GetInternal() const { return rep_; }
193 
194  private:
198  embb_core_set_t rep_;
199 
203  friend class Thread;
204 };
205 
206 } // namespace base
207 } // namespace embb
208 
209 
210 
211 #endif // EMBB_BASE_CORE_SET_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
bool IsContained(unsigned int core) const
Checks whether the specified core is included in the set.
void Remove(unsigned int core)
Removes one core from the core set.
void Reset(bool value)
Resets the core set according to the specified value.
CoreSet & operator|=(const CoreSet &rhs)
Unites this core set with the specified one an overwrites this core set.
CoreSet & operator=(const CoreSet &to_assign)
Assigns an existing core set.
embb_core_set_t const & GetInternal() const
Provides access to internal representation to use it with C API.
Definition: core_set.h:192
CoreSet operator|(const CoreSet &rhs) const
Unites this core set with the specified one.
CoreSet operator&(const CoreSet &rhs) const
Intersects this core set with the specified one.
CoreSet & operator&=(const CoreSet &rhs)
Intersects this core set with the specified one and overwrites this core set.
Represents a thread of execution.
Definition: thread.h:59
CoreSet()
Constructs an empty core set.
static unsigned int CountAvailable()
Returns the number of available processor cores.
void Add(unsigned int core)
Adds one core to the core set.
unsigned int Count() const
Counts the number of cores in the set.