| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include "kernel.h"
- #include "scheduler.h"
- #ifndef ZV_FULL_DISABLE_BALANCED_PRIORITY
- zv_process_t * zv_kernel_balanced_priority(zv_kernel_t *self) {
- zv_process_t *selected = NULL;
- zv_process_t *last = self->processes + self->last;
- zv_priority_t selected_priority = 0;
- bool full_round = true;
-
- for (
- zv_process_t *current = self->processes;
- current != (self->processes + self->processes_count);
- ++current
- ) {
- if (current->priority > self->lowest_priority) {
- self->lowest_priority = current->priority;
- }
- if (current->priority == self->lowest_priority) {
- full_round = full_round && current->balance > 0;
- }
- if (!zv_process_is_ready(current)) {
- continue;
- }
-
- zv_priority_t current_priority = _zv_process_calc_priority(current);
- if (current != last && current_priority > self->lowest_priority) {
- if (current->balance > 0) {
- --current->balance;
- }
- }
- if (selected == NULL) {
- selected = current;
- selected_priority = current_priority;
- continue;
- }
- if (current_priority <= selected_priority) {
- selected = current;
- selected_priority = current_priority;
- continue;
- }
- }
- if (full_round) {
- __zv_kernel_clean_balance(self);
- return zv_kernel_balanced_priority(self);
- }
- if (selected->balance < 255) {
- ++selected->balance;
- }
- return selected;
- }
- #else
- zv_process_t * zv_kernel_balanced_priority(zv_kernel_t *self) {
- return NULL;
- }
- #endif
|