Compare commits

5 Commits

Author SHA1 Message Date
60d2a83df5 android (maybe some other *nix) fix 2025-01-10 20:46:33 +03:00
7757ac10ec add PIP_BUILD_<MODULE> options for PIP build to force disabling modules 2025-01-09 17:36:40 +03:00
f334a6603f adopt for new MinGW 2025-01-06 12:55:44 +03:00
15548de79c version 4.5.0
PIThread::stopAndWait now returns bool
PIKbdListener on Linux now use piwaitevent_p and can immediately stop
new base method piZeroMemory, also migrate all "memset 0" to piZeroMemory
2024-12-29 11:48:24 +03:00
49713ddc57 PIThread now setup itself in thread func 2024-12-29 10:50:38 +03:00
30 changed files with 324 additions and 244 deletions

View File

@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
project(PIP)
set(PIP_MAJOR 4)
set(PIP_MINOR 4)
set(PIP_REVISION 1)
set(PIP_MINOR 5)
set(PIP_REVISION 0)
set(PIP_SUFFIX )
set(PIP_COMPANY SHS)
set(PIP_DOMAIN org.SHS)
@@ -94,6 +94,8 @@ set(PIP_EXPORTS)
set(PIP_SRC_MODULES "console;crypt;compress;usb;fftw;opencl;io_utils;client_server;cloud;lua;http_client;http_server")
foreach(_m ${PIP_SRC_MODULES})
set(PIP_MSG_${_m} "no")
string(TOUPPER "${_m}" _mu)
option(PIP_BUILD_${_mu} "Build \"${_m}\" module" ON)
endforeach()
macro(pip_module NAME LIBS LABEL INCLUDES SOURCES MSG)
@@ -392,142 +394,163 @@ endif()
if (NOT CROSSTOOLS)
if (NOT PIP_FREERTOS)
if (PIP_BUILD_CONSOLE)
pip_module(console "" "PIP console support" "" "" "")
endif()
pip_module(console "" "PIP console support" "" "" "")
pip_find_lib(usb)
if(usb_FOUND)
pip_module(usb "usb" "PIP usb support" "" "" "")
if (PIP_BUILD_USB)
pip_find_lib(usb)
if(usb_FOUND)
pip_module(usb "usb" "PIP usb support" "" "" "")
endif()
endif()
pip_find_lib(zlib NAMES z zlib)
if(zlib_FOUND)
pip_module(compress "zlib" "PIP compression support" "" "" "")
if (PIP_BUILD_COMPRESS)
pip_find_lib(zlib NAMES z zlib)
if(zlib_FOUND)
pip_module(compress "zlib" "PIP compression support" "" "" "")
endif()
endif()
pip_find_lib(sodium)
if(sodium_FOUND)
pip_module(crypt "sodium" "PIP crypt support" "" "" "")
pip_module(client_server "pip_io_utils" "PIP client-server helper" "" "" "")
pip_module(cloud "pip_io_utils" "PIP cloud support" "" "" "")
if (PIP_BUILD_CRYPT)
pip_find_lib(sodium)
if(sodium_FOUND)
pip_module(crypt "sodium" "PIP crypt support" "" "" "")
pip_module(client_server "pip_io_utils" "PIP client-server helper" "" "" "")
pip_module(cloud "pip_io_utils" "PIP cloud support" "" "" "")
endif()
endif()
# Check if PIP support fftw3 for PIFFT using in math module
set(FFTW_LIB_NAME fftw3)
set(FFTW_LIB_SUFFIXES "" "f" "l" "q")
set(FFTW_LIB_SUFFIXES2 "" "-3")
set(FFTW_LIBS)
set(FFTW_ABS_LIBS)
set(CMAKE_REQUIRED_INCLUDES fftw3.h)
foreach(FFTW_S_ IN LISTS FFTW_LIB_SUFFIXES)
set(FFTW_BREAK false)
foreach(FFTW_S2_ IN LISTS FFTW_LIB_SUFFIXES2)
if(NOT FFTW_BREAK)
set(FFTW_CLN "${FFTW_LIB_NAME}${FFTW_S_}${FFTW_S2_}")
set(FFTW_CLNT "${FFTW_LIB_NAME}${FFTW_S_}_threads${FFTW_S2_}")
find_library(${FFTW_CLN}_LIBRARIES ${FFTW_CLN})
find_library(${FFTW_CLNT}_LIBRARIES ${FFTW_CLNT})
set(${FFTW_CLN}_FOUND FALSE)
set(${FFTW_CLNT}_FOUND FALSE)
if(${FFTW_CLN}_LIBRARIES)
set(${FFTW_CLN}_FOUND TRUE)
list(APPEND FFTW_LIBS "${FFTW_CLN}")
list(APPEND FFTW_ABS_LIBS "${${FFTW_CLN}_LIBRARIES}")
set(${FFTW_CLN}_CTS "${FFTW_CLN}")
if(${FFTW_CLNT}_FLIBRARIES)
set(${FFTW_CLNT}_FOUND TRUE)
list(APPEND FFTW_LIBS "${FFTW_CLNT}")
list(APPEND FFTW_ABS_LIBS "${${FFTW_CLNT}_LIBRARIES}")
list(APPEND ${FFTW_CLN}_CTS "${FFTW_CLNT}")
endif()
set(CMAKE_REQUIRED_LIBRARIES ${${FFTW_CLN}_CTS})
CHECK_FUNCTION_EXISTS(fftw${FFTW_S_}_make_planner_thread_safe ${FFTW_CLN}_TSFE)
add_definitions(-DPIP_FFTW${FFTW_S_})
if(${FFTW_CLN}_TSFE)
add_definitions(-DPIP_FFTW${FFTW_S_}_THREADSAFE)
else()
message(STATUS "Warning: PIFFTW${FFTW_S_}::preparePlan was not threadsafe")
if (PIP_BUILD_FFTW)
# Check if PIP support fftw3 for PIFFT using in math module
set(FFTW_LIB_NAME fftw3)
set(FFTW_LIB_SUFFIXES "" "f" "l" "q")
set(FFTW_LIB_SUFFIXES2 "" "-3")
set(FFTW_LIBS)
set(FFTW_ABS_LIBS)
set(CMAKE_REQUIRED_INCLUDES fftw3.h)
foreach(FFTW_S_ IN LISTS FFTW_LIB_SUFFIXES)
set(FFTW_BREAK false)
foreach(FFTW_S2_ IN LISTS FFTW_LIB_SUFFIXES2)
if(NOT FFTW_BREAK)
set(FFTW_CLN "${FFTW_LIB_NAME}${FFTW_S_}${FFTW_S2_}")
set(FFTW_CLNT "${FFTW_LIB_NAME}${FFTW_S_}_threads${FFTW_S2_}")
find_library(${FFTW_CLN}_LIBRARIES ${FFTW_CLN})
find_library(${FFTW_CLNT}_LIBRARIES ${FFTW_CLNT})
set(${FFTW_CLN}_FOUND FALSE)
set(${FFTW_CLNT}_FOUND FALSE)
if(${FFTW_CLN}_LIBRARIES)
set(${FFTW_CLN}_FOUND TRUE)
list(APPEND FFTW_LIBS "${FFTW_CLN}")
list(APPEND FFTW_ABS_LIBS "${${FFTW_CLN}_LIBRARIES}")
set(${FFTW_CLN}_CTS "${FFTW_CLN}")
if(${FFTW_CLNT}_FLIBRARIES)
set(${FFTW_CLNT}_FOUND TRUE)
list(APPEND FFTW_LIBS "${FFTW_CLNT}")
list(APPEND FFTW_ABS_LIBS "${${FFTW_CLNT}_LIBRARIES}")
list(APPEND ${FFTW_CLN}_CTS "${FFTW_CLNT}")
endif()
set(CMAKE_REQUIRED_LIBRARIES ${${FFTW_CLN}_CTS})
CHECK_FUNCTION_EXISTS(fftw${FFTW_S_}_make_planner_thread_safe ${FFTW_CLN}_TSFE)
add_definitions(-DPIP_FFTW${FFTW_S_})
if(${FFTW_CLN}_TSFE)
add_definitions(-DPIP_FFTW${FFTW_S_}_THREADSAFE)
else()
message(STATUS "Warning: PIFFTW${FFTW_S_}::preparePlan was not threadsafe")
endif()
endif()
endif()
endif()
endforeach()
endforeach()
endforeach()
if(FFTW_LIBS)
pip_module(fftw "${FFTW_LIBS}" "PIP FFTW support" "" "" "")
endif()
if (NOT "x${MINGW_INCLUDE}" STREQUAL "x")
list(APPEND CMAKE_INCLUDE_PATH "${MINGW_INCLUDE}")
endif()
find_package(OpenCL QUIET) #OpenCL_VERSION_STRING
if(OpenCL_FOUND)
set(_opencl_inc "${OpenCL_INCLUDE_DIRS}")
if(APPLE)
set(_opencl_inc "${OpenCL_INCLUDE_DIRS}/Headers")
if(FFTW_LIBS)
pip_module(fftw "${FFTW_LIBS}" "PIP FFTW support" "" "" "")
endif()
pip_module(opencl "OpenCL" "PIP OpenCL support" "${_opencl_inc}" "" " (${OpenCL_VERSION_STRING})")
endif()
if(sodium_FOUND)
pip_module(io_utils "pip_crypt" "PIP I/O support" "" "" " (+crypt)")
else()
pip_module(io_utils "" "PIP I/O support" "" "" "")
endif()
# Lua module
set(_lua_src_dir "${CMAKE_CURRENT_SOURCE_DIR}/3rd/lua")
set(_lua_bri_dir "${CMAKE_CURRENT_SOURCE_DIR}/libs/lua/3rd")
set(_lua_src_hdr "${_lua_src_dir}/lua.hpp" "${_lua_src_dir}/lua.h" "${_lua_src_dir}/luaconf.h" "${_lua_src_dir}/lualib.h")
pip_module(lua "" "PIP Lua support" "${_lua_src_dir};${_lua_bri_dir}" "${_lua_src_dir}" " (internal)")
target_include_directories(pip_lua PUBLIC "${_lua_src_dir}" "${_lua_bri_dir}")
if (WIN32)
target_compile_definitions(pip_lua PRIVATE LUA_BUILD_AS_DLL LUA_CORE)
endif()
list(APPEND HDR_DIRS "${_lua_bri_dir}/LuaBridge")
list(APPEND HDRS ${_lua_src_hdr})
# libmicrohttpd
pip_find_lib(microhttpd HINTS "${MINGW_LIB}")
if (microhttpd_FOUND)
set(_microhttpd_add_libs microhttpd)
if(WIN32)
if("${C_COMPILER}" STREQUAL "cl.exe")
else()
list(APPEND _microhttpd_add_libs ws2_32)
if (PIP_BUILD_OPENCL)
if (NOT "x${MINGW_INCLUDE}" STREQUAL "x")
list(APPEND CMAKE_INCLUDE_PATH "${MINGW_INCLUDE}")
endif()
find_package(OpenCL QUIET) #OpenCL_VERSION_STRING
if(OpenCL_FOUND)
set(_opencl_inc "${OpenCL_INCLUDE_DIRS}")
if(APPLE)
set(_opencl_inc "${OpenCL_INCLUDE_DIRS}/Headers")
endif()
pip_module(opencl "OpenCL" "PIP OpenCL support" "${_opencl_inc}" "" " (${OpenCL_VERSION_STRING})")
endif()
endif()
if (PIP_BUILD_IO_UTILS)
if(sodium_FOUND)
pip_module(io_utils "pip_crypt" "PIP I/O support" "" "" " (+crypt)")
else()
list(APPEND _microhttpd_add_libs dl)
find_library(tls_lib gnutls)
if (tls_lib)
set(gnutls_FOUND TRUE)
set(gnutls_LIBRARIES "${tls_lib}")
list(APPEND _microhttpd_add_libs gnutls)
endif()
if(DEFINED ENV{QNX_HOST})
list(APPEND _microhttpd_add_libs socket)
pip_module(io_utils "" "PIP I/O support" "" "" "")
endif()
endif()
if (PIP_BUILD_LUA)
# Lua module
set(_lua_src_dir "${CMAKE_CURRENT_SOURCE_DIR}/3rd/lua")
set(_lua_bri_dir "${CMAKE_CURRENT_SOURCE_DIR}/libs/lua/3rd")
set(_lua_src_hdr "${_lua_src_dir}/lua.hpp" "${_lua_src_dir}/lua.h" "${_lua_src_dir}/luaconf.h" "${_lua_src_dir}/lualib.h")
pip_module(lua "" "PIP Lua support" "${_lua_src_dir};${_lua_bri_dir}" "${_lua_src_dir}" " (internal)")
target_include_directories(pip_lua PUBLIC "${_lua_src_dir}" "${_lua_bri_dir}")
if (WIN32)
target_compile_definitions(pip_lua PRIVATE LUA_BUILD_AS_DLL LUA_CORE)
endif()
list(APPEND HDR_DIRS "${_lua_bri_dir}/LuaBridge")
list(APPEND HDRS ${_lua_src_hdr})
endif()
if (PIP_BUILD_HTTP_SERVER)
# libmicrohttpd
pip_find_lib(microhttpd HINTS "${MINGW_LIB}")
if (microhttpd_FOUND)
set(_microhttpd_add_libs microhttpd)
if(WIN32)
if("${C_COMPILER}" STREQUAL "cl.exe")
else()
list(APPEND _microhttpd_add_libs ws2_32)
endif()
else()
if (NOT DEFINED ANDROID_PLATFORM)
list(APPEND _microhttpd_add_libs pthread util)
list(APPEND _microhttpd_add_libs dl)
find_library(tls_lib gnutls)
if (tls_lib)
set(gnutls_FOUND TRUE)
set(gnutls_LIBRARIES "${tls_lib}")
list(APPEND _microhttpd_add_libs gnutls)
endif()
if(DEFINED ENV{QNX_HOST})
list(APPEND _microhttpd_add_libs socket)
else()
if (NOT DEFINED ANDROID_PLATFORM)
list(APPEND _microhttpd_add_libs pthread util)
endif()
endif()
endif()
#list(APPEND microhttpd_LIBRARIES "${_microhttpd_add_libs}")
pip_module(http_server "${_microhttpd_add_libs}" "PIP HTTP server" "" "" "")
endif()
#list(APPEND microhttpd_LIBRARIES "${_microhttpd_add_libs}")
pip_module(http_server "${_microhttpd_add_libs}" "PIP HTTP server" "" "" "")
endif()
# libcurl
pip_find_lib(curl HINTS "${MINGW_LIB}")
if (curl_FOUND)
pip_module(http_client curl "PIP HTTP client" "" "" "")
if (PIP_BUILD_HTTP_CLIENT)
# libcurl
pip_find_lib(curl HINTS "${MINGW_LIB}")
if (curl_FOUND)
pip_module(http_client curl "PIP HTTP client" "" "" "")
endif()
endif()
# Test program
if(PIP_UTILS)
@@ -547,9 +570,19 @@ if (NOT CROSSTOOLS)
endif()
else()
pip_module(crypt "" "PIP crypt support" "" "" "")
pip_module(compress "" "PIP compression support" "" "" "")
pip_module(io_utils "pip_crypt" "PIP I/O support" "" "" " (+crypt)")
if (PIP_BUILD_CRYPT)
pip_module(crypt "" "PIP crypt support" "" "" "")
endif()
if (PIP_BUILD_COMPRESS)
pip_module(compress "" "PIP compression support" "" "" "")
endif()
if (PIP_BUILD_IO_UTILS)
pip_module(io_utils "pip_crypt" "PIP I/O support" "" "" " (+crypt)")
endif()
endif()
endif()

View File

@@ -20,17 +20,19 @@
#include "piincludes_p.h"
#include "piliterals_time.h"
// clang-format off
#ifndef WINDOWS
# include <fcntl.h>
# include <sys/ioctl.h>
# include <termios.h>
#else
# include <wincon.h>
# include <wingdi.h>
# include <wincon.h>
# ifndef COMMON_LVB_UNDERSCORE
# define COMMON_LVB_UNDERSCORE 0x8000
# endif
#endif
// clang-format on
using namespace PIScreenTypes;

View File

@@ -23,7 +23,6 @@
#include "pisharedmemory.h"
#ifndef MICRO_PIP
# ifdef WINDOWS
# include <wincon.h>
# include <windows.h>
# include <wingdi.h>
# include <winuser.h>
@@ -793,7 +792,7 @@ bool PITerminal::initialize() {
// SetHandleInformation(PRIVATE->pipe_in[1], HANDLE_FLAG_INHERIT, 0);
// SetHandleInformation(PRIVATE->hConBuf, HANDLE_FLAG_INHERIT, 0);
// GetStartupInfoA(&PRIVATE->si);
memset(&PRIVATE->si, 0, sizeof(PRIVATE->si));
piZeroMemory(PRIVATE->si);
PRIVATE->si.cb = sizeof(STARTUPINFO);
// PRIVATE->si.dwFlags |= STARTF_USESTDHANDLES;
PRIVATE->si.dwFlags |= STARTF_USESHOWWINDOW;
@@ -805,7 +804,7 @@ bool PITerminal::initialize() {
PRIVATE->si.dwXCountChars = 80;
PRIVATE->si.dwYCountChars = 24;
memset(&PRIVATE->pi, 0, sizeof(PRIVATE->pi));
piZeroMemory(PRIVATE->pi);
PIString shmh = PIString::fromNumber(randomi() % 10000);
PIString pname = "\\\\.\\pipe\\piterm" + shmh;
@@ -857,7 +856,7 @@ bool PITerminal::initialize() {
# else
# ifdef HAS_FORKPTY
char pty[256];
memset(pty, 0, 256);
piZeroMemory(pty, 256);
winsize ws;
ws.ws_col = dsize_x;
ws.ws_row = dsize_y;

View File

@@ -143,7 +143,7 @@ void log_callback(void * cls, const char * fmt, va_list ap) {
piCout << "log" << server;
if (!server) return;
char buffer[1_KiB];
memset(buffer, 0, 1_KiB);
piZeroMemory(buffer, 1_KiB);
std::vsnprintf(buffer, 1_KiB, fmt, ap);
piCout << buffer;
}
@@ -312,7 +312,7 @@ bool MicrohttpdServer::listen(PINetworkAddress addr) {
key_pass = opts.value(Option::HTTPSKeyPassword).toByteArray();
if (key_pass.isNotEmpty()) key_pass.append(0);
sockaddr_in sa_addr;
memset(&sa_addr, 0, sizeof(sa_addr));
piZeroMemory(sa_addr);
sa_addr.sin_port = htons(addr.port());
sa_addr.sin_addr.s_addr = addr.ip();
sa_addr.sin_family = AF_INET;

View File

@@ -405,7 +405,7 @@ float PISystemMonitor::calcThreadUsage(PISystemTime & t_new, PISystemTime & t_ol
ullong PISystemMonitor::totalRAM() {
#ifdef ESP_PLATFORM
multi_heap_info_t heap_info;
memset(&heap_info, 0, sizeof(multi_heap_info_t));
piZeroMemory(heap_info);
heap_caps_get_info(&heap_info, MALLOC_CAP_8BIT);
return heap_info.total_allocated_bytes + heap_info.total_free_bytes;
#endif
@@ -416,7 +416,7 @@ ullong PISystemMonitor::totalRAM() {
ullong PISystemMonitor::freeRAM() {
#ifdef ESP_PLATFORM
multi_heap_info_t heap_info;
memset(&heap_info, 0, sizeof(multi_heap_info_t));
piZeroMemory(heap_info);
heap_caps_get_info(&heap_info, MALLOC_CAP_8BIT);
return heap_info.total_free_bytes;
#endif
@@ -427,7 +427,7 @@ ullong PISystemMonitor::freeRAM() {
ullong PISystemMonitor::usedRAM() {
#ifdef ESP_PLATFORM
multi_heap_info_t heap_info;
memset(&heap_info, 0, sizeof(multi_heap_info_t));
piZeroMemory(heap_info);
heap_caps_get_info(&heap_info, MALLOC_CAP_8BIT);
return heap_info.total_allocated_bytes;
#endif

View File

@@ -20,12 +20,15 @@
#include "piincludes_p.h"
#include "piliterals.h"
#include "piwaitevent_p.h"
// clang-format off
#ifndef WINDOWS
# include <termios.h>
#else
# include <wincon.h>
# include <wingdi.h>
# include <wincon.h>
#endif
// clang-format on
/** \class PIKbdListener
* \brief Keyboard console input listener
@@ -144,6 +147,7 @@ PRIVATE_DEFINITION_START(PIKbdListener)
int
#endif
ret;
PIWaitEvent event;
PRIVATE_DEFINITION_END(PIKbdListener)
@@ -157,11 +161,11 @@ PIKbdListener::PIKbdListener(KBFunc slot, void * _d, bool startNow): PIThread()
#else
tcgetattr(0, &PRIVATE->sterm);
#endif
is_active = true;
ret_func = slot;
kbddata_ = _d;
dbl_interval = 400;
PIKbdListener::exiting = exit_enabled = false;
ret_func = slot;
kbddata_ = _d;
dbl_interval = 400;
PRIVATE->event.create();
PIKbdListener::exiting = false;
if (startNow) start();
}
@@ -169,7 +173,7 @@ PIKbdListener::PIKbdListener(KBFunc slot, void * _d, bool startNow): PIThread()
PIKbdListener::~PIKbdListener() {
stop();
if (!waitForFinish(100_ms)) terminate();
end();
PRIVATE->event.destroy();
}
@@ -216,7 +220,8 @@ PIKbdListener::MouseButtons getButtons(DWORD v) {
void PIKbdListener::readKeyboard() {
ke.key = 0;
ke.modifiers = 0;
memset(rc, 0, 8);
char rc[8];
piZeroMemory(rc, 8);
#ifdef WINDOWS
INPUT_RECORD ir;
ReadConsoleInput(PRIVATE->hIn, &ir, 1, &(PRIVATE->ret));
@@ -403,6 +408,7 @@ void PIKbdListener::readKeyboard() {
}
#else
tcsetattr(0, TCSANOW, &PRIVATE->tterm);
if (!PRIVATE->event.wait(0)) return;
PRIVATE->ret = read(0, rc, 8);
/*piCout << "key" << PIString(rc).replaceAll("\e", "\\e");
for (int i = 0; i < PRIVATE->ret; ++i)
@@ -542,6 +548,13 @@ void PIKbdListener::readKeyboard() {
void PIKbdListener::stop() {
PIThread::stop();
PRIVATE->event.interrupt();
}
bool PIKbdListener::stopAndWait(PISystemTime timeout) {
stop();
return waitForFinish(timeout);
}

View File

@@ -29,15 +29,11 @@
#include "pithread.h"
#include "pitime.h"
#define WAIT_FOR_EXIT \
while (!PIKbdListener::exiting) \
piMSleep(PIP_MIN_MSLEEP * 5); \
if (PIKbdListener::instance()) { \
PIKbdListener::instance()->stop(); \
if (!PIKbdListener::instance()->waitForFinish(PISystemTime::fromMilliseconds(100))) { \
PIKbdListener::instance()->setDebug(false); \
PIKbdListener::instance()->terminate(); \
} \
#define WAIT_FOR_EXIT \
while (!PIKbdListener::exiting) \
piMSleep(PIP_MIN_MSLEEP * 5); \
if (PIKbdListener::instance()) { \
if (!PIKbdListener::instance()->stopAndWait(PISystemTime::fromSeconds(1))) PIKbdListener::instance()->terminate(); \
}
@@ -188,6 +184,8 @@ public:
void stop();
bool stopAndWait(PISystemTime timeout = {});
//! Returns if keyboard listening is active (not running!)
bool isActive() { return is_active; }
@@ -258,9 +256,8 @@ private:
PRIVATE_DECLARATION(PIP_EXPORT)
KBFunc ret_func;
int exit_key;
bool exit_enabled, is_active;
bool exit_enabled = false, is_active = true;
void * kbddata_;
char rc[8];
double dbl_interval;
PITimeMeasurer tm_dbl;
KeyEvent ke;

View File

@@ -46,6 +46,7 @@
#include <atomic>
#include <cassert>
#include <cstddef>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <limits>
@@ -558,6 +559,23 @@ inline uint piHash(const ldouble & v) {
return piHashData((const uchar *)&v, sizeof(v));
}
//! \~\brief
//! \~english Zero "size" bytes by address "ptr".
//! \~russian Зануляет "size" байт по адресу "ptr".
inline void piZeroMemory(void * ptr, size_t size) {
memset(ptr, 0, size);
}
//! \~\brief
//! \~english Zero variable "v" memory.
//! \~russian Зануляет память переменной "v".
template<typename T>
inline void piZeroMemory(T & v) {
piZeroMemory(&v, sizeof(v));
}
//! \~\brief
//! \~english Call \b delete on each "container" element.
//! \~russian Вызывает \b delete на каждый элемент "container".

View File

@@ -28,7 +28,6 @@
# include <locale>
#endif
#ifdef WINDOWS
# include <wincon.h>
# include <windows.h>
# include <wingdi.h>
# define COMMON_LVB_UNDERSCORE 0x8000

View File

@@ -167,7 +167,7 @@ PIInit::PIInit() {
for (l = 0; l < MAX_PATH; ++l)
if (cpinfo.CodePageName[l] == '\0' || cpinfo.CodePageName[l] == ' ') break;
__sysoemname__ = new char[256];
memset(__sysoemname__, 0, 256);
piZeroMemory(__sysoemname__, 256);
memcpy(__sysoemname__, "ibm-", 4);
memcpy(&(__sysoemname__[4]), cpinfo.CodePageName, l);
# else
@@ -190,7 +190,7 @@ PIInit::PIInit() {
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &__pi_mac_clock);
# endif
char cbuff[1024];
memset(cbuff, 0, 1024);
piZeroMemory(cbuff, 1024);
if (gethostname(cbuff, 1023) == 0) {
sinfo->hostname = cbuff;
}
@@ -210,7 +210,7 @@ PIInit::PIInit() {
wchar_t ** argv_ = CommandLineToArgvW(GetCommandLineW(), &argc_);
if (argc_ > 0 && argv_ != 0) sinfo->execCommand = argv_[0];
LocalFree(argv_);
memset(cbuff, 0, 1024);
piZeroMemory(cbuff, 1024);
ulong unlen = 1023;
if (GetUserNameA(cbuff, &unlen) != 0) sinfo->user = cbuff;
# else // WINDOWS
@@ -219,7 +219,7 @@ PIInit::PIInit() {
if (ps)
sinfo->user = ps->pw_name;
else {
memset(cbuff, 0, 1024);
piZeroMemory(cbuff, 1024);
char * l = getlogin();
if (l) sinfo->user = l;
}

View File

@@ -46,7 +46,7 @@ void PIWaitEvent::create() {
}
#else
for (int i = 0; i < 3; ++i)
memset(&(fds[i]), 0, sizeof(fds[i]));
piZeroMemory(fds[i]);
if (::pipe(pipe_fd) < 0) {
piCout << "Error with pipe:" << errorString();
} else {

View File

@@ -326,7 +326,7 @@ PIVector<PIFile::FileInfo> PIDir::entries() {
}
} else {
WIN32_FIND_DATAA fd;
memset(&fd, 0, sizeof(fd));
piZeroMemory(fd);
p += "\\*";
void * hf = FindFirstFileA((LPCSTR)(p.data()), &fd);
if (!hf) return l;
@@ -335,7 +335,7 @@ PIVector<PIFile::FileInfo> PIDir::entries() {
PIString fn(fd.cFileName);
if (fn == "..") hdd = true;
l << PIFile::fileInfo(dp + fn);
memset(&fd, 0, sizeof(fd));
piZeroMemory(fd);
} while (FindNextFileA(hf, &fd) != 0);
FindClose(hf);
l.sort(sort_compare);
@@ -440,7 +440,7 @@ PIDir PIDir::current() {
char rc[1024];
#endif
#ifdef WINDOWS
memset(rc, 0, 1024);
piZeroMemory(rc, 1024);
if (GetCurrentDirectory(1024, (LPTSTR)rc) == 0) return PIString();
PIString ret(rc);
ret.replaceAll("\\", PIDir::separator);
@@ -463,13 +463,13 @@ PIDir PIDir::home() {
#endif
#ifdef WINDOWS
rc = new char[1024];
memset(rc, 0, 1024);
piZeroMemory(rc, 1024);
if (ExpandEnvironmentStrings((LPCTSTR) "%HOMEPATH%", (LPTSTR)rc, 1024) == 0) {
delete[] rc;
return PIDir();
}
PIString hp(rc);
memset(rc, 0, 1024);
piZeroMemory(rc, 1024);
if (ExpandEnvironmentStrings((LPCTSTR) "%HOMEDRIVE%", (LPTSTR)rc, 1024) == 0) {
delete[] rc;
return PIDir();
@@ -495,7 +495,7 @@ PIDir PIDir::temporary() {
char * rc = nullptr;
#ifdef WINDOWS
rc = new char[1024];
memset(rc, 0, 1024);
piZeroMemory(rc, 1024);
int ret = GetTempPath(1024, (LPTSTR)rc);
if (ret == 0) {
delete[] rc;

View File

@@ -272,7 +272,7 @@ bool PIEthernet::openDevice() {
// if (type() == TCP_Client)
// connecting_ = true;
if (type() != UDP || mode() == PIIODevice::WriteOnly) return true;
memset(&PRIVATE->addr_, 0, sizeof(PRIVATE->addr_));
piZeroMemory(PRIVATE->addr_);
PRIVATE->addr_.sin_family = AF_INET;
PRIVATE->addr_.sin_port = htons(addr_r.port());
if (params[PIEthernet::Broadcast])
@@ -377,7 +377,7 @@ bool PIEthernet::joinMulticastGroup(const PIString & group) {
#else
struct ip_mreq mreq;
#endif
memset(&mreq, 0, sizeof(mreq));
piZeroMemory(mreq);
#ifdef LINUX
// mreq.imr_address.s_addr = INADDR_ANY;
/*PIEthernet::InterfaceList il = interfaces();
@@ -423,7 +423,7 @@ bool PIEthernet::leaveMulticastGroup(const PIString & group) {
#else
struct ip_mreq mreq;
#endif
memset(&mreq, 0, sizeof(mreq));
piZeroMemory(mreq);
if (params[PIEthernet::Broadcast])
#ifndef LWIP
mreq.imr_address.s_addr = INADDR_ANY;
@@ -454,7 +454,7 @@ bool PIEthernet::connect(bool threaded) {
if (connected_) return false;
if (sock == -1) init();
if (sock == -1) return false;
memset(&PRIVATE->addr_, 0, sizeof(PRIVATE->addr_));
piZeroMemory(PRIVATE->addr_);
addr_r.set(path());
PRIVATE->addr_.sin_port = htons(addr_r.port());
PRIVATE->addr_.sin_addr.s_addr = addr_r.ip();
@@ -492,7 +492,7 @@ bool PIEthernet::listen(bool threaded) {
}
listen_threaded = server_bounded = false;
addr_r.set(path());
memset(&PRIVATE->addr_, 0, sizeof(PRIVATE->addr_));
piZeroMemory(PRIVATE->addr_);
PRIVATE->addr_.sin_port = htons(addr_r.port());
PRIVATE->addr_.sin_addr.s_addr = addr_r.ip();
PRIVATE->addr_.sin_family = AF_INET;
@@ -618,7 +618,7 @@ ssize_t PIEthernet::readDevice(void * read_to, ssize_t max_size) {
case TCP_Client:
if (connecting_) {
addr_r.set(path());
memset(&PRIVATE->addr_, 0, sizeof(PRIVATE->addr_));
piZeroMemory(PRIVATE->addr_);
PRIVATE->addr_.sin_port = htons(addr_r.port());
PRIVATE->addr_.sin_addr.s_addr = addr_r.ip();
PRIVATE->addr_.sin_family = AF_INET;
@@ -704,7 +704,7 @@ ssize_t PIEthernet::readDevice(void * read_to, ssize_t max_size) {
if (rs > 0) received(read_to, rs);
return rs;
case UDP: {
memset(&PRIVATE->raddr_, 0, sizeof(PRIVATE->raddr_));
piZeroMemory(PRIVATE->raddr_);
// piCoutObj << "read from" << path() << "...";
#ifdef WINDOWS
long wr = waitForEvent(PRIVATE->event, FD_READ | FD_CLOSE);
@@ -765,7 +765,7 @@ ssize_t PIEthernet::writeDevice(const void * data, ssize_t max_size) {
// piCout << "[PIEth] write to" << ip_s << ":" << port_s << "ok";
case TCP_Client: {
if (connecting_) {
memset(&PRIVATE->addr_, 0, sizeof(PRIVATE->addr_));
piZeroMemory(PRIVATE->addr_);
addr_r.set(path());
PRIVATE->addr_.sin_port = htons(addr_r.port());
PRIVATE->addr_.sin_addr.s_addr = addr_r.ip();
@@ -962,7 +962,7 @@ long PIEthernet::waitForEvent(PIWaitEvent & event, long mask) {
// DWORD wr = WSAWaitForMultipleEvents(1, &(PRIVATE->read_event), FALSE, WSA_INFINITE, TRUE);
// if (wr == WSA_WAIT_EVENT_0) {
WSANETWORKEVENTS events;
memset(&events, 0, sizeof(events));
piZeroMemory(events);
WSAEnumNetworkEvents(sock, event.getEvent(), &events);
// piCoutObj << "wait result" << events.lNetworkEvents;
return events.lNetworkEvents;
@@ -1245,7 +1245,7 @@ PINetworkAddress PIEthernet::interfaceAddress(const PIString & interface_) {
return PINetworkAddress();
#else
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
piZeroMemory(ifr);
strcpy(ifr.ifr_name, interface_.dataAscii());
int s = ::socket(AF_INET, SOCK_DGRAM, 0);
ioctl(s, SIOCGIFADDR, &ifr);

View File

@@ -492,7 +492,7 @@ PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
}
if (!hFile) return ret;
BY_HANDLE_FILE_INFORMATION fi;
memset(&fi, 0, sizeof(fi));
piZeroMemory(fi);
if (GetFileInformationByHandle(hFile, &fi) != 0) {
LARGE_INTEGER filesize;
filesize.LowPart = filesize.HighPart = 0;
@@ -515,7 +515,7 @@ PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
CloseHandle(hFile);
#else
_stat_struct_ fs;
memset(&fs, 0, sizeof(fs));
piZeroMemory(fs);
_stat_call_(path.data(), &fs);
int mode = fs.st_mode;
ret.size = fs.st_size;
@@ -544,7 +544,7 @@ PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
ret.perm_user = FileInfo::Permissions((mode & S_IRUSR) == S_IRUSR, (mode & S_IWUSR) == S_IWUSR, (mode & S_IXUSR) == S_IXUSR);
ret.perm_group = FileInfo::Permissions((mode & S_IRGRP) == S_IRGRP, (mode & S_IWGRP) == S_IWGRP, (mode & S_IXGRP) == S_IXGRP);
ret.perm_other = FileInfo::Permissions((mode & S_IROTH) == S_IROTH, (mode & S_IWOTH) == S_IWOTH, (mode & S_IXOTH) == S_IXOTH);
memset(&fs, 0, sizeof(fs));
piZeroMemory(fs);
_stat_link_(path.data(), &fs);
mode &= ~S_IFLNK;
mode |= S_IFLNK & fs.st_mode;

View File

@@ -877,7 +877,7 @@ ssize_t PISerial::readDevice(void * read_to, ssize_t max_size) {
close();
return 0;
}
memset(&(PRIVATE->overlap), 0, sizeof(PRIVATE->overlap));
piZeroMemory(PRIVATE->overlap);
PRIVATE->overlap.hEvent = PRIVATE->event.getEvent();
PRIVATE->readed = 0;
ReadFile(PRIVATE->hCom, read_to, max_size, NULL, &(PRIVATE->overlap));
@@ -924,7 +924,7 @@ ssize_t PISerial::writeDevice(const void * data, ssize_t max_size) {
DWORD wrote(0);
// piCoutObj << "send ..." << max_size;// << ": " << PIString((char*)data, max_size);
sending = true;
memset(&(PRIVATE->overlap_write), 0, sizeof(PRIVATE->overlap_write));
piZeroMemory(PRIVATE->overlap_write);
PRIVATE->overlap_write.hEvent = PRIVATE->event_write.getEvent();
WriteFile(PRIVATE->hCom, data, max_size, NULL, &(PRIVATE->overlap_write));
if (PRIVATE->event_write.wait()) {
@@ -1160,7 +1160,7 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
const HDEVINFO dis = SetupDiGetClassDevs(&(guids[i]), NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (dis == INVALID_HANDLE_VALUE) continue;
SP_DEVINFO_DATA did;
memset(&did, 0, sizeof(did));
piZeroMemory(did);
did.cbSize = sizeof(did);
DWORD index = 0;
while (SetupDiEnumDeviceInfo(dis, index++, &did)) {

View File

@@ -177,7 +177,7 @@ void PIProcess::startProc(bool detached) {
# endif
# ifdef WINDOWS
GetStartupInfoA(&(PRIVATE->si));
memset(&(PRIVATE->pi), 0, sizeof(PRIVATE->pi));
piZeroMemory(PRIVATE->pi);
if (CreateProcessA(0, // No module name (use command line)
a, // Command line
0, // Process handle not inheritable

View File

@@ -54,7 +54,7 @@ PIStringList PISystemInfo::mountRoots() {
# ifdef LINUX
PIString s_df, s_m;
char in[1024];
memset(in, 0, 1024);
piZeroMemory(in, 1024);
FILE * fp = popen("mount -l", "r");
PIStringList tl;
if (fp) {
@@ -129,7 +129,7 @@ PIVector<PISystemInfo::MountInfo> PISystemInfo::mountInfo(bool ignore_cache) {
#ifdef LINUX
PIString s_df, s_m;
char in[1024];
memset(in, 0, 1024);
piZeroMemory(in, 1024);
// piCout << "mountInfo 0";
FILE * fp = popen("df -B1", "r");
PIStringList l_df;
@@ -141,7 +141,7 @@ PIVector<PISystemInfo::MountInfo> PISystemInfo::mountInfo(bool ignore_cache) {
fp = 0;
}
// piCout << "mountInfo 1";
memset(in, 0, 1024);
piZeroMemory(in, 1024);
fp = popen("mount -l", "r");
PIStringList tl;
if (fp) {

View File

@@ -73,7 +73,7 @@ ushort charFromCodepage(const char * c, int size, const char * codepage, int * t
return buffer;
# else
mbstate_t state;
memset(&state, 0, sizeof(state));
piZeroMemory(state);
wchar_t wc;
ret = mbrtowc(&wc, c, size, &state);
// printf("mbtowc = %d\n", ret);
@@ -369,7 +369,7 @@ PICout operator<<(PICout s, const PIChar & v) {
UConverter * cc = ucnv_open(__syslocname__, &e);
if (cc) {
char uc[8];
memset(uc, 0, 8);
piZeroMemory(uc, 8);
e = (UErrorCode)0;
ucnv_fromUChars(cc, uc, 8, (const UChar *)(&v.ch), 1, &e);
ucnv_close(cc);

View File

@@ -178,7 +178,7 @@ T toDecimal(const PIString & s) {
#define pisprintf(f, v) \
char ch[256]; \
memset(ch, 0, 256); \
piZeroMemory(ch, 256); \
snprintf(ch, 256, f, v); \
return PIStringAscii(ch);

View File

@@ -58,7 +58,7 @@ PIConditionVariable::PIConditionVariable() {
# if !defined(MAC_OS)
pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC);
# endif
memset(&(PRIVATE->nativeHandle), 0, sizeof(PRIVATE->nativeHandle));
piZeroMemory(PRIVATE->nativeHandle);
pthread_cond_init(&PRIVATE->nativeHandle, &condattr);
#endif
}

View File

@@ -209,10 +209,10 @@ void PIMutex::init() {
PRIVATE->mutex = xSemaphoreCreateMutex();
#else
pthread_mutexattr_t attr;
memset(&attr, 0, sizeof(attr));
piZeroMemory(attr);
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
memset(&(PRIVATE->mutex), 0, sizeof(PRIVATE->mutex));
piZeroMemory(PRIVATE->mutex);
pthread_mutex_init(&(PRIVATE->mutex), &attr);
pthread_mutexattr_destroy(&attr);
#endif

View File

@@ -533,7 +533,6 @@ PRIVATE_DEFINITION_START(PIThread)
pthread_t thread = 0;
sched_param sparam;
#endif
std::atomic_bool starting = {false};
PRIVATE_DEFINITION_END(PIThread)
@@ -652,9 +651,9 @@ bool PIThread::startOnce(std::function<void()> func) {
}
void PIThread::stopAndWait(PISystemTime timeout) {
bool PIThread::stopAndWait(PISystemTime timeout) {
stop();
waitForFinish(timeout);
return waitForFinish(timeout);
}
@@ -732,16 +731,15 @@ int PIThread::priority2System(PIThread::Priority p) {
bool PIThread::_startThread(void * func) {
terminating = false;
running_ = true;
PRIVATE->starting = true;
PIScopeExitCall ec([this] { PRIVATE->starting = false; });
terminating = false;
running_ = true;
#ifdef FREERTOS
if (xTaskCreate((__THREAD_FUNC_RET__(*)(void *))func,
((PIString &)name().elided(15, 0.4f).resize(15, PIChar('\0'))).dataAscii(), // A name just for humans
128, // This stack size can be checked & adjusted by reading the Stack Highwater
auto name_ba = createThreadName();
if (xTaskCreate((__THREAD_FUNC_RET__ (*)(void *))func,
(const char *)name_ba.data(), // A name just for humans
128, // This stack size can be checked & adjusted by reading the Stack Highwater
this,
priority_,
&PRIVATE->thread) == pdPASS) {
@@ -753,13 +751,12 @@ bool PIThread::_startThread(void * func) {
if (PRIVATE->thread) CloseHandle(PRIVATE->thread);
# ifdef CC_GCC
PRIVATE->thread = (void *)_beginthreadex(0, 0, (__THREAD_FUNC_RET__(*)(void *))func, this, 0, 0);
PRIVATE->thread = (void *)_beginthreadex(0, 0, (__THREAD_FUNC_RET__ (*)(void *))func, this, CREATE_SUSPENDED, 0);
# else
PRIVATE->thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)func, this, 0, 0);
PRIVATE->thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)func, this, CREATE_SUSPENDED, 0);
# endif
// piCout << "started" << PRIVATE->thread;
if (PRIVATE->thread != 0) {
setPriority(priority_);
ResumeThread(PRIVATE->thread);
return true;
}
@@ -768,24 +765,11 @@ bool PIThread::_startThread(void * func) {
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
int ret = pthread_create(&PRIVATE->thread, &attr, (__THREAD_FUNC_RET__(*)(void *))func, this);
// PICout(PICoutManipulators::DefaultControls) << "pthread_create" << PRIVATE->thread;
int ret = pthread_create(&PRIVATE->thread, &attr, (__THREAD_FUNC_RET__ (*)(void *))func, this);
pthread_attr_destroy(&attr);
// PICout(PICoutManipulators::DefaultControls) << "pthread_create" << PRIVATE->thread;
// piCout << "started" << PRIVATE->thread;
if (ret == 0) {
// if (name().isNotEmpty()) {
PIString tname = name().simplified();
tname.elide(15, 0.4f).resize(15, PIChar('\0'));
PIByteArray tn_data = tname.toAscii();
tn_data.resize(16);
tn_data.back() = 0;
# ifdef MAC_OS
pthread_setname_np((const char *)tn_data.data());
pthread_threadid_np(PRIVATE->thread, (__uint64_t *)&tid_);
# else
pthread_setname_np(PRIVATE->thread, (const char *)tn_data.data());
# endif
setPriority(priority_);
// }
return true;
}
@@ -807,7 +791,7 @@ void PIThread::setPriority(PIThread::Priority prior) {
# ifndef WINDOWS
// PICout(PICoutManipulators::DefaultControls) << "setPriority" << PRIVATE->thread;
int policy_ = 0;
memset(&(PRIVATE->sparam), 0, sizeof(PRIVATE->sparam));
piZeroMemory(PRIVATE->sparam);
pthread_getschedparam(PRIVATE->thread, &policy_, &(PRIVATE->sparam));
PRIVATE->sparam.
# ifndef LINUX
@@ -818,7 +802,6 @@ void PIThread::setPriority(PIThread::Priority prior) {
= priority2System(priority_);
pthread_setschedparam(PRIVATE->thread, policy_, &(PRIVATE->sparam));
# else
if (!running_ || (PRIVATE->thread == 0)) return;
SetThreadPriority(PRIVATE->thread, priority2System(priority_));
# endif
#endif // FREERTOS
@@ -896,6 +879,8 @@ void PIThread::_beginThread() {
#ifdef LINUX
tid_ = gettid();
#endif
setPriority(priority_);
setThreadName();
PIINTROSPECTION_THREAD_START(this);
REGISTER_THREAD(this);
running_ = true;
@@ -910,8 +895,8 @@ void PIThread::_runThread() {
PIINTROSPECTION_THREAD_RUN(this);
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "...";
if (lockRun) thread_mutex.lock();
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "ok";
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "...";
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "ok";
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "...";
#ifdef PIP_INTROSPECTION
PITimeMeasurer _tm;
#endif
@@ -934,11 +919,10 @@ void PIThread::_endThread() {
PIScopeExitCall ec([this] {
terminating = running_ = false;
tid_ = -1;
PRIVATE->thread = 0;
});
while (PRIVATE->starting)
piMinSleep();
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "...";
// while (PRIVATE->starting)
// piMinSleep();
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "...";
stopped();
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
if (lockRun) thread_mutex.lock();
@@ -961,8 +945,8 @@ void PIThread::_endThread() {
#elif defined(FREERTOS)
PRIVATE->thread = 0;
#else
// pthread_detach(PRIVATE->thread);
PRIVATE->thread = 0;
ec.callAndCancel();
pthread_exit(0);
#endif
}
@@ -1077,3 +1061,26 @@ void PIThread::runOnce(std::function<void()> func, const PIString & name) {
#endif
t->startOnce();
}
PIByteArray PIThread::createThreadName(int size) const {
PIString tname = name().simplified();
tname.elide(size - 1, 0.4f).resize(size - 1, PIChar('\0'));
PIByteArray ret = tname.toAscii();
ret.resize(size);
ret.back() = 0;
return ret;
}
void PIThread::setThreadName() {
#ifndef WINDOWS
auto name_ba = createThreadName();
# ifdef MAC_OS
pthread_setname_np((const char *)name_ba.data());
pthread_threadid_np(PRIVATE->thread, (__uint64_t *)&tid_);
# else
pthread_setname_np(PRIVATE->thread, (const char *)name_ba.data());
# endif
#endif
}

View File

@@ -143,15 +143,13 @@ public:
EVENT_HANDLER0(void, stop);
EVENT_HANDLER0(void, terminate);
//! \~english Stop thread and wait for finish.
//! \~russian Останавливает поток и ожидает завершения.
void stopAndWait(int timeout_ms) DEPRECATEDM("use waitForStart(PISystemTime)") {
stopAndWait(PISystemTime::fromMilliseconds(timeout_ms));
bool stopAndWait(int timeout_ms) DEPRECATEDM("use stopAndWait(PISystemTime)") {
return stopAndWait(PISystemTime::fromMilliseconds(timeout_ms));
}
//! \~english Stop thread and wait for finish.
//! \~russian Останавливает поток и ожидает завершения.
void stopAndWait(PISystemTime timeout = {});
//! \~english Stop thread and wait for finish. Returns \b false if timeout expired.
//! \~russian Останавливает поток и ожидает завершения. Возвращает \b false если таймаут истек.
bool stopAndWait(PISystemTime timeout = {});
//! \~english Set common data passed to external function
//! \~russian Устанавливает данные, передаваемые в функцию потока
@@ -194,8 +192,8 @@ public:
return waitForStart(PISystemTime::fromMilliseconds(timeout_msecs));
}
//! \~english Wait for thread finish
//! \~russian Ожидает завершения потока
//! \~english Wait for thread finish. Returns \b false if timeout expired.
//! \~russian Ожидает завершения потока. Возвращает \b false если таймаут истек.
bool waitForFinish(PISystemTime timeout = {});
bool waitForFinish(int timeout_msecs) DEPRECATEDM("use waitForFinish(PISystemTime)") {
return waitForFinish(PISystemTime::fromMilliseconds(timeout_msecs));
@@ -299,6 +297,9 @@ private:
void _beginThread();
void _runThread();
void _endThread();
PIByteArray createThreadName(int size = 16) const;
void setThreadName();
};

View File

@@ -324,7 +324,7 @@ PIString PIDateTime::toString(const PIString & format) const {
time_t PIDateTime::toSecondSinceEpoch() const {
tm pt;
memset(&pt, 0, sizeof(pt));
piZeroMemory(pt);
pt.tm_sec = seconds;
pt.tm_min = minutes;
pt.tm_hour = hours;

View File

@@ -54,6 +54,14 @@ inline void piSleep(double secs) {
piUSleep(int(secs * 1000000.));
} // on !Windows consider constant "usleep" offset
//! \ingroup Types
//! \brief
//! \~english Precise sleep for "t" time
//! \~russian Точно ожидает время "t"
inline void piSleep(PISystemTime t) {
t.sleep();
}
//! \ingroup Types
//! \~english Shortest available on current system sleep
//! \~russian Наименее возможное для данной системы по длительности ожидание

View File

@@ -548,7 +548,7 @@ void PIOpenCL::Kernel::zero() {
bool PIOpenCL::Kernel::init() {
char kname[1024];
memset(kname, 0, 1024);
piZeroMemory(kname, 1024);
cl_int ret = 0;
ret = clGetKernelInfo(PRIVATE->kernel, CL_KERNEL_FUNCTION_NAME, 1024, kname, 0);
if (ret != 0) {
@@ -655,14 +655,14 @@ void PIOpenCL::KernelArg::init(void * _k, uint index) {
cl_kernel k = (cl_kernel)_k;
cl_int ret = 0;
char nm[1024];
memset(nm, 0, 1024);
piZeroMemory(nm, 1024);
ret = clGetKernelArgInfo(k, index, CL_KERNEL_ARG_TYPE_NAME, 1024, nm, 0);
if (ret != 0) {
piCout << "[PIOpenCL::Kernel]"
<< "clGetKernelArgInfo(CL_KERNEL_ARG_TYPE_NAME) error" << ret;
}
type_name = nm;
memset(nm, 0, 1024);
piZeroMemory(nm, 1024);
ret = clGetKernelArgInfo(k, index, CL_KERNEL_ARG_NAME, 1024, nm, 0);
if (ret != 0) {
piCout << "[PIOpenCL::Kernel]"

View File

@@ -45,7 +45,7 @@ void usage() {
}
PIString confDir() {
PIString pisdConfDir() {
return
#ifdef WINDOWS
PIDir::home().path() + "/AppData/Local"
@@ -74,7 +74,7 @@ int main(int argc, char * argv[]) {
}
PINetworkAddress addr = PINetworkAddress("0.0.0.0", 10101);
PIString conf_path = confDir();
PIString conf_path = pisdConfDir();
PIDir::make(conf_path);
conf_path += "/picloud.conf";
uint max_connections = 1000;

View File

@@ -206,7 +206,7 @@ PIString execute(const PIString & cmd) {
if (fp) {
const int sz = 256;
char in[sz];
memset(in, 0, sz);
piZeroMemory(in, sz);
while (true) {
int r = fread(in, 1, sz, fp);
if (r <= 0) break;

View File

@@ -31,8 +31,10 @@ int main(int argc, char * argv[]) {
# include "piscreentypes.h"
# include "pisharedmemory.h"
# include <wincon.h>
// clang-format off
# include <wingdi.h>
# include <wincon.h>
// clang-format on
PIVector<PIVector<PIScreenTypes::Cell>> cells;
@@ -125,7 +127,7 @@ void readConsole(int x, int y, int w, int h) {
bs.X = w;
bs.Y = h;
bc.X = bc.Y = 0;
memset(chars, 0, w * h * sizeof(CHAR_INFO));
piZeroMemory(chars, w * h * sizeof(CHAR_INFO));
ReadConsoleOutput(console, chars, bs, bc, &(sbi.srWindow));
for (int i = 0; i < h; ++i)
for (int j = 0; j < w; ++j)
@@ -249,9 +251,9 @@ int main(int argc, char * argv[]) {
// piCout << "start";
STARTUPINFOA si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi));
memset(&sbi, 0, sizeof(sbi));
piZeroMemory(si);
piZeroMemory(pi);
piZeroMemory(sbi);
PIString shmh, pname;
if (argc > 1) shmh = argv[1];
if (argc > 2) pname = argv[2];

View File

@@ -421,11 +421,12 @@ int main(int argc, char * argv[]) {
if (sapp) CONNECTU(sapp, messageReceived, menu, messageFromApp);
if (cli.hasArgument("silent")) {
PICout::setOutputDevices(PICout::Console);
PIKbdListener ls;
PIKbdListener ls(0, 0, false);
ls.enableExitCapture(PIKbdListener::F10);
ls.start();
WAIT_FOR_EXIT
ls.stopAndWait();
while (!PIKbdListener::exiting)
piMSleep(PIP_MIN_MSLEEP * 5);
if (!ls.stopAndWait(1_s)) ls.terminate();
} else {
screen->start();
screen->waitForFinish();