Revert "Use fabs() for floats, not abs()".
[agianapa.git] / sphere-orbit / workerthread.cpp
blob052e9a893ed93d0644bc2d6af38d781076e4a3d4
1 #include <cstdlib>
2 #include <iostream>
4 #include "workerthread.h"
6 WorkerThread::WorkerThread(QObject *parent, QQueue<float> *pData)
7 : QThread(parent)
9 // Initialize random generator here
10 srand(time(NULL));
12 abort = false;
13 prev = 0;
14 this->pData = pData;
17 WorkerThread::~WorkerThread()
19 mutex.lock();
20 abort = true;
21 condition.wakeOne();
22 mutex.unlock();
24 wait();
27 void WorkerThread::run(void)
29 float r;
31 // Loop
32 while (!abort) {
33 r = 3.0 * (float) rand() / RAND_MAX;
34 r += prev;
35 prev = r;
36 //std::cout << "r = " << r << std::endl;
37 mutex.lock();
38 if (pData->size() > 100) {
39 std::cout << "WorkerThread::run()\t[BLOCKED]\n";
40 condition.wait(&mutex);
41 mutex.unlock();
43 else {
44 pData->enqueue(r);
45 mutex.unlock();
50 void WorkerThread::setData(QQueue<float> *pData)
52 this->pData = pData;