pmm  1.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions
pmm_load.c File Reference

Code for handling load structure. More...

#include <stdlib.h>
#include <time.h>
#include "pmm_load.h"
#include "pmm_log.h"

Go to the source code of this file.

Functions

struct pmm_loadhistorynew_loadhistory ()
int init_loadhistory (struct pmm_loadhistory *h, int size)
void add_load (struct pmm_loadhistory *h, struct pmm_load *l)
int check_loadhistory (struct pmm_loadhistory *h)
struct pmm_loadnew_load ()
void print_loadhistory (const char *output, struct pmm_loadhistory *h)
void print_load (const char *output, struct pmm_load *l)
void free_loadhistory (struct pmm_loadhistory **h)

Detailed Description

Code for handling load structure.

Contains functions for dealing with the load data structures.

Definition in file pmm_load.c.

Function Documentation

void add_load ( struct pmm_loadhistory h,
struct pmm_load l 
)

This function copies the structure l into the load history structure which is a circular array.

Parameters
hpointer to the load history structure
lpointer to the load to be copied into the next free/expired element of the circular array

Definition at line 120 of file pmm_load.c.

int check_loadhistory ( struct pmm_loadhistory h)

Do some sanity checking on the load history structure

Parameters
hpointer to load history
Returns
1 if load history passes check, 0 if it fails

Definition at line 160 of file pmm_load.c.

void free_loadhistory ( struct pmm_loadhistory **  h)

frees a load history structure and all of its members

Parameters
hpointer to address of the load history structure

Definition at line 243 of file pmm_load.c.

int init_loadhistory ( struct pmm_loadhistory h,
int  size 
)

Function initialises the array and indexes that are used to store the load history (in a circular type array)

Parameters
hpointer to a load history structure
sizesize of the circular array
Returns
0 on success, -1 on failure

TODO check that history is not already allocated, free in this case first

Definition at line 90 of file pmm_load.c.

struct pmm_load* new_load ( )
read

initialized a new load observation structure

Returns
pointer to an allocated and intialized load structure

Definition at line 191 of file pmm_load.c.

struct pmm_loadhistory* new_loadhistory ( )
read

Allocates and initialises memory for a new load history structure. This is a circular array arrangement with pointers to the beginning and end. Iteration over the array is done using the modulus operator to wrap the physically beginning and end addresses.

note for a given size we must keep size+1 elements in the array. Thus we store two different sizes. 'size' refers to the number of accessible elements in the circular array. 'size_mod' refers to actual allocated elements in the array and is only to be used when iterating through the accessible elements using i+1size_mod. 'size_mod' will always be the accessible size 'size' + 1

Returns
pointer to a new loadhistory structure or NULL on failure

Definition at line 50 of file pmm_load.c.

void print_load ( const char *  output,
struct pmm_load l 
)

prints a single load observation

Parameters
outputoutput stream to print to
lpointer to load structure to print

Definition at line 233 of file pmm_load.c.

void print_loadhistory ( const char *  output,
struct pmm_loadhistory h 
)

prints a load history sequence

Parameters
outputoutput stream to print to
hpointer to the load history

Definition at line 211 of file pmm_load.c.