A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PDBWorker.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 /*
19  * File: PDBWorker.h
20  * Author: Chris
21  *
22  * Created on September 25, 2015, 5:11 PM
23  */
24 
25 #ifndef PDBWORKER_H
26 #define PDBWORKER_H
27 
28 // create a smart pointer for PDBWorker objects
29 #include <memory>
30 #include "PDBAlarm.h"
31 #include "PDBBuzzer.h"
32 #include "PDBWork.h"
33 #include "PDBWorkerQueue.h"
34 
35 // this class wraps up a thread... note that PDBWorker objects should always be created
36 // by the PDBWorkerQueue class.
37 
38 namespace pdb {
39 
40 class PDBWorker;
41 typedef shared_ptr<PDBWorker> PDBWorkerPtr;
42 
43 class PDBWork;
44 typedef shared_ptr<PDBWork> PDBWorkPtr;
45 
46 class PDBWorker {
47 public:
48  // constructor... accepts the work queue that is creating it
50 
51  // destructor
52  ~PDBWorker();
53 
54  // gets another worder from the same work queue that this guy came from... note that
55  // this call can block if the work queue does not have any additional workers
57 
58  // asks this worker to execute runMe... this call is non-blocking. When the task
59  // is done, myBuzzer->buzz () should be called.
60  void execute(PDBWorkPtr runMe, PDBBuzzerPtr myBuzzer);
61 
62  // directly sound the buzzer on this guy to wake him if he is sleeping
63  void soundBuzzer(PDBAlarm withMe);
64 
65  // gets access to the logger
67 
68  // entry point for a thread
69  void enter();
70 
71  // this resets the contents
72  void reset();
73 
74 private:
75  // the work queue we came from
77 
78  // the work to run
80 
81  // used to signal when we are done, or when some event happens
83 
84  // for coordinating the thread who is running this guy
85  pthread_mutex_t workerMutex;
86  pthread_cond_t workToDoSignal;
87 
88  // set to true when the worker is able to go and do the work
90 };
91 }
92 
93 #endif /* PDBWORKER_H */
pthread_mutex_t workerMutex
Definition: PDBWorker.h:85
bool okToExecute
Definition: PDBWorker.h:89
void enter()
Definition: PDBWorker.cc:57
shared_ptr< PDBWork > PDBWorkPtr
Definition: PDBWork.h:47
PDBWorkerQueue * parent
Definition: PDBWorker.h:76
void execute(PDBWorkPtr runMe, PDBBuzzerPtr myBuzzer)
Definition: PDBWorker.cc:43
PDBWorkPtr runMe
Definition: PDBWorker.h:79
void reset()
Definition: PDBWorker.cc:73
PDBBuzzerPtr buzzWhenDone
Definition: PDBWorker.h:82
shared_ptr< PDBBuzzer > PDBBuzzerPtr
Definition: PDBBuzzer.h:32
PDBWorkerPtr getWorker()
Definition: PDBWorker.cc:35
shared_ptr< PDBWorker > PDBWorkerPtr
Definition: PDBWorker.h:40
pthread_cond_t workToDoSignal
Definition: PDBWorker.h:86
PDBAlarm
Definition: PDBAlarm.h:28
std::shared_ptr< PDBLogger > PDBLoggerPtr
Definition: PDBLogger.h:40
PDBWorker(PDBWorkerQueue *parent)
Definition: PDBWorker.cc:29
void soundBuzzer(PDBAlarm withMe)
Definition: PDBWorker.cc:51
PDBLoggerPtr getLogger()
Definition: PDBWorker.cc:39