Directory: | ./ |
---|---|
File: | src/DetachPool_impl.h |
Date: | 2025-05-16 18:34:22 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 10 | 10 | 100.0% |
Branches: | 5 | 5 | 100.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #ifndef __DETACHPOOL_IMPL_H__ | ||
8 | #define __DETACHPOOL_IMPL_H__ | ||
9 | |||
10 | #include "DetachPool.h" | ||
11 | |||
12 | ///Add the thread into the pool | ||
13 | /** @param description : description of the thread (will be used in the stdout to inform when the thread is finished) | ||
14 | * @param __f : function to be lauched on each thread (function with prototype void f(const std::vector<std::string>& listFile, __args); ) | ||
15 | * @param __args : extra arguments to be passed to the function __f (optional arguments) | ||
16 | * Passed function has to have the following prototype : | ||
17 | * void f(int & exitStatus, other arguments...); | ||
18 | */ | ||
19 | template<typename _Callable, typename... _Args> | ||
20 | 24 | void DetachPool::addThread(const std::string & description, _Callable&& __f, _Args&&... __args){ | |
21 | 24 | ThreadDetachInfo info; | |
22 |
1/1✓ Branch 1 taken 12 times.
|
24 | info.description = description; |
23 | 24 | info.exitStatus = PEXIT_STATUS_NOT_FIHISHED; | |
24 |
1/1✓ Branch 1 taken 12 times.
|
24 | p_mtx.lock(); |
25 |
1/1✓ Branch 1 taken 12 times.
|
24 | p_listThreadInfo.push_back(info); //Let's add the info to the running threads |
26 | 24 | p_mtx.unlock(); | |
27 |
1/1✓ Branch 3 taken 12 times.
|
24 | std::thread thrSimpleDetach(__f, std::ref(p_listThreadInfo.back().exitStatus), __args...); |
28 |
1/1✓ Branch 1 taken 12 times.
|
24 | thrSimpleDetach.detach(); |
29 | 24 | } | |
30 | |||
31 | |||
32 | #endif | ||
33 | |||
34 |