Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/mash/ThreadPool.h @ 69:33d812a61356
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 17:55:14 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 69:33d812a61356 |
---|---|
1 // Copyright © 2015, Battelle National Biodefense Institute (BNBI); | |
2 // all rights reserved. Authored by: Brian Ondov, Todd Treangen, | |
3 // Sergey Koren, and Adam Phillippy | |
4 // | |
5 // See the LICENSE.txt file included with this software for license information. | |
6 | |
7 #ifndef ThreadPool_h | |
8 #define ThreadPool_h | |
9 | |
10 #include <pthread.h> | |
11 #include <queue> | |
12 | |
13 template <class TypeInput, class TypeOutput> | |
14 class ThreadPool | |
15 { | |
16 public: | |
17 | |
18 ThreadPool(TypeOutput * (* functionNew)(TypeInput *), unsigned int threadCountNew); | |
19 ~ThreadPool(); | |
20 | |
21 bool outputAvailable() const; | |
22 TypeOutput * popOutputWhenAvailable(); // output must be deleted by calling function | |
23 bool running() const; | |
24 void runWhenThreadAvailable(TypeInput * input); // thread deletes input when finished | |
25 void runWhenThreadAvailable(TypeInput * input, TypeOutput * (* functionNew)(TypeInput *)); // thread deletes input when finished | |
26 | |
27 private: | |
28 | |
29 struct OutputQueueNode | |
30 { | |
31 // used to preserve input order when outputting | |
32 | |
33 OutputQueueNode * prev; | |
34 OutputQueueNode * next; | |
35 | |
36 TypeOutput * output; | |
37 bool ready; | |
38 }; | |
39 | |
40 unsigned int threadCount; | |
41 | |
42 pthread_t * threads; | |
43 | |
44 static void * thread(void *); | |
45 | |
46 TypeOutput * (* function)(TypeInput *); | |
47 TypeInput * inputCurrent; | |
48 OutputQueueNode * outputQueueNodeCurrent; | |
49 | |
50 pthread_mutex_t * mutexInput; | |
51 pthread_mutex_t * mutexOutput; | |
52 | |
53 pthread_cond_t * condInput; | |
54 pthread_cond_t * condOutput; | |
55 | |
56 OutputQueueNode * outputQueueHead; | |
57 OutputQueueNode * outputQueueTail; | |
58 | |
59 bool finished; | |
60 friend void * thread(void *); | |
61 }; | |
62 | |
63 | |
64 #include "ThreadPool.hxx" | |
65 | |
66 #endif |