ucommon/platform.h File Reference

Various miscelanous platform specific headers and defines. More...

#include <pthread.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdint.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <assert.h>

Include dependency graph for platform.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


Namespaces

namespace  ucc
 Common namespace for all ucommon objects.

Defines

#define UCOMMON_NAMESPACE   ucc
#define NAMESPACE_UCOMMON   namespace ucc {
#define END_NAMESPACE   }
#define _REENTRANT   1
#define _THREADSAFE   1
#define __PRINTF(x, y)
#define __SCANF(x, y)
#define __MALLOC
#define __EXPORT
#define __LOCAL
#define INVALID_SOCKET   -1
#define INVALID_HANDLE_VALUE   -1
#define crit(x, text)   if(!(x)) cpr_runtime_error(text)

Typedefs

typedef int socket_t
typedef int fd_t
typedef void(* sighandler_t )(int)
 Convenient typedef for signal handlers.
typedef unsigned long timeout_t
 Typedef for millisecond timer values.

Functions

void cpr_runtime_error (const char *text)
 Function to handle runtime errors.
void * cpr_memalloc (size_t size)
 Portable memory allocation helper function.
void * cpr_memassign (size_t size, caddr_t address, size_t known)
 Portable memory placement helper function.
void cpr_memswap (void *mem1, void *mem2, size_t size)
 Portable swap code.
void * operator new (size_t size)
 Our generic new operator.
void * operator new[] (size_t size)
 Our generic new array operator.
void * operator new[] (size_t size, caddr_t address)
 A placement new array operator where we assume the size of memory is good.
void * operator new[] (size_t size, caddr_t address, size_t known)
 A placement new array operator where we know the allocated size.
void * operator new (size_t size, size_t extra)
 Overdraft new to allocate extra memory for object from heap.
void * operator new (size_t size, caddr_t address)
 A placement new operator where we assume the size of memory is good.
void * operator new (size_t size, caddr_t address, size_t known)
 A placement new operator where we know the allocated size.
void operator delete (void *object)
 Delete an object from the heap.
void operator delete[] (void *array)
 Delete an array from the heap.
uint16_t lsb_getshort (uint8_t *b)
uint32_t lsb_getlong (uint8_t *b)
uint16_t msb_getshort (uint8_t *b)
uint32_t msb_getlong (uint8_t *b)
void lsb_setshort (uint8_t *b, uint16_t v)
void lsb_setlong (uint8_t *b, uint32_t v)
void msb_setshort (uint8_t *b, uint16_t v)
void msb_setlong (uint8_t *b, uint32_t v)


Detailed Description

Various miscelanous platform specific headers and defines.

This is used to support ucommon on different platforms. The ucommon library assumes at least a real posix threading library is present or will build thread support native on Microsoft Windows legacy platform. This header also deals with issues related to common base types.

Definition in file platform.h.


Typedef Documentation

typedef void(* sighandler_t)(int)

Convenient typedef for signal handlers.

Definition at line 298 of file platform.h.

typedef unsigned long timeout_t

Typedef for millisecond timer values.

Definition at line 299 of file platform.h.


Function Documentation

void* cpr_memalloc ( size_t  size  ) 

Portable memory allocation helper function.

Handles out of heap error as a runtime error.

Parameters:
size of memory block to allocate from heap.
Returns:
memory address of allocated heap space.

void* cpr_memassign ( size_t  size,
caddr_t  address,
size_t  known 
)

Portable memory placement helper function.

This is used to process "placement" new operators where a new object is constructed over a pre-allocated area of memory. This handles invalid values through runtime error.

Parameters:
size of object being constructed.
address where the object is being placed.
known size of the location we are constructing the object in.

void cpr_memswap ( void *  mem1,
void *  mem2,
size_t  size 
)

Portable swap code.

Parameters:
mem1 to swap.
mem2 to swap.
size of swap area.

void cpr_runtime_error ( const char *  text  ) 

Function to handle runtime errors.

When using the standard C library, runtime errors are handled by a simple abort. When using the stdc++ library with stdexcept, then std::runtime_error will be thrown.

Parameters:
text of runtime error.

void operator delete ( void *  object  )  [inline]

Delete an object from the heap.

Parameters:
object to delete.

Definition at line 474 of file platform.h.

void operator delete[] ( void *  array  )  [inline]

Delete an array from the heap.

All array element destructors are called.

Parameters:
array to delete.

Definition at line 481 of file platform.h.

void* operator new ( size_t  size,
caddr_t  address,
size_t  known 
) [inline]

A placement new operator where we know the allocated size.

We find out how much memory is needed by the new and can prevent the object from exceeding the available space we are placing the object.

Parameters:
size of memory needed for object.
address where to place object.
known size of location we are placing object.
Returns:
memory we placed object.

Definition at line 466 of file platform.h.

Here is the call graph for this function:

void* operator new ( size_t  size,
caddr_t  address 
) [inline]

A placement new operator where we assume the size of memory is good.

We construct the object at a specified place in memory which we assume is valid for our needs.

Parameters:
size of memory needed for object.
address where to place object.
Returns:
memory we placed object.

Definition at line 453 of file platform.h.

Here is the call graph for this function:

void* operator new ( size_t  size,
size_t  extra 
) [inline]

Overdraft new to allocate extra memory for object from heap.

This is used for objects that must have a known class size but store extra data behind the class. The last member might be an unsized or 0 element array, and the actual size needed from the heap is hence not the size of the class itself but is known by the routine allocating the object.

Parameters:
size of object.
extra heap space needed for data.

Definition at line 442 of file platform.h.

Here is the call graph for this function:

void* operator new ( size_t  size  )  [inline]

Our generic new operator.

Uses our heap memory allocator.

Parameters:
size of object being constructed.
Returns:
memory allocated from heap.

Definition at line 396 of file platform.h.

Here is the call graph for this function:

void* operator new[] ( size_t  size,
caddr_t  address,
size_t  known 
) [inline]

A placement new array operator where we know the allocated size.

We find out how much memory is needed by the new and can prevent arrayed objects from exceeding the available space we are placing the object.

Parameters:
size of memory needed for object array.
address where to place object array.
known size of location we are placing array.
Returns:
memory we placed object array.

Definition at line 429 of file platform.h.

Here is the call graph for this function:

void* operator new[] ( size_t  size,
caddr_t  address 
) [inline]

A placement new array operator where we assume the size of memory is good.

We construct the array at a specified place in memory which we assume is valid for our needs.

Parameters:
size of memory needed for object array.
address where to place object array.
Returns:
memory we placed object array.

Definition at line 417 of file platform.h.

Here is the call graph for this function:

void* operator new[] ( size_t  size  )  [inline]

Our generic new array operator.

Uses our heap memory allocator.

Parameters:
size of memory needed for object array.
Returns:
memory allocated from heap.

Definition at line 404 of file platform.h.

Here is the call graph for this function:


Generated on Wed May 13 08:42:56 2009 for UCommon by  doxygen 1.5.7.1