18.03.2013 - Bug fixes, add in/out speed diagnostic to PIProtocol, fixed PIConsole tab switch segfault, PIObject EVENT / EVENT_HANDLER mechanism update - new EVENT macros that use EVENT_HANDLER with raiseEvent implementation.

This allow compile check event for CONNECT and use EVENT as CONNECT target, also raise event now is simple execute EVENT function.
This commit is contained in:
peri4
2013-03-18 12:07:44 +04:00
parent cfc5eed75e
commit 66c53a27fc
72 changed files with 4407 additions and 960 deletions

24
pithread.h Executable file → Normal file
View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Thread
Copyright (C) 2012 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2013 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -29,14 +29,31 @@ inline void msleep(int msecs) {Sleep(msecs);}
#else
inline void msleep(int msecs) {usleep(msecs * 1000);}
#endif
void piUSleep(int usecs); // on !Windows consider constant "usleep" offset
inline void piMSleep(int msecs) {piUSleep(msecs * 1000);} // on !Windows consider constant "usleep" offset
typedef void (*ThreadFunc)(void * );
/// events:
/// void started()
/// void stopped()
///
/// handlers:
/// bool start(int timer_delay = -1)
/// bool start(ThreadFunc func, int timer_delay = -1)
/// bool startOnce()
/// bool startOnce(ThreadFunc func)
/// void stop(bool wait = false)
/// void terminate(bool hard = false)
/// bool waitForStart(int timeout_msecs = -1)
/// bool waitForFinish(int timeout_msecs = -1)
/// void lock()
/// void unlock()
class PIThread: public PIObject {
public:
PIThread(void * data, ThreadFunc func, bool startNow = false, int timer_delay = -1);
PIThread(bool startNow = false, int timer_delay = -1);
~PIThread();
virtual ~PIThread();
#ifdef QNX
enum Priority {piHighest = 12,
@@ -76,6 +93,9 @@ public:
EVENT_HANDLER0(PIThread, void, lock) {mutex_.lock();}
EVENT_HANDLER0(PIThread, void, unlock) {mutex_.unlock();}
PIMutex & mutex() {return mutex_;}
EVENT(PIThread, started)
EVENT(PIThread, stopped)
protected:
static void * thread_function(void * t);