PIObject::deleteLater important fix
PIWaitEvent::sleep() method PITimer thread imp wait optimization, migrate to interruptable sleeps
This commit is contained in:
@@ -839,7 +839,7 @@ PIObject::Deleter::Deleter() {
|
||||
PRIVATE->thread.setSlot([this](){
|
||||
PIVector<PIObject*> oq;
|
||||
PRIVATE->thread.lock();
|
||||
while(PRIVATE->obj_queue.isEmpty()) PRIVATE->cond_var.wait(PRIVATE->thread.mutex());
|
||||
PRIVATE->cond_var.wait(PRIVATE->thread.mutex());
|
||||
oq.swap(PRIVATE->obj_queue);
|
||||
PRIVATE->thread.unlock();
|
||||
for (PIObject * o : oq) deleteObject(o);
|
||||
@@ -851,7 +851,9 @@ PIObject::Deleter::Deleter() {
|
||||
PIObject::Deleter::~Deleter() {
|
||||
//piCout << "~Deleter ...";
|
||||
PRIVATE->thread.stop();
|
||||
PRIVATE->thread.mutex().lock();
|
||||
PRIVATE->cond_var.notifyAll();
|
||||
PRIVATE->thread.mutex().unlock();
|
||||
PRIVATE->thread.waitForFinish();
|
||||
for (PIObject * o : PRIVATE->obj_queue) deleteObject(o);
|
||||
//piCout << "~Deleter ok";
|
||||
|
||||
@@ -95,6 +95,27 @@ bool PIWaitEvent::wait(int fd, CheckRole role) {
|
||||
}
|
||||
|
||||
|
||||
bool PIWaitEvent::sleep(int us) {
|
||||
if (!isCreate()) return false;
|
||||
#ifdef WINDOWS
|
||||
DWORD ret = WaitForSingleObjectEx(event, us / 1000, TRUE);
|
||||
ResetEvent(event);
|
||||
return ret == WAIT_TIMEOUT;
|
||||
#else
|
||||
int nfds = pipe_fd[ReadEnd] + 1;
|
||||
FD_ZERO(&(fds[CheckRead]));
|
||||
FD_SET(pipe_fd[ReadEnd], &(fds[CheckRead]));
|
||||
timeval timeout;
|
||||
timeout.tv_sec = us / 1000000;
|
||||
timeout.tv_usec = us % 1000000;
|
||||
int ret = ::select(nfds, &(fds[CheckRead]), nullptr, nullptr, &timeout);
|
||||
int buf = 0;
|
||||
while (::read(pipe_fd[ReadEnd], &buf, sizeof(buf)) > 0);
|
||||
return ret == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PIWaitEvent::interrupt() {
|
||||
if (!isCreate()) return;
|
||||
#ifdef WINDOWS
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
class PIWaitEvent {
|
||||
class PIP_EXPORT PIWaitEvent {
|
||||
public:
|
||||
~PIWaitEvent();
|
||||
|
||||
@@ -44,6 +44,7 @@ public:
|
||||
void create();
|
||||
void destroy();
|
||||
bool wait(int fd = -1, CheckRole role = CheckRead);
|
||||
bool sleep(int us); // return if sleep done
|
||||
void interrupt();
|
||||
bool isCreate() const;
|
||||
void * getEvent() const; // WINDOWS only
|
||||
|
||||
Reference in New Issue
Block a user