From 54d40653cb789a820a27cb12945c8c5feede7922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Fri, 28 Apr 2017 08:43:36 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@480 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src_main/console/piscreentypes.h | 4 ++- src_main/io/pisharedmemory.cpp | 48 ++++++++++++-------------------- src_main/io/pisharedmemory.h | 4 ++- src_main/thread/pithread.cpp | 1 + src_main/thread/pitimer.cpp | 1 + 5 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src_main/console/piscreentypes.h b/src_main/console/piscreentypes.h index c6473e4f..ac49fa3a 100644 --- a/src_main/console/piscreentypes.h +++ b/src_main/console/piscreentypes.h @@ -92,6 +92,7 @@ namespace PIScreenTypes { typedef PIFlags CharFlags; typedef PIFlags FocusFlags; +#pragma pack(push, 1) union CellFormat { CellFormat(uint f = 0) {raw_format = f;} CellFormat(Color col_char, Color col_back = Default, CharFlags flags_ = 0) { @@ -124,7 +125,8 @@ namespace PIScreenTypes { return *this; } }; - +#pragma pack(pop) + struct TileEvent { TileEvent(int t = -1, const PIVariant & d = PIVariant()): type(t), data(d) {} int type; diff --git a/src_main/io/pisharedmemory.cpp b/src_main/io/pisharedmemory.cpp index db9b3767..1538f401 100644 --- a/src_main/io/pisharedmemory.cpp +++ b/src_main/io/pisharedmemory.cpp @@ -83,30 +83,24 @@ PISharedMemory::PISharedMemory(const PIString & shm_name, int size, PIIODevice:: } -PISharedMemory::PISharedMemory(const PISharedMemory & other) { - initPrivate(); - dsize = other.dsize; - setPath(other.path()); - mode_ = other.mode_; -} - - bool PISharedMemory::openDevice() { close(); piCoutObj << "try open" << path() << dsize; #ifdef WINDOWS - DWORD m = PAGE_READWRITE; - if (!isWriteable()) m = PAGE_READONLY; PRIVATE->name = ("PIP_SHM_" + path()).toByteArray(); PRIVATE->name.push_back(0); - PRIVATE->map = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, m, 0, (DWORD)dsize, (const char *)PRIVATE->name.data()); + const char * nm = (const char *)PRIVATE->name.data(); + PRIVATE->map = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, nm); + //piCoutObj << "open map =" << ullong(PRIVATE->map); if (!PRIVATE->map) { - piCoutObj << path() << dsize << "CreateFileMapping error," << errorString(); - return false; + PRIVATE->map = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (DWORD)dsize, nm); + //piCoutObj << "create map =" << ullong(PRIVATE->map); + if (!PRIVATE->map) { + piCoutObj << path() << dsize << "CreateFileMapping error," << errorString(); + return false; + } } - if (!isWriteable()) m = FILE_MAP_READ; - else m = FILE_MAP_ALL_ACCESS; - PRIVATE->data = MapViewOfFile(PRIVATE->map, m, 0, 0, dsize); + PRIVATE->data = MapViewOfFile(PRIVATE->map, FILE_MAP_ALL_ACCESS, 0, 0, dsize); if (!PRIVATE->data) { piCoutObj << path() << dsize << "MapViewOfFile error," << errorString(); CloseHandle(PRIVATE->map); @@ -209,20 +203,6 @@ PIByteArray PISharedMemory::readAll() { #endif PIByteArray a(dsize); read(a.data(), a.size_s()); - /*llong cp = pos(); - if (forceRead) { - seekToBegin(); - while (!isEnd()) - a.push_back(readChar()); - seek(cp); - return a; - } - llong s = size(); - if (s < 0) return a; - a.resize(s); - s = readAll(a.data()); - seek(cp); - if (s >= 0) a.resize(s);*/ return a; } @@ -233,6 +213,14 @@ llong PISharedMemory::size() const { } +void PISharedMemory::setSize(llong s) { + bool o = isOpened(); + if (o) close(); + dsize = s; + if (o) open(); +} + + int PISharedMemory::read(void * read_to, int max_size) { return read(read_to, max_size, 0); } diff --git a/src_main/io/pisharedmemory.h b/src_main/io/pisharedmemory.h index 9144ed46..8762cc0a 100644 --- a/src_main/io/pisharedmemory.h +++ b/src_main/io/pisharedmemory.h @@ -36,7 +36,6 @@ public: //! Constructs a shared memory object with name "shm_name", size "size" and open mode "mode" explicit PISharedMemory(const PIString & shm_name, int size, DeviceMode mode = ReadWrite); - PISharedMemory(const PISharedMemory & other); virtual ~PISharedMemory() {close();} @@ -45,6 +44,9 @@ public: //! Returns shared memory object size llong size() const; + + //! Set shared memory object size + void setSize(llong s); //! Returns if shared memory object is empty bool isEmpty() const {return (size() <= 0);} diff --git a/src_main/thread/pithread.cpp b/src_main/thread/pithread.cpp index a04c3624..2d243915 100755 --- a/src_main/thread/pithread.cpp +++ b/src_main/thread/pithread.cpp @@ -249,6 +249,7 @@ __THREAD_FUNC__ PIThread::thread_function(void * t) { if (ct.lockRun) ct.mutex_.unlock(); ct.started(); while (!ct.terminating) { + ct.maybeCallQueuedEvents(); if (ct.lockRun) ct.mutex_.lock(); //piCout << "thread" << ct.name() << "..."; ct.run(); diff --git a/src_main/thread/pitimer.cpp b/src_main/thread/pitimer.cpp index 431fa099..87827bbd 100755 --- a/src_main/thread/pitimer.cpp +++ b/src_main/thread/pitimer.cpp @@ -516,6 +516,7 @@ void PITimer::tickImp() { if (ret_func != 0) ret_func(data_t, 1); tick(data_t, 1); tickEvent(data_t, 1); + maybeCallQueuedEvents(); piForeach (Delimiter & i, delims) { if (i.delim > ++(i.tick)) continue; i.tick = 0;