Next: 3.10 Classes Up: 3. The libonyx library Previous: 3.8 Guidelines for writing Contents Index

# 3.9 API

void libonyx_init(void):

  Input(s):
    None.
  Output(s):
    None.
  Exception(s):
    CW_ONYXX_OOM.
  Description:
    Initialize various global variables. In particular, initialize cw_g_mem.

void libonyx_shutdown(void):

  Input(s):
    None.
  Output(s):
    None.
  Exception(s):
    None.
  Description:
    Clean up the global variables that are initialized by libonyx_init().

void * cw_opaque_alloc_t(void *a_arg, size_t a_size, const char *a_filename, cw_uint32_t a_line_num):

  Input(s):
    a_arg:
      Opaque pointer.
    a_size:
      Size of memory range to allocate.
    a_filename:
      Should be __FILE__.
    a_line_num:
      Should be __LINE__.
  Output(s):
    retval:
      Pointer to a memory range.
  Exception(s):
    CW_ONYXX_OOM.
  Description:
    Allocate a_size of space and return a pointer to it.

void * cw_opaque_realloc_t(void *a_arg, void *a_ptr, size_t a_size, const char *a_filename, cw_uint32_t a_line_num):

  Input(s):
    a_arg:
      Opaque pointer.
    a_ptr:
      Pointer to memory range to be reallocated.
    a_size:
      Size of memory range to allocate.
    a_filename:
      Should be __FILE__.
    a_line_num:
      Should be __LINE__.
  Output(s):
    retval:
      Pointer to a memory range.
  Exception(s):
    CW_ONYXX_OOM.
  Description:
    Allocate a_size of space and return a pointer to it.

void cw_opaque_dealloc_t(void *a_mem, void *a_ptr, size_t a_size, const char *a_filename, cw_uint32_t a_line_num):

  Input(s):
    a_arg:
      Opaque pointer.
    a_ptr:
      Pointer to to memory range to be freed.
    a_size:
      Sizef of memory range pointed to by a_ptr.
    a_filename:
      Should be __FILE__.
    a_line_num:
      Should be __LINE__.
  Output(s):
    None.
  Exception(s):
    None.
  Description:
    Deallocate the memory pointed to by a_ptr.

void cw_onyx_code(cw_nxo_t *a_thread, const char *a_code):

  Input(s):
    a_thread:
      Pointer to a thread nxo.
    a_code:
      A "-delimited string constant.
  Output(s):
    None.
  Exception(s):
    Depends on actions of a_code.
  Description:
    Convenience macro for static embedded Onyx code.

void cw_assert(expression):

  Input(s):
    expression:
      C expression that evaluates to zero or non-zero.
  Output(s):
    Possible error printed to file descriptor 2.
  Exception(s):
    None.
  Description:
    If the expression evaluates to zero, print an error message to file descriptor 2 and abort().

    Note: This macro is only active if the CW_ASSERT cpp macro is defined.

void cw_not_reached(void):

  Input(s):
    None.
  Output(s):
    Error printed to file descriptor 2.
  Exception(s):
    None.
  Description:
    Abort with an error message.

    Note: This macro is only active if the CW_ASSERT cpp macro is defined.

void cw_check_ptr(a_pointer):

  Input(s):
    a_pointer:
      A pointer.
  Output(s):
    Possible error printed to file descriptor 2.
  Exception(s):
    None.
  Description:
    If a_pointer is NULL, print an error message to file descriptor 2 and abort().

    Note: This macro is only active if the CW_ASSERT cpp macro is defined.

void cw_error(const char *a_str):

  Input(s):
    a_str:
      Pointer to a NULL-terminated character array.
  Output(s):
    Contents of a_str, followed by a carriage return, printed to file descriptor 2.
  Exception(s):
    None.
  Description:
    Print the contents of a_str, followed by a carriage return, to file descriptor 2.

cw_uint64_t cw_ntohq(cw_uint64_t a_val):

  Input(s):
    a_val:
      64 bit integer.
  Output(s):
    retval:
      64 bit integer.
  Exception(s):
    None.
  Description:
    Convert a_val from network byte order to host byte order and return the result.

cw_uint64_t cw_htonq(cw_uint64_t a_val):

  Input(s):
    a_val:
      64 bit integer.
  Output(s):
    retval:
      64 bit integer.
  Exception(s):
    None.
  Description:
    Convert a_val from host byte order to network byte order and return the result.

Next: 3.10 Classes Up: 3. The libonyx library Previous: 3.8 Guidelines for writing Contents Index