Advanced Multi-Physics (AMP)
On-Line Documentation
ThreadPoolWorkItem.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_ThreadPoolWorkItem
5#define included_AMP_ThreadPoolWorkItem
6
7
8#include "AMP/utils/threadpool/ThreadPoolId.h"
9
10#include <vector>
11
12
13namespace AMP {
14
15
18{
19public:
21 virtual void run() = 0;
23 virtual bool has_result() const = 0;
26 {
27 delete[] d_ids;
28 d_ids = nullptr;
29 d_N_ids = 0;
30 d_size = 0;
31 }
33 inline std::size_t get_N_dependencies() const { return d_N_ids; }
35 std::vector<ThreadPoolID> get_dependencies() const;
40 void add_dependency( const ThreadPoolID &id ) { add_dependencies( 1, &id ); }
45 inline void add_dependencies( const std::vector<ThreadPoolID> &ids )
46 {
47 if ( !ids.empty() )
48 add_dependencies( ids.size(), &ids[0] );
49 }
56 void add_dependencies( std::size_t N, const ThreadPoolID *ids );
57
59 inline auto getStatus() const { return d_state; }
60
61protected:
62 friend class ThreadPool;
64 : d_state( ThreadPoolID::Status::none ),
65 d_N_ids( 0 ),
66 d_size( 0 ),
67 d_count( 0 ),
68 d_ids( nullptr )
69 {
70 }
71
72private:
75 volatile ThreadPoolID::Status d_state; // Current state
76 uint16_t d_N_ids; // Number of dependencies
77 uint16_t d_size; // Size of d_ids
78 volatile std::atomic_int32_t d_count; // Count used by a thread_id
79 ThreadPoolID *d_ids; // Pointer to id list
80 // Friends
81 friend class ThreadPoolID;
82};
83
84
85} // namespace AMP
86
87
88#endif
This a class to hold the work item id.
Base class for the work item (users should derive from ThreadPool::WorkItemRet)
void add_dependency(const ThreadPoolID &id)
Add a work item to the list of dependencies.
virtual void run()=0
Function to run the routine.
void add_dependencies(std::size_t N, const ThreadPoolID *ids)
Add a list of work item to the list of dependencies Note: this function is thread-safe for the thread...
void add_dependencies(const std::vector< ThreadPoolID > &ids)
Add a list of work item to the list of dependencies.
std::size_t get_N_dependencies() const
Get the number of work ids that this work item depends on.
auto getStatus() const
Get the current status.
virtual ~ThreadPoolWorkItem()
Empty deconstructor.
volatile ThreadPoolID::Status d_state
ThreadPoolWorkItem(const ThreadPoolWorkItem &)=delete
ThreadPoolWorkItem & operator=(const ThreadPoolWorkItem &)=delete
std::vector< ThreadPoolID > get_dependencies() const
Return the list of work ids that we depend on.
volatile std::atomic_int32_t d_count
virtual bool has_result() const =0
Will the routine return a result.
This is a concrete class that provides for a basic thread pool.
Definition ThreadPool.h:49



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