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

For data that lives the life of the server, this provides a quick way to create and forget about freeing them. More...

#include "qev.h"

Go to the source code of this file.

Functions

void qev_cleanup (void *ptr, const qev_free_fn free_fn)
 Calls qev_cleanup() with last=FALSE.
 
void qev_cleanup_full (void *ptr, const qev_free_fn free_fn, const gboolean last)
 Adds a pointer to a thread-local that needs to be cleaned up on exit. More...
 
void qev_cleanup_and_null (void **ptrptr, const qev_free_fn free_fn)
 Calls qev_cleanup_and_null_full() with last=FALSE.
 
void qev_cleanup_and_null_full (void **ptrptr, const qev_free_fn free_fn, const gboolean last)
 Adds a pointer to be cleaned up and set to NULL on exit. More...
 
void qev_cleanup_fn (const qev_cb fn)
 Calls qev_cleanup_fn_full() with last=FALSE.
 
void qev_cleanup_fn_full (const qev_cb cb, const gboolean last)
 Adds a simple function to be called on exit. More...
 

Detailed Description

For data that lives the life of the server, this provides a quick way to create and forget about freeing them.

On server exit, all registered pointers will have their free functions called and their original pointers will be nulled out.

The cleanup functions are called in the reverse of the order they were added; that is, most-recently added is called first. Since programs typically boot by starting dependencies first, it only makes sense to tear down what nothing depends on while leaving the dependencies until last to make sure everything exits smoothly.

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

Function Documentation

void qev_cleanup_and_null_full ( void **  ptrptr,
const qev_free_fn  free_fn,
const gboolean  last 
)

Adds a pointer to be cleaned up and set to NULL on exit.

Parameters
ptrptrA pointer to the pointer to be cleared out and null'd on exit.
free_fnThe function to free the pointer on exit.
lastIf the item should be freed after everything else. This is useful for things that must last the life of the server and are used during shutdown.
void qev_cleanup_fn_full ( const qev_cb  cb,
const gboolean  last 
)

Adds a simple function to be called on exit.

Parameters
cbThe function to call on exit
lastIf the function should be called after everything else
void qev_cleanup_full ( void *  ptr,
const qev_free_fn  free_fn,
const gboolean  last 
)

Adds a pointer to a thread-local that needs to be cleaned up on exit.

Note
Since QEV threads rely on thread local values existing, these values are cleaned up once all QEV threads have exited. In practice, that typically means they're cleaned up last.
Parameters
ptrThe pointer to pass to the free function on exit.
free_fnThe function to free the pointer on exit.
lastIf the item should be freed after everything else. This is useful for things that must last the life of the server and are used during shutdown.