- API: fix various bugs related to process control and critical sections.

- client: code cleanup (no functional change)


svn path=/trunk/boinc/; revision=25392
This commit is contained in:
David Anderson 2012-03-08 22:22:45 +00:00
parent 9c3e4b76f0
commit 5aa97b5578
2 changed files with 35 additions and 31 deletions

View File

@ -787,39 +787,44 @@ void MSG_QUEUE::init(char* n) {
void MSG_QUEUE::msg_queue_send(const char* msg, MSG_CHANNEL& channel) {
if ((msgs.size()==0) && channel.send_msg(msg)) {
if (log_flags.app_msg_send) {
msg_printf(NULL, MSG_INFO, "[app_msg_send] sent %s to %s", msg, name);
msg_printf(NULL, MSG_INFO,
"[app_msg_send] sent %s to %s", msg, name
);
}
last_block = 0;
return;
}
if (log_flags.app_msg_send) {
msg_printf(NULL, MSG_INFO, "[app_msg_send] deferred %s to %s", msg, name);
msg_printf(NULL, MSG_INFO,
"[app_msg_send] deferred %s to %s", msg, name
);
}
msgs.push_back(std::string(msg));
msgs.push_back(string(msg));
if (!last_block) last_block = gstate.now;
}
void MSG_QUEUE::msg_queue_poll(MSG_CHANNEL& channel) {
if (msgs.size() > 0) {
if (msgs.empty()) return;
if (log_flags.app_msg_send) {
msg_printf(NULL, MSG_INFO,
"[app_msg_send] poll: %d msgs queued for %s:",
(int)msgs.size(), name
);
}
if (channel.send_msg(msgs[0].c_str())) {
if (log_flags.app_msg_send) {
msg_printf(NULL, MSG_INFO,
"[app_msg_send] poll: %d msgs queued for %s:",
(int)msgs.size(), name
"[app_msg_send] poll: delayed sent %s", msgs[0].c_str()
);
}
if (channel.send_msg(msgs[0].c_str())) {
if (log_flags.app_msg_send) {
msg_printf(NULL, MSG_INFO, "[app_msg_send] poll: delayed sent %s", (msgs[0].c_str()));
}
msgs.erase(msgs.begin());
last_block = 0;
}
for (unsigned int i=0; i<msgs.size(); i++) {
if (log_flags.app_msg_send) {
msg_printf(NULL, MSG_INFO,
"[app_msg_send] poll: deferred: %s", (msgs[0].c_str())
);
}
msgs.erase(msgs.begin());
last_block = 0;
}
for (unsigned int i=0; i<msgs.size(); i++) {
if (log_flags.app_msg_send) {
msg_printf(NULL, MSG_INFO,
"[app_msg_send] poll: deferred: %s", msgs[0].c_str()
);
}
}
}
@ -827,23 +832,21 @@ void MSG_QUEUE::msg_queue_poll(MSG_CHANNEL& channel) {
// if the last message in the buffer is "msg", remove it and return 1
//
int MSG_QUEUE::msg_queue_purge(const char* msg) {
int count = (int)msgs.size();
if (!count) return 0;
vector<string>::iterator iter = msgs.begin();
for (int i=0; i<count-1; i++) {
iter++;
}
if (msgs.empty()) return 0;
string last_msg = msgs.back();
if (log_flags.app_msg_send) {
msg_printf(NULL, MSG_INFO,
"[app_msg_send] purge: wanted %s last msg is %s in %s",
msg, iter->c_str(), name
msg, last_msg.c_str(), name
);
}
if (!strcmp(msg, iter->c_str())) {
if (!strcmp(msg, last_msg.c_str())) {
if (log_flags.app_msg_send) {
msg_printf(NULL, MSG_INFO, "[app_msg_send] purged %s from %s", msg, name);
msg_printf(NULL, MSG_INFO,
"[app_msg_send] purged %s from %s", msg, name
);
}
iter = msgs.erase(iter);
msgs.pop_back();
return 1;
}
return 0;

View File

@ -1083,8 +1083,9 @@ void ACTIVE_TASK_SET::kill_tasks(PROJECT* proj) {
int ACTIVE_TASK::suspend() {
if (!app_client_shm.shm) return 0;
if (task_state() != PROCESS_EXECUTING) {
msg_printf(result->project, MSG_INFO,
"Internal error: expected process %s to be executing", result->name
msg_printf(result->project, MSG_INTERNAL_ERROR,
"ACTIVE_TASK::SUSPEND(): expected task %s to be executing",
result->name
);
}
int n = process_control_queue.msg_queue_purge("<resume/>");