15.10.2012 - version 0.2.0 - PIIODevice - base of file, ethernet, serial and packets extractor. PIEthernet now support also TCP (client and server). PIConsole now can align labels in each column individually.

This commit is contained in:
peri4
2012-10-15 23:36:18 +04:00
parent 5558add03e
commit cfc5eed75e
64 changed files with 1879 additions and 867 deletions

21
pithread.h Normal file → Executable file
View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Thread
Copyright (C) 2011 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2012 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
@@ -30,8 +30,11 @@ inline void msleep(int msecs) {Sleep(msecs);}
inline void msleep(int msecs) {usleep(msecs * 1000);}
#endif
typedef void (*ThreadFunc)(void * );
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();
@@ -52,11 +55,16 @@ public:
//bool start(int timer_delay = -1);
EVENT_HANDLER0(PIThread, bool, start) {return start(-1);}
EVENT_HANDLER1(PIThread, bool, start, int, timer_delay);
EVENT_HANDLER1(PIThread, bool, start, ThreadFunc, func) {ret_func = func; return start(-1);}
EVENT_HANDLER2(PIThread, bool, start, ThreadFunc, func, int, timer_delay) {ret_func = func; return start(timer_delay);}
EVENT_HANDLER0(PIThread, bool, startOnce);
EVENT_HANDLER1(PIThread, bool, startOnce, ThreadFunc, func) {ret_func = func; return startOnce();}
EVENT_HANDLER0(PIThread, void, stop) {stop(false);}
EVENT_HANDLER1(PIThread, void, stop, bool, wait) {terminating = true; if (wait) waitForFinish();}
EVENT_HANDLER0(PIThread, void, terminate) {terminate(false);}
EVENT_HANDLER1(PIThread, void, terminate, bool, hard);
void setData(void * d) {data_ = d;}
void setSlot(ThreadFunc func) {ret_func = func;}
void setPriority(PIThread::Priority prior);
PIThread::Priority priority() const {return priority_;}
bool isRunning() const {return running;}
@@ -69,19 +77,20 @@ public:
EVENT_HANDLER0(PIThread, void, unlock) {mutex_.unlock();}
PIMutex & mutex() {return mutex_;}
private:
virtual void begin() {;} // executed at start
virtual void run() {;} // main loop
virtual void end() {;} // executed at finish
protected:
static void * thread_function(void * t);
static void * thread_function_once(void * t);
virtual void begin() {;} // executed at start
virtual void run() {;} // main loop executed with "timer_delay" timeout
virtual void end() {;} // executed at finish
volatile bool terminating, running, lockRun;
int timer, policy;
void * data_;
PIMutex mutex_;
PIThread::Priority priority_;
ThreadFunc ret_func;
#ifndef WINDOWS
pthread_t thread;
sched_param sparam;