forked from Yahya-Ashraf-Mohamed/OS_Scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c33349
commit 424ed11
Showing
20 changed files
with
1,181 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
At time 2 process 4 started arr 17 total 20 remain 20 wait -15 | ||
At time 12 process 4 stopped arr 17 total 20 remain 10 wait -15 | ||
At time 12 process 1 started arr 2 total 10 remain 10 wait 10 | ||
At time 21 process 1 finished arr 2 total 10 remain 0 wait 10 TA 19 WTA 1.90 | ||
At time 21 process 2 started arr 5 total 4 remain 4 wait 16 | ||
At time 25 process 2 finished arr 5 total 4 remain 0 wait 16 TA 20 WTA 5.00 | ||
At time 25 process 3 started arr 7 total 3 remain 3 wait 18 | ||
At time 28 process 3 finished arr 7 total 3 remain 0 wait 18 TA 21 WTA 7.00 | ||
At time 28 process 4 resumed arr 17 total 20 remain 10 wait 1 | ||
At time 38 process 4 finished arr 17 total 20 remain 0 wait 1 TA 21 WTA 1.05 | ||
At time 38 process 4 started arr 17 total 20 remain 20 wait 21 | ||
At time 57 process 4 finished arr 17 total 20 remain 0 wait 21 TA 40 WTA 2.00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#include "Header_File/Min_Heap.h" | ||
|
||
#include <stdlib.h> | ||
|
||
#ifndef SC_HEAP_MAX | ||
#define SC_HEAP_MAX SIZE_MAX / sizeof(struct sc_heap_data) | ||
#endif | ||
|
||
bool sc_heap_init(struct sc_heap *h, size_t cap) | ||
{ | ||
void *e; | ||
const size_t sz = cap * sizeof(struct sc_heap_data); | ||
|
||
*h = (struct sc_heap){0}; | ||
|
||
if (cap == 0) { | ||
return true; | ||
} | ||
|
||
if (cap > SC_HEAP_MAX || (e = sc_heap_malloc(sz)) == NULL) { | ||
return false; | ||
} | ||
|
||
h->elems = e; | ||
h->cap = cap; | ||
|
||
return true; | ||
} | ||
|
||
void sc_heap_term(struct sc_heap *h) | ||
{ | ||
sc_heap_free(h->elems); | ||
|
||
*h = (struct sc_heap){ | ||
.elems = NULL, | ||
}; | ||
} | ||
|
||
size_t sc_heap_size(struct sc_heap *h) | ||
{ | ||
return h->size; | ||
} | ||
|
||
void sc_heap_clear(struct sc_heap *h) | ||
{ | ||
h->size = 0; | ||
} | ||
|
||
bool sc_heap_add(struct sc_heap *h, int64_t key, void *data) | ||
{ | ||
size_t i, cap, m; | ||
void *exp; | ||
|
||
if (++h->size >= h->cap) { | ||
cap = h->cap != 0 ? h->cap * 2 : 4; | ||
m = cap * 2 * sizeof(*h->elems); | ||
|
||
if (h->cap >= SC_HEAP_MAX / 2 || | ||
(exp = sc_heap_realloc(h->elems, m)) == NULL) { | ||
return false; | ||
} | ||
|
||
h->elems = exp; | ||
h->cap = cap; | ||
} | ||
|
||
i = h->size; | ||
while (i != 1 && key < h->elems[i / 2].key) { | ||
h->elems[i] = h->elems[i / 2]; | ||
i /= 2; | ||
} | ||
|
||
h->elems[i].key = key; | ||
h->elems[i].data = data; | ||
|
||
return true; | ||
} | ||
|
||
struct sc_heap_data *sc_heap_peek(struct sc_heap *h) | ||
{ | ||
if (h->size == 0) { | ||
return NULL; | ||
} | ||
|
||
// Top element is always at heap->elems[1]. | ||
return &h->elems[1]; | ||
} | ||
|
||
struct sc_heap_data *sc_heap_pop(struct sc_heap *h) | ||
{ | ||
size_t i = 1, child = 2; | ||
struct sc_heap_data last; | ||
|
||
if (h->size == 0) { | ||
return NULL; | ||
} | ||
|
||
// Top element is always at heap->elems[1]. | ||
h->elems[0] = h->elems[1]; | ||
|
||
last = h->elems[h->size--]; | ||
while (child <= h->size) { | ||
if (child < h->size && | ||
h->elems[child].key > h->elems[child + 1].key) { | ||
child++; | ||
}; | ||
|
||
if (last.key <= h->elems[child].key) { | ||
break; | ||
} | ||
|
||
h->elems[i] = h->elems[child]; | ||
|
||
i = child; | ||
child *= 2; | ||
} | ||
|
||
h->elems[i] = last; | ||
|
||
return &h->elems[0]; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.