[Hardware OS Scheduler Interface] Functionality for process queues. More...
#include "hstructures.h"
Go to the source code of this file.
Defines | |
#define | HSQUEUE_MAX_QUEUES 1000 |
Defines the max amount of hsqueues in the system. | |
Functions | |
int | hsqueue_size (struct hsqueue *element) |
Get size of queue. | |
int | hsqueue_get_state (struct hsqueue *queue) |
Get state of the processes in the queue. | |
struct hsqueue * | hsqueue_get_prev (struct hsqueue *element) |
Get previous queue in list. | |
struct hsqueue * | hsqueue_get_next (struct hsqueue *element) |
Get next queue in list. | |
struct hsqueue * | hsqueue_create () |
Create a new queue. | |
int | hsqueue_remove (struct hsqueue *element) |
Remove a given queue. | |
struct hprocess * | hsqueue_get_first_process (struct hsqueue *queue) |
Get first process in the queue. | |
struct hprocess * | hsqueue_get_last_process (struct hsqueue *queue) |
Get last process in the queue. | |
int | hsqueue_enqueue_process (struct hsqueue *queue, struct hprocess *process) |
Enqueue the given process. | |
struct hprocess * | hsqueue_dequeue_process (struct hsqueue *queue) |
Dequeue the given process. | |
int | hsqueue_remove_process (struct hsqueue *queue, struct hprocess *process) |
Removes the given process from queue. | |
int | hsqueue_get_parent_list (struct hsqueue *queue) |
Get parent list of the queue. | |
int | hsqueue_register_signal (int signal, int(*function)()) |
Register the given signal. |
[Hardware OS Scheduler Interface] Functionality for process queues.
The main purpose of this module is to keep track of queues of processes. There is also functionality for linking several queues together in a double linked list.
Each queue contains processes of the same priority. Each list of queues contains queues of different priorities, but with the same state.
Author (2011): Sindre Hansen
Definition in file hsqueue.h.
struct hsqueue* hsqueue_create | ( | ) | [read] |
Create a new queue.
Definition at line 250 of file hsqueue.c.
{ struct hsqueue* queue = calloc(1, sizeof(*queue)); set_next_(queue, NULL); set_prev_(queue, NULL); set_first_process_(queue, NULL); set_last_process_(queue, NULL); set_size_(queue, 0); set_parent_list_(queue, -1); hsqlist_register_signal(HSIGNAL_ADD_QUEUE, add_queue_callback_); hsqlist_register_signal(HSIGNAL_REMOVE_QUEUE, remove_queue_callback_); return queue; }
Dequeue the given process.
queue | Queue element. |
Dequeue is the same as removing the first process in the queue.
Definition at line 310 of file hsqueue.c.
{ if (queue == NULL) return NULL; struct hprocess* process = hsqueue_get_first_process(queue); if (hsqueue_remove_process(queue, process) == 0) return process; else return NULL; }
Enqueue the given process.
queue | Queue element. | |
process | Process element. |
Definition at line 267 of file hsqueue.c.
{ if (process == NULL) return -1; struct hprocess* last_process = hsqueue_get_last_process(queue); // Signalize change in process structure to process module. signal_enqueue_process_(process, last_process); if (last_process == NULL) { set_first_process_(queue, process); } set_last_process_(queue, process); return increment_size_(queue); }
Get first process in the queue.
element | Queue element. |
Definition at line 333 of file hsqueue.c.
{ if (queue == NULL) return NULL; return queue->first_process; }
Get last process in the queue.
element | Queue element. |
Definition at line 342 of file hsqueue.c.
{ if (queue == NULL) return NULL; return queue->last_process; }
int hsqueue_get_parent_list | ( | struct hsqueue * | queue | ) |
Get parent list of the queue.
queue | Queue element. |
Definition at line 206 of file hsqueue.c.
{ if (queue == NULL) return -1; else if (queue->parent_list < 0) return -1; return queue->parent_list; }
int hsqueue_get_state | ( | struct hsqueue * | queue | ) |
Get state of the processes in the queue.
This functions assumes that all processes in the queue has the same state.
queue | Pointer to the queue. |
Definition at line 226 of file hsqueue.c.
{
return hprocess_get_state( hsqueue_get_first_process(queue) );
}
int hsqueue_register_signal | ( | int | signal, | |
int(*)() | function | |||
) |
Register the given signal.
This functionality is part of an observer-observable pattern between the queue module and the process module (to keep correct encapsulation).
The process module register a given signal with the queue module.
After a signal is registered, changes done in the queue will make sure the internal structure in the affected processes are updated.
list | The signal as defined by enum hsignal in hsignal.h. | |
function | Pointer to the callback function in the hprocess module. |
Definition at line 189 of file hsqueue.c.
{ switch (signal) { case HSIGNAL_ADD_PROCESS: signal_enqueue_process_ = function; return 0; case HSIGNAL_REMOVE_PROCESS: signal_remove_process_ = function; return 0; default: return -1; } return -1; }
int hsqueue_remove | ( | struct hsqueue * | element | ) |
Removes the given process from queue.
This function does NOT free the given process from memory.
queue | Queue element. | |
process | Process element. |
This function can be called by hprocess_remove. This function must remove process even though the queue does not exist (orphan processes may exist).
Definition at line 287 of file hsqueue.c.
{ if (process == NULL) return -1; if (process == hsqueue_get_first_process(queue)) set_first_process_(queue, hprocess_get_next(process)); if (process == hsqueue_get_last_process(queue)) set_last_process_(queue, hprocess_get_prev(process)); decrement_size_(queue); // Ask process module to clean up internal structure (but not remove process from memory). signal_remove_process_(process); return 0; }
int hsqueue_size | ( | struct hsqueue * | element | ) |
Get size of queue.
element | The queue. |
Definition at line 217 of file hsqueue.c.
{ if (element == NULL) return -1; return element->processes_num; }