Finished multi-slot functionality

svn path=/trunk/boinc/; revision=381
This commit is contained in:
Eric Heien 2002-08-26 22:14:06 +00:00
parent 9b038c99d5
commit e029476a87
4 changed files with 46 additions and 1 deletions

View File

@ -1699,3 +1699,14 @@ David August 25, 2002
test_uc_win.php
tools/
add.C
Eric August 26, 2002
- Finished multi-slot functionality. The client now requests an
open slot from the ACTIVE_TASK_SET which will be the slot
for the new process.
client/
app.C
app.h
cs_apps.C

View File

@ -648,6 +648,35 @@ bool ACTIVE_TASK_SET::poll_time() {
return updated;
}
// Gets the next available free slot, or returns -1 if all slots are full
//
int ACTIVE_TASK_SET::get_free_slot(int total_slots) {
int start_slot,i;
char *slot_status;
if (active_tasks.size() >= total_slots)
return -1;
slot_status = (char *)calloc( sizeof(char), total_slots );
if (!slot_status) return -1;
for (i=0; i<active_tasks.size(); i++) {
if (active_tasks[i]->slot >= 0 && active_tasks[i]->slot < total_slots) {
slot_status[active_tasks[i]->slot] = 1;
}
}
for (i=0; i<total_slots; i++) {
if (!slot_status[i]) {
free(slot_status);
return i;
}
}
free(slot_status);
return -1;
}
// Write XML data about this ACTIVE_TASK
//
int ACTIVE_TASK::write(FILE* fout) {

View File

@ -98,6 +98,7 @@ public:
void unsuspend_all();
int restart_tasks();
void exit_tasks();
int get_free_slot(int total_slots);
int write(FILE*);
int parse(FILE*, CLIENT_STATE*);

View File

@ -151,11 +151,14 @@ bool CLIENT_STATE::start_apps() {
RESULT* rp;
ACTIVE_TASK* atp;
bool action = false;
int open_slot;
for (i=0; i<results.size(); i++) {
// If all the app slots are already used, we can't start
// a new app
if (active_tasks.active_tasks.size() == nslots) {
open_slot = active_tasks.get_free_slot(nslots);
if (open_slot < 0) {
if (log_flags.task_debug) {
printf("start_apps(): all slots full\n");
}
@ -172,6 +175,7 @@ bool CLIENT_STATE::start_apps() {
}
rp->is_active = true;
atp = new ACTIVE_TASK;
atp->slot = open_slot;
atp->init(rp);
active_tasks.insert(atp);
action = true;