19 #ifndef PDB_WORKER_Q_C
20 #define PDB_WORKER_Q_C
38 std::cout <<
"I have detected that you have started two PDBWorkerQueue objects in this "
40 std::cout <<
"This is a really bad idea. It probably will result in a crash at some "
42 std::cout <<
"regardless of that, the idea is to have one queue that everyone draws "
54 <<
"This is bad... it appears that you are creating more than one worker queue!\n";
66 for (
int i = 0; i < numWorkers; i++) {
69 new (i * 1024 * 1024 * 4 + ((
char*)
stackBase))
74 (i + 1) * 1024 * 1024 * 4 + ((
char*)stackBase));
97 if (myWorker ==
nullptr)
100 PDBWorkPtr nothing{make_shared<NothingWork>()};
101 myWorker->execute(nothing,
nullptr);
105 for (pthread_t thread :
threads) {
106 if (pthread_join(thread,
nullptr) != 0) {
107 cout <<
"Error joining with thread as the worker queue is shutting down!!\n";
118 for (
int i = 0; i < threads.size(); i++) {
168 stackBaseIn = (
void*)((((
long)stackBaseIn + (PTHREAD_STACK_MIN - 1)) / PTHREAD_STACK_MIN) *
172 pthread_attr_t tattr;
173 pthread_attr_init(&tattr);
175 pthread_attr_setstack(&tattr, stackBaseIn, ((
char*)stackEndIn) - (
char*)stackBaseIn);
179 cout <<
"ERROR; return code from pthread_create () is " << return_code <<
'\n';
193 p->soundBuzzer(withMe);
219 if (
working.erase(temp) != 1) {
220 cout <<
"Why did I find != 1 copies of the worker?";
void * enterTheQueue(void *pdbWorkerQueueInstance)
void notifyAllWorkers(PDBAlarm withMe)
MultiPolicyAllocator< DefaultPolicy, NoReusePolicy, NoReferenceCountPolicy > Allocator
static const size_t defaultAllocatorBlockSize
vector< PDBWorkerPtr > waiting
set< PDBWorkerPtr > working
shared_ptr< PDBWork > PDBWorkPtr
pthread_mutex_t waitingMutex
void addAnotherWorker(void *stackStart, void *stackEnd)
pthread_mutex_t workingMutex
PDBWorkerQueue(PDBLoggerPtr myLogger, int numWorkers)
shared_ptr< PDBWorker > PDBWorkerPtr
std::shared_ptr< PDBLogger > PDBLoggerPtr
pthread_cond_t waitingSignal
vector< pthread_t > threads