05.11.2011 - stable version, 0.1.0, self-test program, work at GCC 2.95 - 4.5, VC 2010, MinGW, Linux, Windows, QNX

This commit is contained in:
peri4
2011-12-05 23:51:02 +03:00
parent e25553b97b
commit 74b4173c4c
43 changed files with 1495 additions and 694 deletions

View File

@@ -1,10 +1,17 @@
#include "pithread.h"
PIThread::PIThread(bool startNow, int timer_delay) {
PIThread::PIThread(bool startNow, int timer_delay): PIObject() {
piMonitor.threads++;
running = lockRun = false;
priority_ = piNormal;
timer = timer_delay;
/*addEvent("started");
addEvent("stopped");
addEventHandler<int>(HANDLER(PIThread, start));
addEventHandler(HANDLER(PIThread, startOnce));
addEventHandler(HANDLER(PIThread, stop));
addEventHandler<bool>(HANDLER(PIThread, terminate));*/
if (startNow) start(timer_delay);
}
@@ -13,6 +20,7 @@ PIThread::PIThread(bool startNow, int timer_delay) {
#endif
PIThread::~PIThread() {
piMonitor.threads--;
if (!running) return;
#ifndef WINDOWS
pthread_cancel(thread);
@@ -79,12 +87,14 @@ void * PIThread::thread_function(void * t) {
PIThread * ct = (PIThread * )t;
ct->running = true;
ct->begin();
raiseEvent(ct, "started");
while (!ct->terminating) {
if (ct->lockRun) ct->mutex_.lock();
ct->run();
if (ct->lockRun) ct->mutex_.unlock();
if (ct->timer > 0) msleep(ct->timer);
}
raiseEvent(ct, "stopped");
ct->end();
ct->running = false;
//cout << "thread " << t << " exiting ... " << endl;
@@ -101,9 +111,11 @@ void * PIThread::thread_function_once(void * t) {
PIThread * ct = (PIThread * )t;
ct->running = true;
ct->begin();
raiseEvent(ct, "started");
if (ct->lockRun) ct->mutex_.lock();
ct->run();
if (ct->lockRun) ct->mutex_.unlock();
raiseEvent(ct, "stopped");
ct->end();
ct->running = false;
//cout << "thread " << t << " exiting ... " << endl;