------------------------------------------------------------ revno: 3099 committer: poy <p...@123gen.com> branch nick: trunk timestamp: Tue 2012-10-30 19:48:58 +0100 message: replace the dev plugin's mutex by a lock-free queue modified: plugins/Dev/Dialog.cpp plugins/Dev/Dialog.h
-- lp:dcplusplus https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk Your team Dcplusplus-team is subscribed to branch lp:dcplusplus. To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'plugins/Dev/Dialog.cpp' --- plugins/Dev/Dialog.cpp 2012-10-29 18:19:03 +0000 +++ plugins/Dev/Dialog.cpp 2012-10-30 18:48:58 +0000 @@ -36,6 +36,7 @@ Dialog::Dialog() : hwnd(nullptr), + messages(1024), counter(0), scroll(true), hubMessages(true), @@ -68,8 +69,7 @@ void Dialog::write(bool hubOrUser, bool sending, string ip, string peer, string message) { Message msg = { hubOrUser, sending, move(ip), move(peer), move(message) }; - Lock l(mutex); - messages.push_back(move(msg)); + messages.push(msg); } void Dialog::close() { @@ -148,20 +148,13 @@ } void Dialog::timer() { - decltype(messages) messages_; - { - Lock l(mutex); - messages_.swap(messages); - } - if(messages_.empty()) { - return; - } - auto control = GetDlgItem(hwnd, IDC_MESSAGES); LVITEM lvi = { 0 }; - for(auto& message: messages_) { + Message message; + while(messages.pop(message)) { + if(!(message.hubOrUser ? hubMessages : userMessages)) { continue; } === modified file 'plugins/Dev/Dialog.h' --- plugins/Dev/Dialog.h 2012-10-29 18:19:03 +0000 +++ plugins/Dev/Dialog.h 2012-10-30 18:48:58 +0000 @@ -20,19 +20,13 @@ #define PLUGINS_DEV_DIALOG_H #include <unordered_set> -#include <vector> +#include <boost/lockfree/queue.hpp> #include <boost/regex.hpp> -#include <CriticalSection.h> - using std::move; using std::string; using std::unordered_set; -using std::vector; - -using dcpp::CriticalSection; -using dcpp::Lock; class Dialog { @@ -65,9 +59,7 @@ // store the messages to be displayed here; process them with a timer. struct Message { bool hubOrUser; bool sending; string ip; string peer; string message; }; - vector<Message> messages; - - CriticalSection mutex; + boost::lockfree::queue<Message> messages; uint16_t counter; bool scroll;
_______________________________________________ Mailing list: https://launchpad.net/~linuxdcpp-team Post to : linuxdcpp-team@lists.launchpad.net Unsubscribe : https://launchpad.net/~linuxdcpp-team More help : https://help.launchpad.net/ListHelp