diff options
author | Andreas Volz <andreas.volz@tux-style.com> | 2011-11-28 14:02:43 +0100 |
---|---|---|
committer | Andreas Volz <andreas.volz@tux-style.com> | 2011-11-28 14:02:43 +0100 |
commit | 25f8eade72fb3ff4c651f7b90bde52b6a962530c (patch) | |
tree | 5a8ae8377c3d43fc3cd24a6d09a8ea3a82ab427f | |
parent | 1c8e43e6d60205b427c2c7540254c6d6fb9c2682 (diff) | |
parent | 1eb7c3df2f0bce3f842e121586fe350c941a937d (diff) | |
download | dbus-c++-merge-requests/5.tar.gz |
Merge commit 'refs/merge-requests/5' of git://gitorious.org/dbus-cplusplus/mainline into merge-requests/5merge-requests/5
Conflicts:
src/dispatcher.cpp
src/eventloop-integration.cpp
-rw-r--r-- | src/dispatcher.cpp | 42 | ||||
-rw-r--r-- | src/eventloop-integration.cpp | 8 | ||||
-rw-r--r-- | test/functional/Test1/TestApp.cpp | 3 |
3 files changed, 32 insertions, 21 deletions
diff --git a/src/dispatcher.cpp b/src/dispatcher.cpp index bc07d71..e6d2d86 100644 --- a/src/dispatcher.cpp +++ b/src/dispatcher.cpp @@ -218,30 +218,36 @@ void Dispatcher::dispatch_pending() void Dispatcher::dispatch_pending(Connection::PrivatePList &pending_queue) { - // SEEME: dbus-glib is dispatching only one message at a time to not starve the loop/other things... - _mutex_p_copy.lock(); - while (pending_queue.size() > 0) - { - Connection::PrivatePList::iterator i, j; + + // Make sure to return after some time. In particular, we do not + // want to call do_dispatch twice if an item is pushed back into the + // queue. + for (int i = _pending_queue.size(); i > 0; i--) + { + Connection::Private* x; - i = pending_queue.begin(); + // This should never happen, but just in case someone else + // removed items from the queue. + if (_pending_queue.size() == 0) + break; // Mutex is released after the for loop. - while (i != pending_queue.end()) - { - j = i; + x = _pending_queue.front(); + _pending_queue.pop_front(); - ++j; + _mutex_p.unlock(); - if ((*i)->do_dispatch()) - pending_queue.erase(i); - else - debug_log("dispatch_pending_private: do_dispatch error"); + if (!x->do_dispatch()) + { + _mutex_p.lock(); + _pending_queue.push_back(x); + _mutex_p.unlock(); + } - i = j; - } - } - _mutex_p_copy.unlock(); + _mutex_p.lock(); + } + + _mutex_p.unlock(); } void DBus::_init_threading() diff --git a/src/eventloop-integration.cpp b/src/eventloop-integration.cpp index 0cc65c3..593808a 100644 --- a/src/eventloop-integration.cpp +++ b/src/eventloop-integration.cpp @@ -144,8 +144,12 @@ void BusDispatcher::del_pipe(Pipe *pipe) void BusDispatcher::do_iteration() { - dispatch_pending(); - dispatch(); + dispatch_pending(); + // Only check for events, if there is nothing in the queue. + // TODO: It would be better to just prevent the poll from sleeping + // in this case. + if (!has_something_to_dispatch()) + dispatch(); } Timeout *BusDispatcher::add_timeout(Timeout::Internal *ti) diff --git a/test/functional/Test1/TestApp.cpp b/test/functional/Test1/TestApp.cpp index 0dcaac5..c4c2530 100644 --- a/test/functional/Test1/TestApp.cpp +++ b/test/functional/Test1/TestApp.cpp @@ -94,7 +94,7 @@ void TestApp::testHandler(const void *data, void *buffer, unsigned int nbyte) char *str = (char *) buffer; cout << "buffer1: " << str << ", size: " << nbyte << endl; - cout << "run it!" << endl; + cout << "+run it!" << endl; if (string(str) == "test1") { g_testComIntro->test1(); @@ -103,4 +103,5 @@ void TestApp::testHandler(const void *data, void *buffer, unsigned int nbyte) { g_testComIntro->testByte(4); } + cout << "-run it!" << endl; } |