condvar fixes
This commit is contained in:
@@ -839,7 +839,7 @@ PIObject::Deleter::Deleter() {
|
|||||||
PRIVATE->thread.setSlot([this](){
|
PRIVATE->thread.setSlot([this](){
|
||||||
PIVector<PIObject*> oq;
|
PIVector<PIObject*> oq;
|
||||||
PRIVATE->thread.lock();
|
PRIVATE->thread.lock();
|
||||||
PRIVATE->cond_var.wait(PRIVATE->thread.mutex());
|
if (PRIVATE->obj_queue.isEmpty()) PRIVATE->cond_var.wait(PRIVATE->thread.mutex());
|
||||||
oq.swap(PRIVATE->obj_queue);
|
oq.swap(PRIVATE->obj_queue);
|
||||||
PRIVATE->thread.unlock();
|
PRIVATE->thread.unlock();
|
||||||
for (PIObject * o : oq) deleteObject(o);
|
for (PIObject * o : oq) deleteObject(o);
|
||||||
@@ -851,9 +851,7 @@ PIObject::Deleter::Deleter() {
|
|||||||
PIObject::Deleter::~Deleter() {
|
PIObject::Deleter::~Deleter() {
|
||||||
//piCout << "~Deleter ...";
|
//piCout << "~Deleter ...";
|
||||||
PRIVATE->thread.stop();
|
PRIVATE->thread.stop();
|
||||||
PRIVATE->thread.mutex().lock();
|
|
||||||
PRIVATE->cond_var.notifyAll();
|
PRIVATE->cond_var.notifyAll();
|
||||||
PRIVATE->thread.mutex().unlock();
|
|
||||||
PRIVATE->thread.waitForFinish();
|
PRIVATE->thread.waitForFinish();
|
||||||
for (PIObject * o : PRIVATE->obj_queue) deleteObject(o);
|
for (PIObject * o : PRIVATE->obj_queue) deleteObject(o);
|
||||||
//piCout << "~Deleter ok";
|
//piCout << "~Deleter ok";
|
||||||
|
|||||||
@@ -278,9 +278,7 @@ bool _PITimerImp_Thread::startTimer(double interval_ms) {
|
|||||||
|
|
||||||
bool _PITimerImp_Thread::stopTimer(bool wait) {
|
bool _PITimerImp_Thread::stopTimer(bool wait) {
|
||||||
thread_.stop();
|
thread_.stop();
|
||||||
thread_.mutex().lock();
|
|
||||||
event.notifyAll();
|
event.notifyAll();
|
||||||
thread_.mutex().unlock();
|
|
||||||
if (wait) return thread_.waitForFinish();
|
if (wait) return thread_.waitForFinish();
|
||||||
// if (wait)
|
// if (wait)
|
||||||
// if (!thread_.waitForFinish(10))
|
// if (!thread_.waitForFinish(10))
|
||||||
|
|||||||
16
main.cpp
16
main.cpp
@@ -87,7 +87,7 @@ void phase(const char * msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
piCout << "main";
|
/*piCout << "main";
|
||||||
|
|
||||||
PITimer timer;
|
PITimer timer;
|
||||||
timer.setSlot([](){
|
timer.setSlot([](){
|
||||||
@@ -101,7 +101,19 @@ int main(int argc, char * argv[]) {
|
|||||||
PITimeMeasurer tm;
|
PITimeMeasurer tm;
|
||||||
timer.stop();
|
timer.stop();
|
||||||
double tm_ms = tm.elapsed_m();
|
double tm_ms = tm.elapsed_m();
|
||||||
piCout << "stop took" << tm_ms;
|
piCout << "stop took" << tm_ms;*/
|
||||||
|
|
||||||
|
PIWaitEvent event;
|
||||||
|
event.create();
|
||||||
|
tm.reset();
|
||||||
|
PIThread::runOnce([&event](){
|
||||||
|
//piMSleep(100);
|
||||||
|
piCout << "interrupt";
|
||||||
|
//event.interrupt();
|
||||||
|
});
|
||||||
|
event.sleep(2010000);
|
||||||
|
double tm_ms = tm.elapsed_m();
|
||||||
|
piCout << "waited for" << tm_ms;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/*for (int i = 0; i < count; ++i)
|
/*for (int i = 0; i < count; ++i)
|
||||||
|
|||||||
Reference in New Issue
Block a user