OnixS C++ B3 BOE Binary Order Entry  1.2.0
API Documentation
Thread.h
Go to the documentation of this file.
1 /*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable OnixS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 
20 #pragma once
21 
22 #include <set>
23 
24 #include <OnixS/B3/BOE/ABI.h>
26 
27 namespace OnixS {
28 namespace B3 {
29 namespace BOE {
30 namespace Threading {
31 
32 /// Logical processors that a thread is allowed to run on (first logical CPU has index 0).
33 typedef size_t CpuIndex;
34 typedef std::set < CpuIndex > CpuIndexes;
35 
36 /// Represents set of CPU indices.
38 {
39 public:
40 
41  /// Constructs thread affinity from the string presentation.
42  /// Symbol ',' is used as the CPU index delimiter.
43  explicit ThreadAffinity(const std::string & str);
44 
45  /// Destructs the instance.
46  ~ThreadAffinity();
47 
48  /// Read-only access to index collection.
49  const CpuIndexes & cpuIndexes() const;
50 
51  /// Collection of CPU indices.
52  CpuIndexes & cpuIndexes();
53 
54  /// Serializes thread affinity to the string presentation.
55  std::string toString();
56 
57 private:
59  ThreadAffinity & operator = (const ThreadAffinity &);
60 
61  CpuIndexes * indexes_;
62 };
63 
64 /// Current thread related tasks.
66 {
67 public:
68  /// Suspends the execution of the current thread for
69  /// the given amount of time.
70  static void sleep(unsigned int milliseconds);
71 
72  /// Executes a single instruction during the given number of microseconds.
73  static void spinWait(unsigned int microseconds);
74 
75  /// Sets the processor affinity mask for the current thread.
76  static void affinity(const CpuIndexes & cpuIndexes);
77 
78  /// Sets the processor affinity mask for the current thread.
79  static void affinity(CpuIndex cpuIndex);
80 
81  /// Sets the priority for the current thread.
82  static void priority(int priority);
83 
84  /// Sets the scheduling policy for the current thread.
85  ///
86  /// \note This method also sets the priority to the minimal value for the new policy,
87  /// therefore, the priority should be set to a necessary value afterwards.
88  static void policy(int policy);
89 
90  /// \return the platform identifier for the current thread.
91  static ThreadId id();
92 
93  /// \return the processor number the current thread is running on during the call to this method.
94  static unsigned int processorNumber();
95 
96 private:
97  ThisThread(const ThisThread &);
98  ThisThread & operator = (const ThisThread &);
99 };
100 
101 }
102 }
103 }
104 }
Current thread related tasks.
Definition: Thread.h:65
pthread_t ThreadId
Type alias for thread identifier.
Definition: Definitions.h:34
#define ONIXS_B3_BOE_EXPORTED
Definition: Compiler.h:181
Represents set of CPU indices.
Definition: Thread.h:37
Definition: Defines.h:40
size_t CpuIndex
Logical processors that a thread is allowed to run on (first logical CPU has index 0)...
Definition: Thread.h:33
std::set< CpuIndex > CpuIndexes
Definition: Thread.h:34