#include <stdint.h>
#include <Arch/Arch.hpp>
#include <Memory/paging.hpp>
Go to the source code of this file.
- Author
- Micah Switzer (mswit.nosp@m.zer@.nosp@m.cedar.nosp@m.vill.nosp@m.e.edu)
- Version
- 0.3
- Date
- 2020-08-29
- Copyright
- Copyright the Xyris Contributors (c) 2020
Definition in file tasks.hpp.
◆ MAX_TASKS_QUEUED
#define MAX_TASKS_QUEUED 8 |
◆ TASK_ONLY
◆ TIME_SLICE_SIZE
#define TIME_SLICE_SIZE (1 * 1000 * 1000ULL) |
◆ task_alloc
Enumerator |
---|
ALLOC_STATIC | |
ALLOC_DYNAMIC | |
Definition at line 30 of file tasks.hpp.
◆ task_state
Enumerator |
---|
TASK_RUNNING | |
TASK_READY | |
TASK_SLEEPING | |
TASK_BLOCKED | |
TASK_STOPPED | |
TASK_PAUSED | |
TASK_STATE_COUNT | |
Definition at line 19 of file tasks.hpp.
◆ tasks_block_current()
Blocks the current task.
- Parameters
-
Definition at line 422 of file tasks.cpp.
424 _aquire_scheduler_lock();
428 _release_scheduler_lock();
◆ tasks_exit()
Exits the current task.
Definition at line 511 of file tasks.cpp.
516 _aquire_scheduler_lock();
526 _release_scheduler_lock();
◆ tasks_get_self_time()
uint64_t tasks_get_self_time |
( |
| ) |
|
Returns the lifetime of the current task (in nanoseconds).
- Returns
- uint64_t Task lifetime (in nanoseconds)
Definition at line 416 of file tasks.cpp.
◆ tasks_init()
Initializes the kernel task manager.
Definition at line 151 of file tasks.cpp.
154 struct task *this_task = &_first_task;
156 _discover_cpu_speed();
180 _last_time = _get_cpu_time_ns();
181 _last_timer_time = _last_time;
◆ tasks_nano_sleep()
void tasks_nano_sleep |
( |
uint64_t |
time | ) |
|
Sleep for a given period of time (in nanoseconds).
- Parameters
-
Definition at line 506 of file tasks.cpp.
◆ tasks_nano_sleep_until()
void tasks_nano_sleep_until |
( |
uint64_t |
time | ) |
|
Sleeps until the provided absolute time (in nanoseconds).
- Parameters
-
time | Absolute time to sleep until (in nanoseconds since boot) |
Definition at line 494 of file tasks.cpp.
497 _aquire_scheduler_lock();
503 _release_scheduler_lock();
◆ tasks_new()
struct task* tasks_new |
( |
void(*)(void) |
entry, |
|
|
struct task * |
storage, |
|
|
task_state |
state, |
|
|
const char * |
name |
|
) |
| |
Creates a new kernel task with a provided entry point, register storage struct, and task state struct. If the storage parameter is provided, the struct task struct provided will be written to. If NULL is passed as the storage parameter, a pointer to a allocated task will be returned.
- Parameters
-
entry | Task function entry point |
storage | Task stack structure (if NULL, a pointer to the task is returned) |
state | Task state structure |
name | Task name (for debugging / printing) |
- Returns
- struct task* Pointer to the created kernel task
Definition at line 289 of file tasks.cpp.
291 struct task *new_task = storage;
292 if (storage == NULL) {
296 if (new_task == NULL) {
297 panic(
"Unable to allocate memory for new task struct.");
304 panic(
"Unable to allocate memory for new task stack.");
309 _stack_push_word(&stack_pointer, 0);
311 _stack_push_word(&stack_pointer, (
size_t)_task_stopping);
313 _stack_push_word(&stack_pointer, (
size_t)entry);
316 _stack_push_word(&stack_pointer, (
size_t)_task_starting);
318 _stack_push_word(&stack_pointer, 0);
319 _stack_push_word(&stack_pointer, 0);
320 _stack_push_word(&stack_pointer, 0);
321 _stack_push_word(&stack_pointer, 0);
322 new_task->
stack_top = (uintptr_t)stack_pointer;
324 new_task->
next = NULL;
◆ tasks_schedule()
Tell the kernel task scheduler to schedule all of the added tasks.
Definition at line 406 of file tasks.cpp.
409 _aquire_scheduler_lock();
413 _release_scheduler_lock();
◆ tasks_switch_to()
void tasks_switch_to |
( |
struct task * |
task | ) |
|
Switches to a provided task.
- Parameters
-
task | Pointer to the task struct |
◆ tasks_sync_block()
void tasks_sync_block |
( |
struct task_sync * |
tsc | ) |
|
Definition at line 560 of file tasks.cpp.
562 _aquire_scheduler_lock();
564 if (ts->dbg_name != NULL) {
572 _release_scheduler_lock();
◆ tasks_sync_unblock()
void tasks_sync_unblock |
( |
struct task_sync * |
tsc | ) |
|
Definition at line 575 of file tasks.cpp.
577 _aquire_scheduler_lock();
579 if (ts->dbg_name != NULL) {
584 struct task *
task = ts->waiting.head;
595 }
while (
task != NULL);
596 ts->waiting.head = NULL;
597 ts->waiting.tail = NULL;
601 _release_scheduler_lock();
◆ tasks_unblock()
void tasks_unblock |
( |
struct task * |
task | ) |
|
Unblocks the current task.
- Parameters
-
Definition at line 431 of file tasks.cpp.
433 _aquire_scheduler_lock();
437 _release_scheduler_lock();
◆ current_task
struct task* current_task |