1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
Description: Fix locking
Author: Simon Richter <sjr@debian.org>
Last-Update: 2023-12-16
--- librevisa-0.0.20130812.orig/src/messagepump.cpp
+++ librevisa-0.0.20130812/src/messagepump.cpp
@@ -32,11 +32,20 @@
namespace librevisa {
messagepump::messagepump() throw() :
+ keep_running(true),
worker(*this)
{
return;
}
+messagepump::~messagepump() throw()
+{
+ keep_running = false;
+ lock l(cs);
+ cv.signal();
+ worker.kill(SIGUSR1);
+}
+
void messagepump::register_watch(watch &w)
{
worker.start();
@@ -120,7 +129,7 @@ void messagepump::run()
timeval now;
::gettimeofday(&now, 0);
- for(;;)
+ while(keep_running)
{
timeout *expired = 0;
bool have_timeout = false;
@@ -212,6 +221,9 @@ void messagepump::run()
next_as_ts.tv_nsec = next.tv_usec * 1000;
}
+ if(maxfd == -1 && !have_timeout)
+ break;
+
int rc = ::pselect(maxfd + 1, &readfds, &writefds, &exceptfds, have_timeout? &next_as_ts : 0, &mask);
if(rc == -1)
{
--- librevisa-0.0.20130812.orig/src/messagepump.h
+++ librevisa-0.0.20130812/src/messagepump.h
@@ -33,6 +33,7 @@ class messagepump :
{
public:
messagepump() throw();
+ ~messagepump() throw();
// thread::runnable
virtual void init();
@@ -84,6 +85,8 @@ public:
void update_timeout(timeout &, timeval const *);
private:
+ bool keep_running;
+
typedef intrusive_list<watch> watch_list;
typedef watch_list::iterator watch_iterator;
watch_list watches;
--- librevisa-0.0.20130812.orig/src/thread_pthread.h
+++ librevisa-0.0.20130812/src/thread_pthread.h
@@ -40,6 +40,12 @@ public:
};
thread(runnable &r) : sui(r) { }
+ ~thread() throw()
+ {
+ if(!sui.running)
+ return;
+ pthread_join(handle, 0);
+ }
void start()
{
@@ -54,6 +60,9 @@ public:
void kill(int sig)
{
+ if(!sui.running)
+ return;
+
pthread_kill(handle, sig);
}
|