Defines | Functions

/home/sindre/dev_uclinux/suzaku_shared/hwos_sw/libhwos/hsqueue.h File Reference

[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 hsqueuehsqueue_get_prev (struct hsqueue *element)
 Get previous queue in list.
struct hsqueuehsqueue_get_next (struct hsqueue *element)
 Get next queue in list.
struct hsqueuehsqueue_create ()
 Create a new queue.
int hsqueue_remove (struct hsqueue *element)
 Remove a given queue.
struct hprocesshsqueue_get_first_process (struct hsqueue *queue)
 Get first process in the queue.
struct hprocesshsqueue_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 hprocesshsqueue_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.

Detailed Description

[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.


Function Documentation

struct hsqueue* hsqueue_create (  )  [read]

Create a new queue.

Returns:
Pointer to queue on success. NULL on failure.

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;
}

struct hprocess* hsqueue_dequeue_process ( struct hsqueue queue  )  [read]

Dequeue the given process.

Parameters:
queue Queue element.
Returns:
Pointer to the dequeued process on success. NULL on failure.

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;
}

int hsqueue_enqueue_process ( struct hsqueue queue,
struct hprocess process 
)

Enqueue the given process.

Parameters:
queue Queue element.
process Process element.
Returns:
0 on success. Negative on failure.

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);
}

struct hprocess* hsqueue_get_first_process ( struct hsqueue queue  )  [read]

Get first process in the queue.

Parameters:
element Queue element.
Returns:
Pointer to the process on success. NULL on failure.

Definition at line 333 of file hsqueue.c.

{
        if (queue == NULL)
                return NULL;

        return queue->first_process; 
}

struct hprocess* hsqueue_get_last_process ( struct hsqueue queue  )  [read]

Get last process in the queue.

Parameters:
element Queue element.
Returns:
Pointer to the process on success. NULL on failure.

Definition at line 342 of file hsqueue.c.

{
        if (queue == NULL)
                return NULL;

        return queue->last_process;
}

struct hsqueue* hsqueue_get_next ( struct hsqueue element  )  [read]

Get next queue in list.

Parameters:
element Queue element that has the next field.
Returns:
Pointer to queue on success. NULL on failure.

Definition at line 241 of file hsqueue.c.

{
        if (element == NULL)
                return NULL;

        return element->next;
}

int hsqueue_get_parent_list ( struct hsqueue queue  ) 

Get parent list of the queue.

Parameters:
queue Queue element.
Returns:
Positive integer (corresponding to a process state) describing the list on success. Negative on failure.

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;
}

struct hsqueue* hsqueue_get_prev ( struct hsqueue element  )  [read]

Get previous queue in list.

Parameters:
element Queue element that has the previous field.
Returns:
Pointer to queue on success. NULL on failure.

Definition at line 232 of file hsqueue.c.

{
        if (element == NULL)
                return NULL;

        return (struct hsqueue*)(element->prev);
}

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.

Parameters:
queue Pointer to the queue.
Returns:
State (positive integer) of the processes. Negative on failure.

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.

Parameters:
list The signal as defined by enum hsignal in hsignal.h.
function Pointer to the callback function in the hprocess module.
Returns:
0 on success. Negative on failure.

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  ) 

Remove a given queue.

Parameters:
element Queue element.
Returns:
0 on success. Negative on failure.

Definition at line 323 of file hsqueue.c.

{
        if (queue == NULL)
                return -1;

        // Ask list module to remove this queue.
        return hsqlist_remove_queue(hsqueue_get_parent_list(queue), queue);
}

int hsqueue_remove_process ( struct hsqueue queue,
struct hprocess process 
)

Removes the given process from queue.

This function does NOT free the given process from memory.

Parameters:
queue Queue element.
process Process element.
Returns:
0 on success. Negative on failure.

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.

Parameters:
element The queue.
Returns:
Size of the queue.

Definition at line 217 of file hsqueue.c.

{
        if (element == NULL)
                return -1;

        return element->processes_num;
}

 All Data Structures Files Functions Variables Enumerations Enumerator Defines