This is Unofficial EPICS BASE Doxygen Site
cantProceed.c File Reference
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include "errlog.h"
#include "cantProceed.h"
#include "epicsThread.h"
#include "epicsStackTrace.h"
+ Include dependency graph for cantProceed.c:

Go to the source code of this file.

Functions

LIBCOM_API void * callocMustSucceed (size_t count, size_t size, const char *msg)
 A calloc() that never returns NULL. More...
 
LIBCOM_API void * mallocMustSucceed (size_t size, const char *msg)
 A malloc() that never returns NULL. More...
 
LIBCOM_API void cantProceed (const char *msg,...)
 

Function Documentation

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

A calloc() that never returns NULL.

Parameters
countNumber of objects.
sizeSize of each object.
errorMessageWhat this memory is needed for.
Returns
Pointer to zeroed allocated memory.

Definition at line 22 of file cantProceed.c.

23 {
24  void * mem = NULL;
25  if (count > 0 && size > 0) {
26  while ((mem = calloc(count, size)) == NULL) {
27  errlogPrintf("%s: callocMustSucceed(%lu, %lu) - calloc failed\n",
28  msg, (unsigned long)count, (unsigned long)size);
29  errlogPrintf("Thread %s (%p) suspending.\n",
31  errlogFlush();
33  }
34  }
35  return mem;
36 }
void errlogFlush(void)
Definition: errlog.c:529
LIBCOM_API const char *epicsStdCall epicsThreadGetNameSelf(void)
Definition: osdThread.c:846
#define NULL
Definition: catime.c:38
LIBCOM_API void epicsStdCall epicsThreadSuspendSelf(void)
Definition: osdThread.c:664
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
LIBCOM_API epicsThreadId epicsStdCall epicsThreadGetIdSelf(void)
Definition: osdThread.c:810
LIBCOM_API void cantProceed ( const char *  msg,
  ... 
)

Definition at line 54 of file cantProceed.c.

55 {
56  va_list pvar;
57  va_start(pvar, msg);
58  if (msg)
59  errlogVprintf(msg, pvar);
60  va_end(pvar);
61 
62  errlogPrintf("Thread %s (%p) can't proceed, suspending.\n",
64 
66 
67  errlogFlush();
68 
69  epicsThreadSleep(1.0);
70  while (1)
72 }
void errlogFlush(void)
Definition: errlog.c:529
int errlogVprintf(const char *pFormat, va_list pvar)
Definition: errlog.c:144
LIBCOM_API const char *epicsStdCall epicsThreadGetNameSelf(void)
Definition: osdThread.c:846
LIBCOM_API void epicsStdCall epicsThreadSuspendSelf(void)
Definition: osdThread.c:664
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
void epicsStackTrace(void)
LIBCOM_API void epicsStdCall epicsThreadSleep(double seconds)
Block the calling thread for at least the specified time.
Definition: osdThread.c:790
LIBCOM_API epicsThreadId epicsStdCall epicsThreadGetIdSelf(void)
Definition: osdThread.c:810
LIBCOM_API void* mallocMustSucceed ( size_t  size,
const char *  errorMessage 
)

A malloc() that never returns NULL.

Parameters
sizeSize of block to allocate.
errorMessageWhat this memory is needed for.
Returns
Pointer to allocated memory.

Definition at line 38 of file cantProceed.c.

39 {
40  void * mem = NULL;
41  if (size > 0) {
42  while ((mem = malloc(size)) == NULL) {
43  errlogPrintf("%s: mallocMustSucceed(%lu) - malloc failed\n",
44  msg, (unsigned long)size);
45  errlogPrintf("Thread %s (%p) suspending.\n",
47  errlogFlush();
49  }
50  }
51  return mem;
52 }
void errlogFlush(void)
Definition: errlog.c:529
LIBCOM_API const char *epicsStdCall epicsThreadGetNameSelf(void)
Definition: osdThread.c:846
#define NULL
Definition: catime.c:38
LIBCOM_API void epicsStdCall epicsThreadSuspendSelf(void)
Definition: osdThread.c:664
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
LIBCOM_API epicsThreadId epicsStdCall epicsThreadGetIdSelf(void)
Definition: osdThread.c:810