This is Unofficial EPICS BASE Doxygen Site
osdPoolStatus.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 is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 
10 #include <memLib.h>
11 #include <limits.h>
12 
13 #include "epicsThread.h"
14 #include "osiPoolStatus.h"
15 
16 /*
17  * It turns out that memPartInfoGet() and memFindMax() are very CPU intensive on vxWorks
18  * so we must spawn off a thread that periodically polls. Although this isnt 100% safe, I
19  * dont see what else to do.
20  *
21  * It takes about 30 uS to call memPartInfoGet() on a pcPentium I vxWorks system.
22  *
23  * joh
24  */
25 
26 static epicsThreadOnceId osdMaxBlockOnceler = EPICS_THREAD_ONCE_INIT;
27 
28 static size_t osdMaxBlockSize = 0;
29 
30 static void osdSufficentSpaceInPoolQuery ()
31 {
32  osdMaxBlockSize = (size_t) memFindMax ();
33 }
34 
35 static void osdSufficentSpaceInPoolPoll ( void *pArgIn )
36 {
37  while ( 1 ) {
38  epicsThreadSleep ( 1.0 );
39  osdSufficentSpaceInPoolQuery ();
40  }
41 }
42 
43 static void osdSufficentSpaceInPoolInit ( void *pArgIn )
44 {
45  epicsThreadId id;
46 
47  osdSufficentSpaceInPoolQuery ();
48 
51  osdSufficentSpaceInPoolPoll, 0 );
52 }
53 
54 /*
55  * osiSufficentSpaceInPool ()
56  */
57 LIBCOM_API int epicsStdCall osiSufficentSpaceInPool ( size_t contiguousBlockSize )
58 {
59  epicsThreadOnce ( &osdMaxBlockOnceler, osdSufficentSpaceInPoolInit, 0 );
60 
61  if ( UINT_MAX - 100000u >= contiguousBlockSize ) {
62  return ( osdMaxBlockSize > 100000 + contiguousBlockSize );
63  }
64  else {
65  return 0;
66  }
67 }
#define epicsThreadPriorityMedium
Definition: epicsThread.h:76
Functions to check the state of the system memory pool.
LIBCOM_API int epicsStdCall osiSufficentSpaceInPool(size_t contiguousBlockSize)
Checks if a memory block of a specific size can be safely allocated.
Definition: osdPoolStatus.c:19
LIBCOM_API unsigned int epicsStdCall epicsThreadGetStackSize(epicsThreadStackSizeClass size)
Definition: osdThread.c:466
epicsThreadId epicsStdCall epicsThreadCreate(const char *name, unsigned int priority, unsigned int stackSize, EPICSTHREADFUNC funptr, void *parm)
Definition: epicsThread.cpp:33
#define EPICS_THREAD_ONCE_INIT
Definition: epicsThread.h:109
LIBCOM_API void epicsStdCall epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg)
LIBCOM_API void epicsStdCall epicsThreadSleep(double seconds)
Block the calling thread for at least the specified time.
Definition: osdThread.c:790
C++ and C descriptions for a thread.