31 #include <boost/bind.hpp>
32 #include <boost/shared_ptr.hpp>
33 #include <boost/thread.hpp>
34 #include <boost/thread/shared_mutex.hpp>
120 class Tasks:
public std::queue<Protocol::FullId>,
public boost::mutex {};
237 class Requests:
public std::map<Protocol::FullId, boost::shared_ptr<T> >,
public boost::shared_mutex {};
250 using namespace Protocol;
251 using namespace boost;
255 shared_lock<shared_mutex> reqReadLock(requests);
256 typename Requests::iterator it(requests.find(
id));
257 if(it!=requests.end())
259 lock_guard<mutex> mesLock(it->second->messages);
260 it->second->messages.push(message);
261 lock_guard<mutex> tasksLock(tasks);
264 else if(!message.
type)
266 Header& header=*(Header*)message.
data.get();
269 BeginRequest& body=*(BeginRequest*)(message.
data.get()+
sizeof(Header));
271 reqReadLock.unlock();
272 unique_lock<shared_mutex> reqWriteLock(requests);
274 boost::shared_ptr<T>& request = requests[id];
275 request.reset(
new T);
276 request->set(
id, transceiver, body.getRole(), !body.getKeepConn(), boost::bind(&Manager::push, boost::ref(*
this),
id, _1));
284 messages.push(message);
288 lock_guard<mutex> sleepLock(sleepMutex);
296 using namespace boost;
298 threadId=pthread_self();
303 lock_guard<mutex> stopLock(stopMutex);
311 bool sleep=transceiver.handler();
314 lock_guard<mutex> terminateLock(terminateMutex);
317 shared_lock<shared_mutex> requestsLock(requests);
318 if(requests.empty() && sleep)
326 unique_lock<mutex> tasksLock(tasks);
327 unique_lock<mutex> sleepLock(sleepMutex);
336 if(sleep) transceiver.sleep();
355 shared_lock<shared_mutex> reqReadLock(requests);
356 typename map<Protocol::FullId, boost::shared_ptr<T> >::iterator it(requests.find(
id));
357 if(it!=requests.end() && it->second->handler())
359 reqReadLock.unlock();
360 unique_lock<shared_mutex> reqWriteLock(requests);