This is Unofficial EPICS BASE Doxygen Site
cantProceed.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE Versions 3.13.7
7 * and higher are distributed subject to a Software License Agreement found
8 * in file LICENSE that is included with this distribution.
9 \*************************************************************************/
10 
11 /* Author: Marty Kraimer Date: 04JAN99 */
12 
13 #include <stddef.h>
14 #include <stdlib.h>
15 #include <stdarg.h>
16 
17 #include "errlog.h"
18 #include "cantProceed.h"
19 #include "epicsThread.h"
20 #include "epicsStackTrace.h"
21 
22 LIBCOM_API void * callocMustSucceed(size_t count, size_t size, const char *msg)
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 }
37 
38 LIBCOM_API void * mallocMustSucceed(size_t size, const char *msg)
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 }
53 
54 LIBCOM_API void cantProceed(const char *msg, ...)
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
#define NULL
Definition: catime.c:38
LIBCOM_API void epicsStdCall epicsThreadSuspendSelf(void)
Definition: osdThread.c:664
LIBCOM_API void * callocMustSucceed(size_t count, size_t size, const char *msg)
A calloc() that never returns NULL.
Definition: cantProceed.c:22
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
void epicsStackTrace(void)
LIBCOM_API void * mallocMustSucceed(size_t size, const char *msg)
A malloc() that never returns NULL.
Definition: cantProceed.c:38
LIBCOM_API void epicsStdCall epicsThreadSleep(double seconds)
Block the calling thread for at least the specified time.
Definition: osdThread.c:790
LIBCOM_API void cantProceed(const char *msg,...)
Definition: cantProceed.c:54
Routines for code that can&#39;t continue or return after an error.
C++ and C descriptions for a thread.
LIBCOM_API epicsThreadId epicsStdCall epicsThreadGetIdSelf(void)
Definition: osdThread.c:810