mirror of https://github.com/BOINC/boinc.git
Condor: use flockfile() instead of pthread mutex
This commit is contained in:
parent
37e822fe3a
commit
74a8a8cad7
samples/condor
|
@ -49,14 +49,11 @@ char response_prefix[256];
|
||||||
// in which we send "R" when a command has completed.
|
// in which we send "R" when a command has completed.
|
||||||
// Synchronization is needed in case 2 commands complete around the same time.
|
// Synchronization is needed in case 2 commands complete around the same time.
|
||||||
//
|
//
|
||||||
pthread_mutex_t io_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
|
||||||
bool wrote_r = false;
|
bool wrote_r = false;
|
||||||
bool async_mode = false;
|
bool async_mode = false;
|
||||||
|
|
||||||
#define BPRINTF(fmt, ...) \
|
#define BPRINTF(fmt, ...) \
|
||||||
pthread_mutex_lock(&io_lock); \
|
|
||||||
printf( "%s" fmt, response_prefix, ##__VA_ARGS__ ); \
|
printf( "%s" fmt, response_prefix, ##__VA_ARGS__ ); \
|
||||||
pthread_mutex_unlock(&io_lock);
|
|
||||||
|
|
||||||
bool debug_mode = false;
|
bool debug_mode = false;
|
||||||
// if set, handle commands synchronously rather than
|
// if set, handle commands synchronously rather than
|
||||||
|
@ -562,13 +559,13 @@ void* handle_command_aux(void* q) {
|
||||||
} else {
|
} else {
|
||||||
c.out = strdup("Unknown command");
|
c.out = strdup("Unknown command");
|
||||||
}
|
}
|
||||||
pthread_mutex_lock(&io_lock);
|
flockfile(stdout);
|
||||||
if ( async_mode && !wrote_r ) {
|
if ( async_mode && !wrote_r ) {
|
||||||
BPRINTF("R\n");
|
BPRINTF("R\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
wrote_r = true;
|
wrote_r = true;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&io_lock);
|
funlockfile(stdout);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -629,24 +626,24 @@ int handle_command(char* p) {
|
||||||
} else if (!strcasecmp(cmd, "COMMANDS")) {
|
} else if (!strcasecmp(cmd, "COMMANDS")) {
|
||||||
BPRINTF("S ASYNC_MODE_OFF ASYNC_MODE_ON BOINC_ABORT_JOBS BOINC_FETCH_OUTPUT BOINC_PING BOINC_QUERY_BATCHES BOINC_RETIRE_BATCH BOINC_SELECT_PROJECT BOINC_SUBMIT COMMANDS QUIT RESULTS VERSION\n");
|
BPRINTF("S ASYNC_MODE_OFF ASYNC_MODE_ON BOINC_ABORT_JOBS BOINC_FETCH_OUTPUT BOINC_PING BOINC_QUERY_BATCHES BOINC_RETIRE_BATCH BOINC_SELECT_PROJECT BOINC_SUBMIT COMMANDS QUIT RESULTS VERSION\n");
|
||||||
} else if (!strcasecmp(cmd, "RESPONSE_PREFIX")) {
|
} else if (!strcasecmp(cmd, "RESPONSE_PREFIX")) {
|
||||||
pthread_mutex_lock(&io_lock);
|
flockfile(stdout);
|
||||||
BPRINTF("S\n");
|
BPRINTF("S\n");
|
||||||
strcpy(response_prefix, p+strlen("RESPONSE_PREFIX "));
|
strcpy(response_prefix, p+strlen("RESPONSE_PREFIX "));
|
||||||
pthread_mutex_unlock(&io_lock);
|
funlockfile(stdout);
|
||||||
} else if (!strcasecmp(cmd, "ASYNC_MODE_ON")) {
|
} else if (!strcasecmp(cmd, "ASYNC_MODE_ON")) {
|
||||||
pthread_mutex_lock(&io_lock);
|
flockfile(stdout);
|
||||||
BPRINTF("S\n");
|
BPRINTF("S\n");
|
||||||
async_mode = true;
|
async_mode = true;
|
||||||
pthread_mutex_unlock(&io_lock);
|
funlockfile(stdout);
|
||||||
} else if (!strcasecmp(cmd, "ASYNC_MODE_OFF")) {
|
} else if (!strcasecmp(cmd, "ASYNC_MODE_OFF")) {
|
||||||
pthread_mutex_lock(&io_lock);
|
flockfile(stdout);
|
||||||
BPRINTF("S\n");
|
BPRINTF("S\n");
|
||||||
async_mode = false;
|
async_mode = false;
|
||||||
pthread_mutex_unlock(&io_lock);
|
funlockfile(stdout);
|
||||||
} else if (!strcasecmp(cmd, "QUIT")) {
|
} else if (!strcasecmp(cmd, "QUIT")) {
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if (!strcasecmp(cmd, "RESULTS")) {
|
} else if (!strcasecmp(cmd, "RESULTS")) {
|
||||||
pthread_mutex_lock(&io_lock);
|
flockfile(stdout);
|
||||||
BPRINTF("S %d\n", n_results());
|
BPRINTF("S %d\n", n_results());
|
||||||
vector<COMMAND*>::iterator i = commands.begin();
|
vector<COMMAND*>::iterator i = commands.begin();
|
||||||
while (i != commands.end()) {
|
while (i != commands.end()) {
|
||||||
|
@ -660,7 +657,7 @@ int handle_command(char* p) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wrote_r = false;
|
wrote_r = false;
|
||||||
pthread_mutex_unlock(&io_lock);
|
funlockfile(stdout);
|
||||||
} else if (!strcasecmp(cmd, "BOINC_SELECT_PROJECT")) {
|
} else if (!strcasecmp(cmd, "BOINC_SELECT_PROJECT")) {
|
||||||
int n = sscanf(p, "%s %s %s", cmd, project_url, authenticator);
|
int n = sscanf(p, "%s %s %s", cmd, project_url, authenticator);
|
||||||
if (n ==3) {
|
if (n ==3) {
|
||||||
|
|
Loading…
Reference in New Issue