TaskQueuedStrategy::TaskQueuedStrategy(stream_protocol::socket &msocket) :
clientSocket(msocket) {
runThread = false;
+ cmdReady = false;
}
/**
LOGD(TEE_STUB, "A Cancel command has been received!");
executeCancellation(command);
} else {
- map_mutex.lock();
+ boost::unique_lock<boost::mutex> lck(ready_mutex);
//If new session ID, just add to map
if (sessionTaskMap.find(command->sessionID) == sessionTaskMap.end()) {
SessionState ss(command->sessionID);
sessionTaskMap[command->sessionID].addTask(command);
}
LOGD(TEE_STUB, "MapSize: %d", sessionTaskMap.size());
- map_mutex.unlock();
+ cmdReady = true;
+ ready_cond.notify_all();
}
}
*/
unsigned char writeData[1024];
while (runThread) {
- map_mutex.lock();
+ boost::unique_lock<boost::mutex> lck(ready_mutex);
+ while (!cmdReady) ready_cond.wait(lck);
if (sessionTaskMap.size() > 0) {
for (std::map<uint32_t, SessionState>::iterator itr =
} //if queue
} //for
} //if map
- map_mutex.unlock();
+ cmdReady = false; // all commands done
// TODO: check how to reduce cycles from while(1)
// boost::this_thread::sleep(boost::posix_time::milliseconds(1));
class TaskQueuedStrategy:
public TaskStrategy {
private:
+ boost::mutex ready_mutex;
+ boost::condition_variable ready_cond;
+ bool cmdReady;
+
std::map<uint32_t, SessionState> sessionTaskMap;
std::vector<CommandRequestCancel> cancelVector;
boost::thread executorThread;
- boost::mutex map_mutex;
// The socket used to communicate with the client.
stream_protocol::socket &clientSocket;