From f76510e74a8f3f01cc3439a03fac1c9fa5dec329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Mon, 17 Apr 2017 08:52:24 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@370 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- CMakeLists.txt | 1 + src/console/piconsole.cpp | 14 ++++--- src/console/piconsole.h | 4 +- src/console/piterminal.h | 1 - src/containers/picontainers.h | 8 +++- src/containers/pilist.h | 2 +- src/containers/pivector.h | 1 - src/core/pibase.h | 5 +-- src/core/picoremodule.h | 2 - src/core/pistring.cpp | 4 +- src/io/pibasetransfer.h | 1 - src/io/piprotocol.h | 1 - src/math/pimath.h | 30 --------------- src/math/pimathbase.h | 4 +- src/math/pimathvector.h | 1 + src/system/pisignals.cpp | 1 + src/system/pisignals.h | 2 +- src/system/pisystemmonitor.cpp | 69 ++++++++++++++++++++-------------- src/system/pisystemmonitor.h | 12 +----- src/thread/pimutex.cpp | 49 +++++++++++++++--------- src/thread/pimutex.h | 11 +----- 21 files changed, 101 insertions(+), 122 deletions(-) delete mode 100644 src/math/pimath.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b850b266..ac2eafab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/src/console/piconsole.cpp b/src/console/piconsole.cpp index 5c36812f..41799bcc 100644 --- a/src/console/piconsole.cpp +++ b/src/console/piconsole.cpp @@ -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.); } diff --git a/src/console/piconsole.h b/src/console/piconsole.h index 76658653..e25d2bec 100644 --- a/src/console/piconsole.h +++ b/src/console/piconsole.h @@ -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_; diff --git a/src/console/piterminal.h b/src/console/piterminal.h index 8e23c415..bee77052 100644 --- a/src/console/piterminal.h +++ b/src/console/piterminal.h @@ -23,7 +23,6 @@ #ifndef PITERMINAL_H #define PITERMINAL_H -#include "pithread.h" #include "pikbdlistener.h" #include "piscreentypes.h" diff --git a/src/containers/picontainers.h b/src/containers/picontainers.h index dc696a5c..505a7962 100755 --- a/src/containers/picontainers.h +++ b/src/containers/picontainers.h @@ -27,8 +27,14 @@ #define PICONTAINERS_H #include "picout.h" -#include +#ifdef PIP_DEBUG +# include +#endif +#ifndef assert +# define assert(x) +#endif #include +#include #ifndef PIP_MEMALIGN_BYTES # define PIP_MEMALIGN_BYTES (sizeof(void*)*4) #endif diff --git a/src/containers/pilist.h b/src/containers/pilist.h index e18f9678..ea46d72b 100644 --- a/src/containers/pilist.h +++ b/src/containers/pilist.h @@ -1,6 +1,6 @@ #ifndef PILIST_H #define PILIST_H -#include "pivector.h" +#include "pibase.h" #include template > diff --git a/src/containers/pivector.h b/src/containers/pivector.h index 14a8e1d7..441a6995 100755 --- a/src/containers/pivector.h +++ b/src/containers/pivector.h @@ -25,7 +25,6 @@ #ifndef PIVECTOR_H #define PIVECTOR_H -#include "piincludes.h" #include "picontainers.h" #if !defined(PIP_CONTAINERS_STL) || defined(DOXYGEN) diff --git a/src/core/pibase.h b/src/core/pibase.h index 0e58dbcc..c501ccb0 100644 --- a/src/core/pibase.h +++ b/src/core/pibase.h @@ -91,9 +91,7 @@ #endif -#include -#include -#include +#include #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 diff --git a/src/core/picoremodule.h b/src/core/picoremodule.h index 881f6190..96eafec2 100644 --- a/src/core/picoremodule.h +++ b/src/core/picoremodule.h @@ -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" diff --git a/src/core/pistring.cpp b/src/core/pistring.cpp index c6eaa7ee..d2b4a2c0 100755 --- a/src/core/pistring.cpp +++ b/src/core/pistring.cpp @@ -16,10 +16,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#include "piincludes_p.h" #include "pistring.h" -#include -#include #ifdef PIP_ICU # include "unicode/ucnv.h" #endif diff --git a/src/io/pibasetransfer.h b/src/io/pibasetransfer.h index 55b7ae4c..f5001e63 100644 --- a/src/io/pibasetransfer.h +++ b/src/io/pibasetransfer.h @@ -24,7 +24,6 @@ #define PIBASETRANSFER_H #include "picrc.h" -#include "pitimer.h" #include "pidiagnostics.h" class PIBaseTransfer: public PIObject diff --git a/src/io/piprotocol.h b/src/io/piprotocol.h index 1ddab2bd..ad1d46bc 100755 --- a/src/io/piprotocol.h +++ b/src/io/piprotocol.h @@ -29,7 +29,6 @@ #include "pitimer.h" #include "piconfig.h" #include "pifile.h" -#include "math.h" class PIProtocol; /// DEPRECATED diff --git a/src/math/pimath.h b/src/math/pimath.h deleted file mode 100644 index c807ebea..00000000 --- a/src/math/pimath.h +++ /dev/null @@ -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 . -*/ - -#ifndef PIMATH_H -#define PIMATH_H - -#include "pimathsolver.h" -#include "pistatistic.h" -#include "pifft.h" - -#endif // PIMATH_H diff --git a/src/math/pimathbase.h b/src/math/pimathbase.h index 662f4f52..5731f50e 100644 --- a/src/math/pimathbase.h +++ b/src/math/pimathbase.h @@ -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 diff --git a/src/math/pimathvector.h b/src/math/pimathvector.h index 9e2af539..37270471 100644 --- a/src/math/pimathvector.h +++ b/src/math/pimathvector.h @@ -24,6 +24,7 @@ #define PIMATHVECTOR_H #include "pimathbase.h" +#include template class PIMathMatrixT; diff --git a/src/system/pisignals.cpp b/src/system/pisignals.cpp index f1e860b3..8a6c1087 100755 --- a/src/system/pisignals.cpp +++ b/src/system/pisignals.cpp @@ -17,6 +17,7 @@ along with this program. If not, see . */ +#include "piincludes.h" #include "pisignals.h" #ifdef BLACKBERRY # include diff --git a/src/system/pisignals.h b/src/system/pisignals.h index 601fd242..bbe72325 100755 --- a/src/system/pisignals.h +++ b/src/system/pisignals.h @@ -23,7 +23,7 @@ #ifndef PISIGNALS_H #define PISIGNALS_H -#include "piincludes.h" +#include "piflags.h" class PIP_EXPORT PISignals { diff --git a/src/system/pisystemmonitor.cpp b/src/system/pisystemmonitor.cpp index 061de480..57699d9b 100755 --- a/src/system/pisystemmonitor.cpp +++ b/src/system/pisystemmonitor.cpp @@ -21,10 +21,23 @@ #include "pisystemmonitor.h" #include "pisysteminfo.h" #ifdef WINDOWS +# include # include #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); diff --git a/src/system/pisystemmonitor.h b/src/system/pisystemmonitor.h index dc3e9a8c..d1e44da9 100755 --- a/src/system/pisystemmonitor.h +++ b/src/system/pisystemmonitor.h @@ -22,9 +22,6 @@ #include "pithread.h" #include "piprocess.h" -#ifdef WINDOWS -# include -#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 }; diff --git a/src/thread/pimutex.cpp b/src/thread/pimutex.cpp index 0ecccf56..3a271d21 100755 --- a/src/thread/pimutex.cpp +++ b/src/thread/pimutex.cpp @@ -17,12 +17,6 @@ along with this program. If not, see . */ -#include "pimutex.h" -#ifdef WINDOWS -# include -# include -#endif - /** \class PIMutex * \brief Mutex * \details @@ -40,6 +34,25 @@ * * */ +#include "pimutex.h" +#ifdef WINDOWS +# include +# include +#endif +#ifdef BLACKBERRY +# include +#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; diff --git a/src/thread/pimutex.h b/src/thread/pimutex.h index 9f807aba..52bd2a81 100755 --- a/src/thread/pimutex.h +++ b/src/thread/pimutex.h @@ -24,9 +24,6 @@ #define PIMUTEX_H #include "piinit.h" -#ifdef BLACKBERRY -# include -#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;