Alex Bikfalvi
SimWorker Documentation
SimWorkers.cpp
00001 #include "Headers.h" 00002 #include "SimWorkers.h" 00003 00004 CSimWorkers::CSimWorkers( 00005 unsigned int workersCount, 00006 unsigned int workersQueueSize 00007 ) 00008 { 00009 this->workersCount = workersCount; 00010 this->workerLast = 0; 00011 00012 // Create workers 00013 this->workers = new CSimWorker*[this->workersCount]; 00014 for(unsigned int index = 0; index < this->workersCount; index++) 00015 this->workers[index] = new CSimWorker(index, workersQueueSize); 00016 } 00017 00018 CSimWorkers::~CSimWorkers() 00019 { 00020 for(unsigned int index = 0; index < this->workersCount; index++) 00021 delete this->workers[index]; 00022 delete[] this->workers; 00023 } 00024 00025 void CSimWorkers::Start() 00026 { 00027 cout << "\nStarting simulator worker threads : "; 00028 // Start all workers 00029 for(unsigned int index = 0; index < this->workersCount; index++) 00030 { 00031 // Start worker 00032 this->workers[index]->Start(); 00033 cout << index << " "; 00034 } 00035 cout << "done!" << endl; 00036 00037 #ifdef WORKER_PRIORITY 00038 cout << "Scheduling policies:" << endl; 00039 cout << "\tSCHED_OTHER min=" << sched_get_priority_min(SCHED_OTHER) << " max=" << sched_get_priority_max(SCHED_OTHER) << endl; 00040 cout << "\tSCHED_FIFO min=" << sched_get_priority_min(SCHED_FIFO) << " max=" << sched_get_priority_max(SCHED_FIFO) << endl; 00041 cout << "\tSCHED_RR min=" << sched_get_priority_min(SCHED_RR) << " max=" << sched_get_priority_max(SCHED_RR) << endl; 00042 #endif 00043 } 00044 00045 void CSimWorkers::Stop() 00046 { 00047 cout << "\nStopping simulator worker threads : "; 00048 // Stop all workers 00049 for(unsigned int index = 0; index < this->workersCount; index++) 00050 { 00051 // Stop worker 00052 this->workers[index]->Stop(); 00053 cout << index << " "; 00054 } 00055 cout << "done!" << endl; 00056 } 00057 00058 void CSimWorkers::Enqueue(CSimWorkItem* item) 00059 { 00060 // Enqueue a work item on the current worker 00061 this->workers[this->workerLast]->Enqueue(item); 00062 00063 // Select next worker 00064 this->workerLast = (++this->workerLast) % this->workersCount; 00065 }
Last updated: February 8, 2011