QuickIO  0.2
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Typedefs | Functions
fair.h File Reference

Helps with determining if resources can be fairly allocated given current conditions. More...

#include "qev.h"

Go to the source code of this file.

Typedefs

typedef struct qev_fair qev_fair_t
 Don't even try modifying this.
 

Functions

qev_fair_tqev_fair_new (const gchar *name, const guint total, const gsize pressure, const gsize min)
 Create a new limited pool that needs allocating. More...
 
void qev_fair_free (qev_fair_t *fair)
 Free the fairness pool. More...
 
gboolean qev_fair_use (qev_fair_t *fair, const gsize in_use, const gsize wants)
 Determines if the given number of resources may be used. More...
 
gboolean qev_fair_used (qev_fair_t *fair, const gsize in_use, const gsize added)
 Like qev_fair_use, except this one just tells the fair pool that the number of resources has already been allocated. More...
 
void qev_fair_return (qev_fair_t *fair, const gsize giving)
 Return used resources to the pool. More...
 
gsize qev_fair_get_usage (qev_fair_t *fair)
 Get how much of the shared resource is currently in use.
 
void qev_fair_set_total (qev_fair_t *fair, const gsize total)
 Set the total number of things the pool may allocate. More...
 
void qev_fair_set_pressure (qev_fair_t *fair, const gsize pressure)
 Change the pressure of the pool. More...
 
void qev_fair_set_min (qev_fair_t *fair, const gsize min)
 Change the min allocation for the pool. More...
 

Detailed Description

Helps with determining if resources can be fairly allocated given current conditions.

Typically, this is used for allocating limited resources to clients.

Author
Andrew Stone andre.nosp@m.w@cl.nosp@m.ovar..nosp@m.com

Function Documentation

void qev_fair_free ( qev_fair_t fair)

Free the fairness pool.

Parameters
fairThe pool to free
qev_fair_t* qev_fair_new ( const gchar *  name,
const guint  total,
const gsize  pressure,
const gsize  min 
)

Create a new limited pool that needs allocating.

Note
Because pools use stats, they must be setup completely before the server is run.
Parameters
nameThe name of this pool. A stat will be created with this name that reports the status of this pool.
totalThe total number of resources that this pool may distribute
pressureAt what percent of total pressure should be applied to bring resource usage back down
minThe smallest amount of resources that a single client has access to, regardless of memory pressure. If the number of allocated resources is greater than total, then this will be ignored.
Returns
The fairness allocation pool.
void qev_fair_return ( qev_fair_t fair,
const gsize  giving 
)

Return used resources to the pool.

Parameters
fairThe fair pool to return resources to
givingThe number of resources that are being given up
void qev_fair_set_min ( qev_fair_t fair,
const gsize  min 
)

Change the min allocation for the pool.

Parameters
fairThe pool to update
minThe new min value (will be constrained to be less than total)
void qev_fair_set_pressure ( qev_fair_t fair,
const gsize  pressure 
)

Change the pressure of the pool.

Parameters
fairThe pool to update
pressureThe new pressure for the pool (0-100)
void qev_fair_set_total ( qev_fair_t fair,
const gsize  total 
)

Set the total number of things the pool may allocate.

Parameters
fairThe pool to update
totalThe new total resource count for the pool
gboolean qev_fair_use ( qev_fair_t fair,
const gsize  in_use,
const gsize  wants 
)

Determines if the given number of resources may be used.

Note
This only gives a fuzzy yes/no. It's possible for this to give out more than the number of available resources as no locks are used. In reality, it will only really give out a slightly-higher number of resources.
Parameters
fairThe fair pool to allocate from
in_useHow many resources this user has already used from the pool
wantsHow many additional resources the user wants.
Returns
If the user may, in fact, allocate the request resources.
gboolean qev_fair_used ( qev_fair_t fair,
const gsize  in_use,
const gsize  added 
)

Like qev_fair_use, except this one just tells the fair pool that the number of resources has already been allocated.

Like qev_fair_use, this will return if the number of resources now in use is too many.

Parameters
fairThe fair pool to allocate from
in_useHow many resources this user has already used from the pool
addedHow many additional resources the user took
Returns
If the user is now using too many of the resource.