[Hardware OS Scheduler Interface] Defines a list of process queues. More...
#include "hstructures.h"
Go to the source code of this file.
Functions | |
int | hsqlist_size (int list) |
Get size of list. | |
int | hsqlist_create (int list) |
Create new list. | |
struct hsqueue * | hsqlist_get_queue (int list, int priority) |
Get queue by priority in list. | |
int | hsqlist_add_queue (int list, struct hsqueue *queue) |
Add a queue to the list. | |
int | hsqlist_insert_queue_before (int list, struct hsqueue *second_queue, struct hsqueue *queue) |
Insert queue before another queue in the list. | |
int | hsqlist_get_state (int list) |
Get state of the processes in the list of queues. | |
struct hsqueue * | hsqlist_get_first_queue (int list) |
Get first queue in the list. | |
struct hsqueue * | hsqlist_get_last_queue (int list) |
Get last queue in the list. | |
int | hsqlist_is_valid_range (int list) |
Checks if the given list value is in valid range. | |
int | hsqlist_remove_queue (int list, struct hsqueue *queue) |
Remove the given queue from the list. | |
int | hsqlist_remove (int list) |
Remove the given list. | |
int | hsqlist_register_signal (int signal, int(*function)()) |
Register the given signal. |
[Hardware OS Scheduler Interface] Defines a list of process queues.
The main purpose of this module is to keep lists of process queues. Since there is a small and constant number of lists (as many as there are process states), lists are referenced by a number from 0 to HPS_NUMBER.
Author (2011): Sindre Hansen
Definition in file hsqlist.h.
int hsqlist_add_queue | ( | int | list, | |
struct hsqueue * | queue | |||
) |
Add a queue to the list.
list | The list. | |
queue | The queue to be added. |
Definition at line 258 of file hsqlist.c.
{ struct hsqlist* list_element = get_list_(list); // Signalize a change in the queue structure to the queue module. // Must be done before setting the last queue. signal_add_queue_(queue, hsqlist_get_last_queue(list), NULL, list); if (hsqlist_size(list) == 0) set_first_queue_(list_element, queue); set_last_queue_(list_element, queue); return increment_size_(list_element); }
int hsqlist_create | ( | int | list | ) |
Create new list.
list | The list. |
Definition at line 200 of file hsqlist.c.
{ if (!hsqlist_is_valid_range(list)) return -1; if (get_list_(list) != NULL) return -1; struct hsqlist* new_list = calloc(1, sizeof(*new_list)); set_size_(new_list, 0); set_first_queue_(new_list, NULL); set_last_queue_(new_list, NULL); set_list_(list, new_list); return 0; }
struct hsqueue* hsqlist_get_first_queue | ( | int | list | ) | [read] |
Get first queue in the list.
list | The list. |
Definition at line 303 of file hsqlist.c.
{ struct hsqlist* list_element = get_list_(list); if (list_element == NULL) return NULL; return list_element->first_queue; }
struct hsqueue* hsqlist_get_last_queue | ( | int | list | ) | [read] |
Get last queue in the list.
list | The list. |
Definition at line 314 of file hsqlist.c.
{ struct hsqlist* list_element = get_list_(list); if (list_element == NULL) return NULL; return list_element->last_queue; }
struct hsqueue* hsqlist_get_queue | ( | int | list, | |
int | priority | |||
) | [read] |
Get queue by priority in list.
list | The list. | |
priority | The priority of the processes in the queue. |
int hsqlist_get_state | ( | int | list | ) |
Get state of the processes in the list of queues.
This functions assumes that this list has a list of queues and that the all processes in the queues has the same state.
list | The list. |
Definition at line 292 of file hsqlist.c.
{ struct hsqueue* first_queue = hsqlist_get_first_queue(list); if (first_queue == NULL) return -1; return hsqueue_get_state(first_queue); }
Insert queue before another queue in the list.
list | The list. | |
second_queue | The queue that is already in the list. | |
queue | The queue to be inserted. |
Definition at line 275 of file hsqlist.c.
{ struct hsqlist* list_element = get_list_(list); // Signalize a change in the queue structure to the queue module. signal_add_queue_(queue, hsqueue_get_prev(second_queue), second_queue, list); if (hsqlist_size(list) == 0) { set_first_queue_(list_element, queue); set_last_queue_(list_element, queue); } else if (hsqlist_get_first_queue(list) == second_queue) set_first_queue_(list_element, queue); return increment_size_(list_element); }
int hsqlist_is_valid_range | ( | int | list | ) |
Checks if the given list value is in valid range.
list | The list. |
Definition at line 218 of file hsqlist.c.
{ if ((list < 0) || (list > HPS_NUMBER)) { hlog_write(HLOG_ERROR, "hsqlist_is_valid_range: Invalid list range.\n"); return 0; } return 1; }
int hsqlist_register_signal | ( | int | signal, | |
int(*)() | function | |||
) |
Register the given signal.
This functionality is part of an observer-observable pattern between the list module and the queue module (to keep correct encapsulation).
The queue module register a given signal with the list module.
After a signal is registered, changes done in the list will make sure internal structure in the affected queues are updated.
list | The signal as defined by enum hsignal in hsignal.h. | |
function | Pointer to the callback function in the hqueue module. |
Definition at line 131 of file hsqlist.c.
{ switch (signal) { case HSIGNAL_ADD_QUEUE: signal_add_queue_ = function; return 0; case HSIGNAL_REMOVE_QUEUE: signal_remove_queue_ = function; return 0; default: return -1; } return -1; }
int hsqlist_remove | ( | int | list | ) |
int hsqlist_remove_queue | ( | int | list, | |
struct hsqueue * | queue | |||
) |
Remove the given queue from the list.
list | The list. | |
queue | Pointer to the queue. |
This function can be called by hsqueue_remove. This function must remove queue even though the list does not exist (orphan queues may exist).
Definition at line 173 of file hsqlist.c.
{ if (queue == NULL) return -1; struct hsqlist* list_element = get_list_(list); if (queue == hsqlist_get_first_queue(list)) { set_first_queue_(list_element, hsqueue_get_next(queue)); } if (queue == hsqlist_get_last_queue(list)) set_last_queue_(list_element, hsqueue_get_prev(queue)); decrement_size_(list_element); // Ask queue module to clean up internal structure and free queue from memory. signal_remove_queue_(queue); return 0; }
int hsqlist_size | ( | int | list | ) |
Get size of list.
list | The list. |
Definition at line 162 of file hsqlist.c.
{ struct hsqlist* list_element = get_list_(list); if (list_element == NULL) return -1; return list_element->queues_num; }