PhoenixThread  1.0.0
Tools to ease parallel programming in C++
Loading...
Searching...
No Matches
DetachPool.h
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#ifndef __DETACHPOOL_H__
8#define __DETACHPOOL_H__
9
10#include <unistd.h>
11#include <thread>
12#include <list>
13#include <mutex>
14#include <string>
15#include <iostream>
16
18
19#define PEXIT_STATUS_NOT_FIHISHED 0
20#define PEXIT_STATUS_OK 1
21#define PEXIT_STATUS_FAIL 2
22
26 std::string description;
29};
30
31typedef std::list<ThreadDetachInfo> ListThreadDetachInfo;
32
35 public:
36 DetachPool();
37 DetachPool(const DetachPool & other);
38 virtual ~DetachPool();
39 DetachPool & operator = (const DetachPool & other);
40
41 void setRefreshTime(PEllapsedTime refreshTime);
43
44 void setDestructionWaitTime(PEllapsedTime destructorWaitTime);
46
48
49 template<typename _Callable, typename... _Args>
50 void addThread(const std::string & description, _Callable&& __f, _Args&&... __args);
51 void removeFinishedThread(std::ostream & out = std::cout);
52
53 void refresh();
54 void waitUntilAllFinish(PEllapsedTime maxWaitTime = 10000000); //Wait 10 seconds by default
55
56 protected:
57 void copyDetachPool(const DetachPool & other);
58
59 private:
61
63 std::mutex p_mtx;
72};
73
74std::string phoenix_statusToString(int exitStatus);
75void phoenix_printThreadStatus(const ListThreadDetachInfo & listThreadInfo, std::ostream & out = std::cout);
76
77#include "DetachPool_impl.h"
78
79#endif
80
std::string phoenix_statusToString(int exitStatus)
Convert the current status of a thread into a string.
std::list< ThreadDetachInfo > ListThreadDetachInfo
Definition DetachPool.h:31
void phoenix_printThreadStatus(const ListThreadDetachInfo &listThreadInfo, std::ostream &out=std::cout)
Print the status of all remaning thread.
PhoenixTime p_timeLastRefresh
Time of last refresh (in micro second)
Definition DetachPool.h:67
void removeFinishedThread(std::ostream &out=std::cout)
Remove all finished threads.
void initialisationDetachPool()
Initialisation function of the class DetachPool.
DetachPool & operator=(const DetachPool &other)
Definition of equal operator of DetachPool.
DetachPool()
Default constructor of DetachPool.
ListThreadDetachInfo getListThreadInfo()
Get the list of thread information.
virtual ~DetachPool()
Destructor of DetachPool.
PEllapsedTime p_refreshTime
Ellapsed time between two refresh (in micro second)
Definition DetachPool.h:65
void addThread(const std::string &description, _Callable &&__f, _Args &&... __args)
Add the thread into the pool.
PEllapsedTime p_destructorWaitTime
Wait time when object is destroyed.
Definition DetachPool.h:71
PEllapsedTime getDestructorWaitTime() const
Get the wait time on object destruction (in microseconds)
std::mutex p_mtx
Mutex to handle exit status of detached threads.
Definition DetachPool.h:63
void setRefreshTime(PEllapsedTime refreshTime)
Set the ellasped time between two refresh in microseconds.
PEllapsedTime getRefreshTime() const
Get the ellasped time between two refresh in microseconds.
void setDestructionWaitTime(PEllapsedTime destructorWaitTime)
Set the wait time on object destruction (in microseconds)
void waitUntilAllFinish(PEllapsedTime maxWaitTime=10000000)
wait until all detached thread have fnished theirs computation
ListThreadDetachInfo p_listThreadInfo
List of the information related to all ongoing threads.
Definition DetachPool.h:69
void copyDetachPool(const DetachPool &other)
Copy function of DetachPool.
void refresh()
Refresh the list of the detached threads.
std::chrono::time_point< std::chrono::steady_clock > PhoenixTime
int64_t PEllapsedTime
Information related to the current detached thread.
Definition DetachPool.h:24
int exitStatus
Exit status of the current thread.
Definition DetachPool.h:28
std::string description
Description of the current thread.
Definition DetachPool.h:26