2016-11-18 19:57:51 -08:00
|
|
|
#include "task.h"
|
|
|
|
#include "task_table.h"
|
|
|
|
|
|
|
|
#include "global_scheduler_algorithm.h"
|
|
|
|
|
2016-12-06 15:47:31 -08:00
|
|
|
global_scheduler_policy_state *init_global_scheduler_policy(void) {
|
|
|
|
global_scheduler_policy_state *policy_state =
|
|
|
|
malloc(sizeof(global_scheduler_policy_state));
|
|
|
|
policy_state->round_robin_index = 0;
|
|
|
|
return policy_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroy_global_scheduler_policy(
|
|
|
|
global_scheduler_policy_state *policy_state) {
|
|
|
|
free(policy_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_task_waiting(global_scheduler_state *state,
|
|
|
|
global_scheduler_policy_state *policy_state,
|
|
|
|
task *task) {
|
2016-11-18 19:57:51 -08:00
|
|
|
if (utarray_len(state->local_schedulers) > 0) {
|
2016-12-06 15:47:31 -08:00
|
|
|
local_scheduler *scheduler = (local_scheduler *) utarray_eltptr(
|
|
|
|
state->local_schedulers, policy_state->round_robin_index);
|
|
|
|
policy_state->round_robin_index += 1;
|
|
|
|
policy_state->round_robin_index %= utarray_len(state->local_schedulers);
|
2016-11-18 19:57:51 -08:00
|
|
|
assign_task_to_local_scheduler(state, task, scheduler->id);
|
|
|
|
} else {
|
|
|
|
CHECKM(0, "We currently don't handle this case.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_object_available(global_scheduler_state *state,
|
2016-12-06 15:47:31 -08:00
|
|
|
global_scheduler_policy_state *policy_state,
|
2016-11-18 19:57:51 -08:00
|
|
|
object_id object_id) {
|
|
|
|
/* Do nothing for now. */
|
|
|
|
}
|
|
|
|
|
2016-12-06 15:47:31 -08:00
|
|
|
void handle_local_scheduler_heartbeat(
|
|
|
|
global_scheduler_state *state,
|
|
|
|
global_scheduler_policy_state *policy_state) {
|
2016-11-18 19:57:51 -08:00
|
|
|
/* Do nothing for now. */
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_new_local_scheduler(global_scheduler_state *state,
|
2016-12-06 15:47:31 -08:00
|
|
|
global_scheduler_policy_state *policy_state,
|
2016-11-18 19:57:51 -08:00
|
|
|
db_client_id db_client_id) {
|
2016-11-19 12:19:49 -08:00
|
|
|
local_scheduler local_scheduler;
|
|
|
|
memset(&local_scheduler, 0, sizeof(local_scheduler));
|
|
|
|
local_scheduler.id = db_client_id;
|
2016-11-18 19:57:51 -08:00
|
|
|
utarray_push_back(state->local_schedulers, &local_scheduler);
|
|
|
|
}
|