cantProceed.h

Routines for code that can’t continue or return after an error.

This is the EPICS equivalent of a Kernel Panic, except that the effect is to halt only the thread that detects the error.

Memory Allocation Functions

These versions of calloc() and malloc() never fail, they suspend the thread if the OS is unable to allocate the requested memory at the current time. If the thread is resumed, they will re-try the memory allocation, and will only return after it succeeds. These routines should only be used while an IOC is starting up; code that runs after iocInit() should fail gracefully when memory runs out.

void *callocMustSucceed(size_t count, size_t size, const char *errorMessage)

A calloc() which suspends on error.

Will always return NULL for a zero length allocation. Will never return NULL otherwise.

Parameters:
  • count – Number of objects.

  • size – Size of each object.

  • errorMessage – Context added to logged error message

Returns:

Pointer to zeroed allocated memory. Should later be free() d

void *mallocMustSucceed(size_t size, const char *errorMessage)

A malloc() which suspends on error.

Will always return NULL for a zero length allocation. Will never return NULL otherwise.

Parameters:
  • size – Size of block to allocate.

  • errorMessage – Context added to logged error message

Returns:

Pointer to allocated memory. Should later be free() d

Functions

void cantProceed(const char *errorMessage, ...)

Suspend this thread, the caller cannot continue or return.

The effect of calling this is to print the error message followed by the name of the thread that is being suspended. A stack trace will also be shown if supported by the OS, and the thread is suspended inside an infinite loop.

Parameters:
  • errorMessage – A printf-style error message describing the error.

  • ... – Any parameters required for the error message.