version 0.5.0_alpha

git-svn-id: svn://db.shs.com.ru/pip@8 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-03-10 10:13:18 +00:00
parent b1f651ab62
commit c11bc3b3b8
697 changed files with 18150 additions and 18839 deletions

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Mutex
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 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
@@ -57,3 +57,30 @@ PIMutex::~PIMutex() {
pthread_mutex_destroy(&mutex);
#endif
}
void PIMutex::lock() {
#ifdef WINDOWS
WaitForSingleObject(mutex, INFINITE);
#else
pthread_mutex_lock(&mutex);
#endif
}
void PIMutex::unlock() {
#ifdef WINDOWS
ReleaseMutex(mutex);
#else
pthread_mutex_unlock(&mutex);
#endif
}
bool PIMutex::tryLock() {
#ifdef WINDOWS
return (WaitForSingleObject(mutex, 0) == WAIT_OBJECT_0);
#else
return (pthread_mutex_trylock(&mutex) == 0);
#endif
}

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Mutex
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 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
@@ -38,36 +38,16 @@ public:
//! \brief Lock mutex
//! \details If mutex is unlocked it set to locked state and returns immediate.
//! If mutex is already locked function blocks until mutex will be unlocked
void lock() {
#ifdef WINDOWS
WaitForSingleObject(mutex, INFINITE);
#else
pthread_mutex_lock(&mutex);
#endif
}
void lock();
//! \brief Unlock mutex
//! \details In any case this function returns immediate
void unlock() {
#ifdef WINDOWS
ReleaseMutex(mutex);
#else
pthread_mutex_unlock(&mutex);
#endif
}
void unlock();
//! \brief Try to lock mutex
//! \details If mutex is unlocked it set to locked state and returns "true" immediate.
//! If mutex is already locked function returns immediate an returns "false"
bool tryLock() {
#ifdef WINDOWS
return (WaitForSingleObject(mutex, 0) == WAIT_OBJECT_0);
#else
return (pthread_mutex_trylock(&mutex) == 0);
#endif
}
bool tryLock();
private:
#ifdef WINDOWS

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Thread
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 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
@@ -19,6 +19,10 @@
#include "pithread.h"
#include "pisystemtests.h"
#include <signal.h>
#ifdef WINDOWS
void __PISetTimerResolution() {if (setTimerResolutionAddr == NULL) return; ULONG ret; setTimerResolutionAddr(1, TRUE, &ret);}
#endif
/*! \class PIThread

View File

@@ -6,7 +6,7 @@
/*
PIP - Platform Independent Primitives
Thread
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 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
@@ -25,7 +25,6 @@
#ifndef PITHREAD_H
#define PITHREAD_H
#include <signal.h>
#include "piinit.h"
#include "pimutex.h"
#include "piobject.h"

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Timer
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 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
@@ -18,6 +18,9 @@
*/
#include "pitimer.h"
#ifdef PIP_TIMER_RT
# include <csignal>
#endif
/*! \class PITimer
@@ -207,51 +210,66 @@ void _PITimerImp_Thread::adjustTimes() {
#ifdef PIP_TIMER_RT
void threadFuncS(sigval sv) {((_PITimerImp_RT * )sv.sival_ptr)->tfunc(((_PITimerImp_RT * )sv.sival_ptr)->parent);}
struct _PITimerImp_RT_Private_ {
itimerspec spec;
timer_t tt;
sigevent se;
};
_PITimerImp_RT::_PITimerImp_RT() {
//piCout << "new _PITimerImp_RT";
priv = new _PITimerImp_RT_Private_();
priv->tt = 0;
ti = -1;
tt = 0;
memset(&se, 0, sizeof(se));
se.sigev_notify = SIGEV_THREAD;
se.sigev_value.sival_ptr = this;
se.sigev_notify_function = threadFuncS;
se.sigev_notify_attributes = 0;
memset(&(priv->se), 0, sizeof(priv->se));
priv->se.sigev_notify = SIGEV_THREAD;
priv->se.sigev_value.sival_ptr = this;
priv->se.sigev_notify_function = threadFuncS;
priv->se.sigev_notify_attributes = 0;
}
_PITimerImp_RT::~_PITimerImp_RT() {
stop();
delete priv;
}
bool _PITimerImp_RT::startTimer(double interval_ms) {
int flags(0);
spec.it_interval.tv_nsec = ((int)(interval_ms * 1000) % 1000000) * 1000;
spec.it_interval.tv_sec = (time_t)(interval_ms / 1000);
priv->spec.it_interval.tv_nsec = ((int)(interval_ms * 1000) % 1000000) * 1000;
priv->spec.it_interval.tv_sec = (time_t)(interval_ms / 1000);
if (deferred_) {
if (deferred_mode) {
PISystemTime dtm = deferred_datetime.toSystemTime();
spec.it_value.tv_nsec = dtm.nanoseconds;
spec.it_value.tv_sec = dtm.seconds;
priv->spec.it_value.tv_nsec = dtm.nanoseconds;
priv->spec.it_value.tv_sec = dtm.seconds;
flags = TIMER_ABSTIME;
} else {
spec.it_value.tv_nsec = ((int)(deferred_delay * 1000) % 1000000) * 1000;
spec.it_value.tv_sec = (time_t)(deferred_delay / 1000);
priv->spec.it_value.tv_nsec = ((int)(deferred_delay * 1000) % 1000000) * 1000;
priv->spec.it_value.tv_sec = (time_t)(deferred_delay / 1000);
}
} else {
spec.it_value = spec.it_interval;
priv->spec.it_value = priv->spec.it_interval;
}
ti = timer_create(CLOCK_REALTIME, &se, &tt);
ti = timer_create(CLOCK_REALTIME, &(priv->se), &(priv->tt));
//cout << "***create timer " << msecs << " msecs\n";
if (ti == -1) {
piCout << "Can`t create RT timer for " << interval_ms << " msecs: " << errorString();
return false;
}
timer_settime(tt, flags, &spec, 0);
timer_settime(priv->tt, flags, &(priv->spec), 0);
return true;
}
bool _PITimerImp_RT::stopTimer() {
if (ti < 0) return true;
timer_delete(tt);
timer_delete(priv->tt);
ti = -1;
tt = 0;
priv->tt = 0;
return true;
}

View File

@@ -4,7 +4,7 @@
/*
PIP - Platform Independent Primitives
Timer
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 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
@@ -54,8 +54,11 @@ public:
bool stop();
protected:
typedef void(*TickFunc)(PITimer*);
TickFunc tfunc;
PITimer * parent;
protected:
virtual bool startTimer(double interval_ms) = 0;
virtual bool stopTimer() = 0;
@@ -64,8 +67,6 @@ protected:
bool deferred_, deferred_mode; // mode: true - date, false - delay
volatile bool running_;
PIDateTime deferred_datetime;
PITimer * parent;
TickFunc tfunc;
};
@@ -90,20 +91,18 @@ private:
#ifdef PIP_TIMER_RT
struct _PITimerImp_RT_Private_;
class _PITimerImp_RT: public _PITimerBase {
public:
_PITimerImp_RT();
virtual ~_PITimerImp_RT() {stop();}
virtual ~_PITimerImp_RT();
protected:
private:
virtual bool startTimer(double interval_ms);
virtual bool stopTimer();
static void threadFuncS(sigval sv) {((_PITimerImp_RT * )sv.sival_ptr)->tfunc(((_PITimerImp_RT * )sv.sival_ptr)->parent);}
int ti;
itimerspec spec;
timer_t tt;
sigevent se;
_PITimerImp_RT_Private_ * priv;
};
#endif
@@ -259,7 +258,7 @@ public:
* \brief Start timer with \b interval_msecs loop delay after \b start_datetime date and time.
* \details Timer wait until \b start_datetime and then normally starts with
* \b interval_msecs loop delay. */
//! \fn void clearDelimiters()
//! \brief Remove all frequency delimiters