git-svn-id: svn://db.shs.com.ru/pip@370 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2017-04-17 08:52:24 +00:00
parent 9c59a27999
commit f76510e74a
21 changed files with 101 additions and 122 deletions

View File

@@ -44,6 +44,7 @@ option(DEBUG "Build with -g3" 0)
set(CMAKE_BUILD_TYPE "Release")
set(LIBS)
if(DEBUG)
add_definitions(-DPIP_DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
endif()

View File

@@ -107,12 +107,13 @@ PIConsole::PIConsole(bool startNow, PIKbdListener::KBFunc slot): PIThread() {
tabs.reserve(16);
addTab("main");
listener = new PIKbdListener(key_event, this);
peer_timer = new PITimer();
peer = 0;
server_mode = pause_ = false;
state = Disconnected;
peer_timer.addDelimiter(20);
peer_timer.setName("__S__PIConsole::peer_timer");
CONNECT2(void, void * , int, &peer_timer, tickEvent, this, peerTimer);
peer_timer->addDelimiter(20);
peer_timer->setName("__S__PIConsole::peer_timer");
CONNECT2(void, void * , int, peer_timer, tickEvent, this, peerTimer);
if (startNow) start();
}
@@ -123,6 +124,7 @@ PIConsole::~PIConsole() {
stop();
clearTabs(false);
delete listener;
delete peer_timer;
#ifdef WINDOWS
SetConsoleMode(PRIVATE->hOut, PRIVATE->smode);
SetConsoleTextAttribute(PRIVATE->hOut, PRIVATE->dattr);
@@ -882,14 +884,14 @@ void PIConsole::startServer(const PIString & name) {
peer = new PIPeer("_rcs_:" + name);
CONNECT2(void, const PIString & , const PIByteArray &, peer, dataReceivedEvent, this, peerReceived);
CONNECT1(void, const PIString & , peer, peerDisconnectedEvent, this, peerDisconnectedEvent);
peer_timer.start(50.);
peer_timer->start(50.);
serverSendInfo();
}
void PIConsole::stopPeer() {
remote_clients.clear();
peer_timer.stop();
peer_timer->stop();
if (peer != 0) delete peer;
peer = 0;
state = Disconnected;
@@ -914,7 +916,7 @@ void PIConsole::listenServers() {
srand(PISystemTime::current().nanoseconds);
peer = new PIPeer("_rcc_:" + PIDateTime::current().toString("hhmmssddMMyy_") + PIString::fromNumber(rand()));
CONNECT2(void, const PIString & , const PIByteArray &, peer, dataReceivedEvent, this, peerReceived);
peer_timer.start(100.);
peer_timer->start(100.);
}

View File

@@ -24,12 +24,12 @@
#define PICONSOLE_H
#include "pikbdlistener.h"
#include "pitimer.h"
class PIProtocol;
class PIDiagnostics;
class PISystemMonitor;
class PIPeer;
class PITimer;
class PIP_EXPORT PIConsole: public PIThread
{
@@ -444,7 +444,7 @@ public:
uint cur_tab, col_cnt;
PIPeer * peer;
PITimer peer_timer;
PITimer * peer_timer;
PITimeMeasurer peer_tm;
PIString server_name;
bool server_mode, pause_;

View File

@@ -23,7 +23,6 @@
#ifndef PITERMINAL_H
#define PITERMINAL_H
#include "pithread.h"
#include "pikbdlistener.h"
#include "piscreentypes.h"

View File

@@ -27,8 +27,14 @@
#define PICONTAINERS_H
#include "picout.h"
#include <cassert>
#ifdef PIP_DEBUG
# include <cassert>
#endif
#ifndef assert
# define assert(x)
#endif
#include <malloc.h>
#include <string.h>
#ifndef PIP_MEMALIGN_BYTES
# define PIP_MEMALIGN_BYTES (sizeof(void*)*4)
#endif

View File

@@ -1,6 +1,6 @@
#ifndef PILIST_H
#define PILIST_H
#include "pivector.h"
#include "pibase.h"
#include <list>
template<typename Type, typename Allocator = std::allocator<Type> >

View File

@@ -25,7 +25,6 @@
#ifndef PIVECTOR_H
#define PIVECTOR_H
#include "piincludes.h"
#include "picontainers.h"
#if !defined(PIP_CONTAINERS_STL) || defined(DOXYGEN)

View File

@@ -91,9 +91,7 @@
#endif
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <cstddef>
#ifdef WINDOWS
# ifdef CC_VC
# define SHUT_RDWR 2
@@ -105,7 +103,6 @@
# endif
typedef int socklen_t;
extern long long __pi_perf_freq;
inline int random() {return rand();}
#endif
#ifdef ANDROID

View File

@@ -20,12 +20,10 @@
#ifndef PICOREMODULE_H
#define PICOREMODULE_H
#include "pistring.h"
#include "picollection.h"
#include "piobject.h"
#include "pistatemachine.h"
#include "pitime.h"
#include "pivariant.h"
#include "picli.h"
#include "pichunkstream.h"
#include "pipropertystorage.h"

View File

@@ -16,10 +16,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "piincludes_p.h"
#include "pistring.h"
#include <iostream>
#include <string.h>
#ifdef PIP_ICU
# include "unicode/ucnv.h"
#endif

View File

@@ -24,7 +24,6 @@
#define PIBASETRANSFER_H
#include "picrc.h"
#include "pitimer.h"
#include "pidiagnostics.h"
class PIBaseTransfer: public PIObject

View File

@@ -29,7 +29,6 @@
#include "pitimer.h"
#include "piconfig.h"
#include "pifile.h"
#include "math.h"
class PIProtocol; /// DEPRECATED

View File

@@ -1,30 +0,0 @@
/*! \file pimath.h
* \brief Many mathematical functions and classes
*/
/*
PIP - Platform Independent Primitives
Many mathematical functions and classes
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIMATH_H
#define PIMATH_H
#include "pimathsolver.h"
#include "pistatistic.h"
#include "pifft.h"
#endif // PIMATH_H

View File

@@ -89,6 +89,9 @@
#ifndef M_GRAVITY_CONST
# define M_GRAVITY_CONST 398600.4418e9;
#endif
#ifdef WINDOWS
inline int random() {return rand();}
#endif
using std::complex;
@@ -163,7 +166,6 @@ inline PIByteArray & operator >>(PIByteArray & s, complexd & v) {double t0, t1;
inline PIByteArray & operator >>(PIByteArray & s, complexld & v) {ldouble t0, t1; s >> t0; s >> t1; v = complexld(t0, t1); return s;}
void randomize();
// [-1 ; 1]
inline double randomd() {return (double)
#ifdef QNX

View File

@@ -24,6 +24,7 @@
#define PIMATHVECTOR_H
#include "pimathbase.h"
#include <stdarg.h>
template<uint Cols, uint Rows, typename Type>
class PIMathMatrixT;

View File

@@ -17,6 +17,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "piincludes.h"
#include "pisignals.h"
#ifdef BLACKBERRY
# include <signal.h>

View File

@@ -23,7 +23,7 @@
#ifndef PISIGNALS_H
#define PISIGNALS_H
#include "piincludes.h"
#include "piflags.h"
class PIP_EXPORT PISignals
{

View File

@@ -21,10 +21,23 @@
#include "pisystemmonitor.h"
#include "pisysteminfo.h"
#ifdef WINDOWS
# include <psapi.h>
# include <tlhelp32.h>
#endif
PRIVATE_DEFINITION_START(PISystemMonitor)
#ifndef WINDOWS
llong cpu_u_cur, cpu_u_prev, cpu_s_cur, cpu_s_prev;
#else
HANDLE hProc;
PROCESS_MEMORY_COUNTERS mem_cnt;
PISystemTime tm_kernel, tm_user;
PITimeMeasurer tm;
#endif
PRIVATE_DEFINITION_END(PISystemMonitor)
PISystemMonitor::PISystemMonitor(): PIThread() {
pID_ = cycle = 0;
cpu_count = PISystemInfo::instance()->processorsCount;
@@ -35,8 +48,8 @@ PISystemMonitor::PISystemMonitor(): PIThread() {
page_size = getpagesize();
# endif
#else
hProc = 0;
mem_cnt.cb = sizeof(mem_cnt);
PRIVATE->hProc = 0;
PRIVATE->mem_cnt.cb = sizeof(PRIVATE->mem_cnt);
#endif
setName("system_monitor");
}
@@ -66,12 +79,12 @@ bool PISystemMonitor::startOnProcess(int pID) {
}
cycle = -1;
#else
hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pID_);
if (hProc == 0) {
PRIVATE->hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pID_);
if (PRIVATE->hProc == 0) {
piCoutObj << "Can`t open process with ID = " << pID_ << "," << errorString();
return false;
}
tm.reset();
PRIVATE->tm.reset();
#endif
return start(1000);
}
@@ -80,9 +93,9 @@ bool PISystemMonitor::startOnProcess(int pID) {
void PISystemMonitor::stop() {
PIThread::stop();
#ifdef WINDOWS
if (hProc != 0) {
CloseHandle(hProc);
hProc = 0;
if (PRIVATE->hProc != 0) {
CloseHandle(PRIVATE->hProc);
PRIVATE->hProc = 0;
}
#endif
@@ -112,17 +125,17 @@ void PISystemMonitor::run() {
stat.group_ID = sl[3].toInt();
stat.session_ID = sl[4].toInt();
if (cycle < 0) {
cpu_u_prev = cpu_u_cur = sl[12].toLLong();
cpu_s_prev = cpu_s_cur = sl[13].toLLong();
PRIVATE->cpu_u_prev = PRIVATE->cpu_u_cur = sl[12].toLLong();
PRIVATE->cpu_s_prev = PRIVATE->cpu_s_cur = sl[13].toLLong();
}
cycle++;
//if (cycle >= 4) {
cpu_u_prev = cpu_u_cur;
cpu_s_prev = cpu_s_cur;
cpu_u_cur = sl[12].toLLong();
cpu_s_cur = sl[13].toLLong();
stat.cpu_load_system = cpu_s_cur - cpu_s_prev;
stat.cpu_load_user = cpu_u_cur - cpu_u_prev;
PRIVATE->cpu_u_prev = PRIVATE->cpu_u_cur;
PRIVATE->cpu_s_prev = PRIVATE->cpu_s_cur;
PRIVATE->cpu_u_cur = sl[12].toLLong();
PRIVATE->cpu_s_cur = sl[13].toLLong();
stat.cpu_load_system = PRIVATE->cpu_s_cur - PRIVATE->cpu_s_prev;
stat.cpu_load_user = PRIVATE->cpu_u_cur - PRIVATE->cpu_u_prev;
stat.cpu_load_system /= cpu_count;
stat.cpu_load_user /= cpu_count;
cycle = 0;
@@ -143,10 +156,10 @@ void PISystemMonitor::run() {
stat.ID = pID_;
// HMODULE hMod;
// DWORD cbNeeded;
if (GetProcessMemoryInfo(hProc, &mem_cnt, sizeof(mem_cnt)) != 0) {
stat.physical_memsize = mem_cnt.WorkingSetSize;
if (GetProcessMemoryInfo(PRIVATE->hProc, &PRIVATE->mem_cnt, sizeof(PRIVATE->mem_cnt)) != 0) {
stat.physical_memsize = PRIVATE->mem_cnt.WorkingSetSize;
}
stat.priority = GetPriorityClass(hProc);
stat.priority = GetPriorityClass(PRIVATE->hProc);
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, pID_);
int thcnt = 0;
if (snap != 0) {
@@ -164,12 +177,12 @@ void PISystemMonitor::run() {
CloseHandle(snap);
}
FILETIME ft0, ft1, ft_kernel, ft_user;
double el_s = tm.elapsed_s() * cpu_count / 100.;
if (GetProcessTimes(hProc, &ft0, &ft1, &ft_kernel, &ft_user) != 0) {
double el_s = PRIVATE->tm.elapsed_s() * cpu_count / 100.;
if (GetProcessTimes(PRIVATE->hProc, &ft0, &ft1, &ft_kernel, &ft_user) != 0) {
PISystemTime tm_kernel_c(ft_kernel), tm_user_c(ft_user);
if (cycle < 0) {
tm_kernel = tm_kernel_c;
tm_user = tm_user_c;
PRIVATE->tm_kernel = tm_kernel_c;
PRIVATE->tm_user = tm_user_c;
}
//cycle++;
cycle = 0;
@@ -177,16 +190,16 @@ void PISystemMonitor::run() {
stat.cpu_load_system = 0.f;
stat.cpu_load_user = 0.f;
} else {
stat.cpu_load_system = (tm_kernel_c - tm_kernel).toSeconds() / el_s;
stat.cpu_load_user = (tm_user_c - tm_user).toSeconds() / el_s;
stat.cpu_load_system = (tm_kernel_c - PRIVATE->tm_kernel).toSeconds() / el_s;
stat.cpu_load_user = (tm_user_c - PRIVATE->tm_user).toSeconds() / el_s;
}
tm_kernel = tm_kernel_c;
tm_user = tm_user_c;
PRIVATE->tm_kernel = tm_kernel_c;
PRIVATE->tm_user = tm_user_c;
} else {
stat.cpu_load_system = 0.f;
stat.cpu_load_user = 0.f;
}
tm.reset();
PRIVATE->tm.reset();
#endif
stat.cpu_load_system = piClampf(stat.cpu_load_system, 0.f, 100.f);

View File

@@ -22,9 +22,6 @@
#include "pithread.h"
#include "piprocess.h"
#ifdef WINDOWS
# include <psapi.h>
#endif
class PIP_EXPORT PISystemMonitor: public PIThread
{
@@ -71,14 +68,7 @@ private:
PIFile file, filem;
ProcessStats stat;
int pID_, page_size, cpu_count, cycle;
#ifndef WINDOWS
llong cpu_u_cur, cpu_u_prev, cpu_s_cur, cpu_s_prev;
#else
HANDLE hProc;
PROCESS_MEMORY_COUNTERS mem_cnt;
PISystemTime tm_kernel, tm_user;
PITimeMeasurer tm;
#endif
PRIVATE_DECLARATION
};

View File

@@ -17,12 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pimutex.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
/** \class PIMutex
* \brief Mutex
* \details
@@ -40,6 +34,25 @@
*
* */
#include "pimutex.h"
#ifdef WINDOWS
# include <windef.h>
# include <winbase.h>
#endif
#ifdef BLACKBERRY
# include <pthread.h>
#endif
PRIVATE_DEFINITION_START(PIMutex)
#ifdef WINDOWS
void *
#else
pthread_mutex_t
#endif
mutex;
PRIVATE_DEFINITION_END(PIMutex)
PIMutex::PIMutex(): inited_(false) {
init();
@@ -53,9 +66,9 @@ PIMutex::~PIMutex() {
void PIMutex::lock() {
#ifdef WINDOWS
WaitForSingleObject(mutex, INFINITE);
WaitForSingleObject(PRIVATE->mutex, INFINITE);
#else
pthread_mutex_lock(&mutex);
pthread_mutex_lock(&(PRIVATE->mutex));
#endif
locked = true;
}
@@ -63,9 +76,9 @@ void PIMutex::lock() {
void PIMutex::unlock() {
#ifdef WINDOWS
ReleaseMutex(mutex);
ReleaseMutex(PRIVATE->mutex);
#else
pthread_mutex_unlock(&mutex);
pthread_mutex_unlock(&(PRIVATE->mutex));
#endif
locked = false;
}
@@ -74,9 +87,9 @@ void PIMutex::unlock() {
bool PIMutex::tryLock() {
bool ret =
#ifdef WINDOWS
(WaitForSingleObject(mutex, 0) == WAIT_OBJECT_0);
(WaitForSingleObject(PRIVATE->mutex, 0) == WAIT_OBJECT_0);
#else
(pthread_mutex_trylock(&mutex) == 0);
(pthread_mutex_trylock(&(PRIVATE->mutex)) == 0);
#endif
locked = true;
return ret;
@@ -91,14 +104,14 @@ bool PIMutex::isLocked() const {
void PIMutex::init() {
if (inited_) destroy();
#ifdef WINDOWS
mutex = CreateMutex(0, false, 0);
PRIVATE->mutex = CreateMutex(0, false, 0);
#else
pthread_mutexattr_t attr;
memset(&attr, 0, sizeof(attr));
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
memset(&mutex, 0, sizeof(mutex));
pthread_mutex_init(&mutex, &attr);
memset(&(PRIVATE->mutex), 0, sizeof(PRIVATE->mutex));
pthread_mutex_init(&(PRIVATE->mutex), &attr);
pthread_mutexattr_destroy(&attr);
#endif
locked = false;
@@ -109,10 +122,10 @@ void PIMutex::init() {
void PIMutex::destroy() {
if (inited_) {
#ifdef WINDOWS
if (mutex) CloseHandle(mutex);
mutex = 0;
if (PRIVATE->mutex) CloseHandle(PRIVATE->mutex);
PRIVATE->mutex = 0;
#else
pthread_mutex_destroy(&mutex);
pthread_mutex_destroy(&(PRIVATE->mutex));
#endif
}
locked = inited_ = false;

View File

@@ -24,9 +24,6 @@
#define PIMUTEX_H
#include "piinit.h"
#ifdef BLACKBERRY
# include <pthread.h>
#endif
class PIP_EXPORT PIMutex
{
@@ -62,13 +59,7 @@ private:
void init();
void destroy();
#ifdef WINDOWS
void *
#else
pthread_mutex_t
#endif
mutex;
PRIVATE_DECLARATION
bool inited_;
volatile bool locked;