Advanced Multi-Physics (AMP)
On-Line Documentation
ThreadPoolId.h
Go to the documentation of this file.
1// Copyright 2004 Mark Berrill. All Rights Reserved. This work is distributed with permission,
2// but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
3// PARTICULAR PURPOSE.
4#ifndef included_AMP_ThreadPoolID
5#define included_AMP_ThreadPoolID
6
7
8#include <atomic>
9
10
11namespace AMP {
12
13
14class ThreadPoolWorkItem;
15
16
25{
26public:
27 // Work status
28 enum class Status : int8_t { none = 0, added = 1, started = 2, finished = 3 };
29
30 // nullID definitins
31 static constexpr uint64_t nullThreadID = 0x0FFFFFFFFFFFFFFF;
32 static constexpr uint64_t maxThreadID = 0x00FFFFFFFFFFFFFD;
33
35 ThreadPoolID() = default;
36
38 inline ~ThreadPoolID() { reset(); }
39
41 ThreadPoolID( const volatile ThreadPoolID &rhs );
42 ThreadPoolID( volatile ThreadPoolID &&rhs );
43 ThreadPoolID &operator=( const ThreadPoolID &rhs ) volatile;
44 ThreadPoolID &operator=( volatile ThreadPoolID &&rhs ) volatile;
45#if !defined( WIN32 ) && !defined( _WIN32 ) && !defined( WIN64 ) && !defined( _WIN64 )
49 ThreadPoolID &operator=( const volatile ThreadPoolID &rhs );
50 ThreadPoolID &operator=( const volatile ThreadPoolID &rhs ) volatile;
51#endif
52
53 // Overload key operators
54 inline bool operator==( const ThreadPoolID &rhs ) const
55 {
56 return !( ( d_id ^ rhs.d_id ) & nullThreadID );
57 }
58 inline bool operator!=( const ThreadPoolID &rhs ) const
59 {
60 return ( d_id ^ rhs.d_id ) & nullThreadID;
61 }
62 inline bool operator>=( const ThreadPoolID &rhs ) const { return d_id >= rhs.d_id; }
63 inline bool operator<=( const ThreadPoolID &rhs ) const { return d_id <= rhs.d_id; }
64 inline bool operator>( const ThreadPoolID &rhs ) const { return d_id > rhs.d_id; }
65 inline bool operator<( const ThreadPoolID &rhs ) const { return d_id < rhs.d_id; }
66 inline bool operator==( const volatile ThreadPoolID &rhs ) const volatile
67 {
68 return !( ( d_id ^ rhs.d_id ) & nullThreadID );
69 }
70 inline bool operator!=( const volatile ThreadPoolID &rhs ) const volatile
71 {
72 return ( d_id ^ rhs.d_id ) & nullThreadID;
73 }
74 inline bool operator>=( const volatile ThreadPoolID &rhs ) const volatile
75 {
76 return d_id >= rhs.d_id;
77 }
78 inline bool operator<=( const volatile ThreadPoolID &rhs ) const volatile
79 {
80 return d_id <= rhs.d_id;
81 }
82 inline bool operator>( const volatile ThreadPoolID &rhs ) const volatile
83 {
84 return d_id > rhs.d_id;
85 }
86 inline bool operator<( const volatile ThreadPoolID &rhs ) const volatile
87 {
88 return d_id < rhs.d_id;
89 }
90
92 void reset() volatile;
93 void reset();
94
96 Status status() const;
97
99 inline bool started() const { return static_cast<int>( status() ) >= 2; }
100
102 inline bool finished() const { return static_cast<int>( status() ) == 3; }
103
105 inline void swap( ThreadPoolID &rhs )
106 {
107 std::swap( this->d_id, rhs.d_id );
108 std::swap( this->d_count, rhs.d_count );
109 std::swap( this->d_work, rhs.d_work );
110 }
111
113 inline bool isNull() const { return d_id == nullThreadID; }
114
117 {
118 return reinterpret_cast<ThreadPoolWorkItem *>( d_work );
119 }
120
121public:
122 // Is the id ready to process
123 bool ready() const;
124 // Reset the internal data to the given values
125 void reset( int8_t priority, uint64_t local_id, void *work );
126 // Generate an id
127 static uint64_t createId( int8_t priority, uint64_t local_id );
128 // Get the local id
129 uint64_t getLocalID() const;
130 // Get the priority
131 int8_t getPriority() const;
132 // Increase the priority
133 void setPriority( int8_t priority );
134 // Check if the id is initialized
135 inline bool initialized() const volatile { return d_id != 0x0FFFFFFFFFFFFFFF; }
136
137private:
138 // Data
139 uint64_t d_id = nullThreadID; // 64-bit data to store id
140 volatile std::atomic_int32_t *d_count = nullptr; // Reference count
141 void *d_work = nullptr; // Pointer to the work item
142};
143
144
145} // namespace AMP
146
147
148#endif
This a class to hold the work item id.
ThreadPoolID & operator=(volatile ThreadPoolID &&rhs) volatile
ThreadPoolID(const ThreadPoolID &rhs)
bool operator>(const volatile ThreadPoolID &rhs) const volatile
ThreadPoolWorkItem * getWork() const
Check if thread id is null.
~ThreadPoolID()
Destructor.
bool operator>=(const volatile ThreadPoolID &rhs) const volatile
static constexpr uint64_t nullThreadID
void reset() volatile
Reset the id back to a NULL id.
bool operator>(const ThreadPoolID &rhs) const
static uint64_t createId(int8_t priority, uint64_t local_id)
ThreadPoolID()=default
Empty constructor.
bool finished() const
Check if the work has finished.
uint64_t getLocalID() const
static constexpr uint64_t maxThreadID
bool operator<=(const volatile ThreadPoolID &rhs) const volatile
bool initialized() const volatile
ThreadPoolID & operator=(ThreadPoolID &&rhs)
bool operator<(const ThreadPoolID &rhs) const
void reset(int8_t priority, uint64_t local_id, void *work)
ThreadPoolID & operator=(const volatile ThreadPoolID &rhs) volatile
volatile std::atomic_int32_t * d_count
ThreadPoolID & operator=(const ThreadPoolID &rhs)
Status status() const
Return the status of the work item.
bool operator!=(const volatile ThreadPoolID &rhs) const volatile
bool isNull() const
Check if thread id is null.
ThreadPoolID & operator=(const ThreadPoolID &rhs) volatile
bool operator!=(const ThreadPoolID &rhs) const
int8_t getPriority() const
bool operator<=(const ThreadPoolID &rhs) const
ThreadPoolID & operator=(const volatile ThreadPoolID &rhs)
ThreadPoolID(const volatile ThreadPoolID &rhs)
Copy constructors.
bool started() const
Check if the work has started (will return true if it has started or finished)
void swap(ThreadPoolID &rhs)
swap with rhs
bool ready() const
ThreadPoolID(volatile ThreadPoolID &&rhs)
bool operator>=(const ThreadPoolID &rhs) const
void setPriority(int8_t priority)
bool operator==(const ThreadPoolID &rhs) const
bool operator<(const volatile ThreadPoolID &rhs) const volatile
bool operator==(const volatile ThreadPoolID &rhs) const volatile
Base class for the work item (users should derive from ThreadPool::WorkItemRet)



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page