GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> PBS / V2-12-1 > pbs / rhel6-32
#include <PBS/BUG.h>
#include <PBS/RNG.h>
#include <PBS/TOC.ih>
#include <RW_tmr.ih>
#include <PBI/PTR.h>
Classes | |
struct | _RNG_dyn |
The dynamic component of the ring buffer. More... | |
struct | _RNG_rcb |
Ring buffer control block. More... | |
Defines | |
#define | ROUND_TO(_ptr, _msk) (((PTR_as_uint)(_ptr) + _msk) & ~(PTR_as_uint)_msk) |
Rounds the specified pointer up to the specified binary boundary. | |
Typedefs | |
typedef struct _RNG_dyn | RNG_dyn |
Typedef for _RNG_dyn. | |
typedef struct _RNG_rcb | RNG_rcb |
Typedef for struct _RNG_rcb. | |
Functions | |
static void * | rng_allocate (RNG_rcb *rcb, int minimum, const void *curWrt, int *allocated, const TOC *toc) |
The underlying workhorse allocator. | |
static RW_state | rng__wait (RW_tmr *tmr, RW_state state, unsigned char *volatile *rrd, unsigned char *rd, int needed) |
Blocks the requestor indefinitely until there is a reasonable chance enough memory has been returned to satisfy the request. | |
const RNG_dsc * | RNG_dsc_get (const RNG_rcb *rcb) |
Query routine to return a pointer to the ring buffer description structure. | |
const RNG_dyn * | RNG_dyn_get (const RNG_rcb *rcb) |
Query routine to return a pointer to the ring buffer dynamic quantities. | |
int | RNG_destroy (RNG_rcb *rcb) |
Returns any resources associated with this ring buffer. | |
int | RNG_sizeof_rcb () |
Returns the size of the Ring Contol Block. | |
int | RNG_init (RNG_rcb *rcb, RNG_type type, void *buffer, int size, int underflow, int overflow, int alignment) |
Initializes the control structure for a Ring buffer. | |
void * | RNG_get (RNG_rcb *rcb, int request, const void *write) |
Non-blocking allocation request for a specified amount of memory. | |
void * | RNG_getW (RNG_rcb *rcb, int request, const void *write) |
Blocking allocation request for a specified amount of memory. | |
void * | RNG_getW_toc (RNG_rcb *rcb, int request, const void *write, const TOC *toc) |
Blocking allocation request for a specified amount of memory, with timeout. | |
void * | RNG_grab (RNG_rcb *rcb, int minimum, const void *write, int *allocated) |
Non-blocking allocation request for all the remaining contigious memory, i.e. a greedy form of RNG_get. | |
void * | RNG_grabW (RNG_rcb *rcb, int minimum, const void *write, int *allocated) |
Blocking allocation request for all the remaining contigious memory, i.e. a greedy form of RNG_getW. | |
void * | RNG_grabW_toc (RNG_rcb *rcb, int minimum, const void *write, int *allocated, const TOC *toc) |
Blocking allocation request for all the remaining contigious memory with a timeout, i.e. a greedy form of RNG_getWtos. | |
int | RNG_free (RNG_rcb *rcb, const void *packet, int amount) |
Frees the requested amount of memory from the specified address. | |
void * | RNG_shrink (RNG_rcb *rcb, const void *write, int left) |
Shrinks the previously allocated packet back to the specified address. | |
int | RNG_reset (RNG_rcb *rcb) |
If the ring buffer is empty, reset the read and write pointers to their initial positions. This can only be called if the user knows that the buffer is empty. |
CVS $Id: RNG.c,v 1.10 2011/03/24 23:05:46 apw Exp $
While ring buffers managers are quick and simply allocators, ring buffers have their limitations. This version supports only in order allocation and deallocation. That is, one must deallocate the memory in the same order that it was allocated.
This version of ring buffer management does provide some help when the end of the ring buffer is reached. In order to keep the allocation request contigious in this case, the ring buffer may be configured with an overflow area. The ring buffer management utilities are allowed to use the overflow to satisfy an allocation request, but they never begin an allocation in the overflow area. It is the user's responsibility to specify the overflow area to be as large as the maximum size request that will be made.
The user may also configure an underflow area, which is symmetric to the overflow area, except at the top of the buffer. It's usage is a bit more esoteric. Imagine the situation of wishing to DMA 1000 bytes into a piece of memory allocated by the RNG utility. Circumstances dictate that the memory be contigious within the ring buffer pool. The DMA operation naturally demands continuity. Suppose the current state of the ring buffer is such that one is close the end of the ring buffer pool. The overflow area could be used to satisfy this request. At the end of the DMA operation, the user simply allocates the amount of memory which spilled into the overflow area at the top of the ring buffer and copies into it. The user is now pretty content. The DMA operation proceeded nicely into a chunk of contigious memory and, after the copy operation, the results are contigious in the ring buffer. So what's the problem? It's the copy operation. Suppose the ring buffer only had 4 bytes left at the bottom, leaving the user to copy 996 bytes back to the top. If the allocation could have been made 4 bytes above the top of the ring buffer, then only 4 bytes would have to be copied to the bottom. The underflow provides the memory to implement this scheme.
unsigned char pool[POOL_SIZE]; size = RNG_sizeof_rcb (); rcb = (RNG_rcb *)MBA_alloc (size); RNG_init (rcb, pool, sizeof(pool), BYTE_ALIGN, RNG_K_TYPE_FIFO_PENDING); . . max = 1000; / * Ask for 1000 bytes of memory * / msg = (unsigned char *)RNG_getW (rcb, max, NULL, RNG_K_WTO_FOREVER); . . / * Fill this memory, then return the used portion * / next = fillMemory (msg, max, &left); RNG_shrink (rcb, next, left); used = max - left; . . / * Return the rest of the allocated memory * / RNG_free (rcb, msg, used);
1. There is enough memory to satisfy the request 2. There is not enough memory to satisfy the request
In the first case, all is well, the allocator got what he wanted. In the second case, the allocator is forced to retry. This is really no different than if the allocator had been called slightly sooner (before the free routine could put back the memory), so unless there is some highly determinestic reason which sequences the allocator and freer, this is just the luck of the draw.
There is, as always, one complication; how to distinguish the completely full state from the completely empty state. The tact taken here is to always contain the WRITE pointer within the pool, but, when the pool is completely empty, to represent the READ pointer by the WRITE pointer + the size of the buffer. This means that the READ buffer can potentially point outside the buffer. This is okay, provided that anytime this value is used, it is first checked to see if it is outside the pool. It can then be constrained to be within the pool simply be subtracting the size of the pool.
The WRITE (allocator) does this when the distance between the two pointers is calculated. If this distance is the size of the pool, read pointer can be safely pushed to it's value - length of the pool. There is no danger of the FREER manipulating the pointer, since all the memory is allocated, ie there is no **legitimate** reason for the free routine to be called.
This declares the contents at the location adr to be volatile, not the value of adr. The former is what one usually wants, but in this case, it is the value of adr that is volatile.
Without the volatile declaration the optimizer is free to tranform
w1 = rcb->wr; w1 = rcb->wr; w2 = rcb->wr; into w2 = w1; w3 = rcb->wr; w3 = w1;
If rcb->wr is being modified from another thread of execution, this is incorrect.
#define ROUND_TO | ( | _ptr, | |||
_msk | ) | (((PTR_as_uint)(_ptr) + _msk) & ~(PTR_as_uint)_msk) |
Rounds the specified pointer up to the specified binary boundary.
_ptr | The pointer to round | |
_msk | Bit mask corresponding to the binary boundary, ie round to 4, _msk = 3, round to 8, _msk = 7, etc |
Referenced by rng_allocate(), RNG_free(), and RNG_init().
Typedef for _RNG_dyn.
This is an internal structure. It is available as a package private structure for debugging purposes, but, otherwise is not exposed to the user.
While the user is free to cache a pointer to this structure, he is not free to cache the values; they are dynamic. Furthermore, all the quantities are declared volatile, making it illegal for the compiler to cache them.
Typedef for struct _RNG_rcb.
This structure contains all the context information needed to describe and control a ring buffer.
static RW_state rng__wait | ( | RW_tmr * | tmr, | |
RW_state | state, | |||
unsigned char *volatile * | rrd, | |||
unsigned char * | rd, | |||
int | needed | |||
) | [inline, static] |
Blocks the requestor indefinitely until there is a reasonable chance enough memory has been returned to satisfy the request.
tmr | The RW timer control structure | |
state | The current state of tmr. | |
rrd | The address of read pointer | |
rd | The current value of the read pointer | |
needed | The amount of memory needed |
References RW__tmr_lock(), RW__tmr_unlock(), and RW__tmr_wait().
Referenced by rng_allocate().
static void * rng_allocate | ( | RNG_rcb * | rcb, | |
int | request, | |||
const void * | write, | |||
int * | allocated, | |||
const TOC * | toc | |||
) | [static] |
The underlying workhorse allocator.
rcb | The ring buffer control block | |
request | The requested amount of memory to acquire. If the allocated' parameter is NULL, this is interpretted as the exact amount to allocate. If the allocated parameter is non-NULL, then this is interpretted as the minimum amount to allocate. | |
write | The predicted value of the next write pointer. This should be the value of the last allocated memory address + its size. This is used for integrity checking. If one wishes to live dangerously, NULL may be specified, in which case no check is performed | |
allocated | Returned as the size actually allocated. This may be NULL, in which case the allocated amount is exactly the requested. If not NULL, all the available contigious memory is allocated. In this case, the request is treated as a minimum allocation. | |
toc | The timeout control block. This controls the type of timeout's that are requested. |
The allocation does not execute that many lines of code, but there are a couple of cases and some subtle details to consider, so this routine looks considerably bulker than one might suspect. The complexity is in the number of cases that most be handled. Both the dispatching to the proper case and the code within the proper case are quick, its just that there are a number of cases to handle.
The code is heavily commented, defining the cases and the sublities. Some of these comments refer to the diagram below which defines and describes the various states the ring buffer may be in.
DETAILS
-------
In order to do the allocation, one must determine which of three possible states of the ring buffer is in. These three scenerios which are distinguished by the sign of RD - WR. The third scenerio is when the buffer is completely empty. One could legitimately force the WR and RD pointers to the top and bottom of the buffers, but this would kill the useful (debugging) feature of the ring buffer, ie to treat it as a history buffer. So this case is treated as a degenerate version of the second case.
The diagrams below are meant to illustrate 2 these 3 cases. The allocated memory is indicated by the x's, while the free memory is indicated by the blank spaces. WR and RD represent the current values of the WRITE and READ pointers.
RD - WR > 0 RD - WR < 0 +-----------------+ +----------------+ |xxxxxxxxxxxxxxxxx| | | |xxxxxxxxxxxxxxxxx| | FREE SPACE | |xxxxxxxxxxxxxxxxx| | | |xxxxxxxxxxxxxxxxx| RD +----------------+ WR +-----------------+ |xxxxxxxxxxxxxxxx| | | |xxxxxxxxxxxxxxxx| | FREE SPACE | |xxxxxxxxxxxxxxxx| | | |xxxxxxxxxxxxxxxx| | | |xxxxxxxxxxxxxxxx| RD +-----------------+ |xxxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxxxx| WR +----------------+ |xxxxxxxxxxxxxxxxx| | | |xxxxxxxxxxxxxxxxx| | FREE SPACE | |xxxxxxxxxxxxxxxxx| | | +-----------------+ +----------------+
CASE 1: RD - WR > 0
There is one free area of memory which starts at the current WS pointer and continues to th current READ pointer. This case is straight-forward, either the amount of memory satisfies the requested size or it doesn't.
CASE 2: RD - WR < 0
There are two free areas of memory. The first choice is to try to satisfy the request by the piece which extends from the current WRITE to the end of the memory pool. If this does not satisfy the request, the amount from the beginning of the pool to the current READ pointer is tried. If this works one must 'remember' the abandoned piece so that it gets properly freed. In some sense, this piece is internally allocated. When the READ pointer catches up to this location (by doing RNG_free's) this shard of memory is also freed.
CASE 3: RD - WR = 0 (actually the SIZE of the POOL)
This indicates that the buffer is completely empty. For the most part, this is treated exactly as CASE 2. The one exception is when neither space is big enough to satisfy the request. In this case, since the entire buffer is empty, one can move the WR to the beginning of the buffer and the RD pointer to the bottom. This somewhat destroys the buffer for use as a history buffer, but, the alternative is to deny the caller the memory, even though it is available.
References _RNG_dsc::beg, _RNG_rcb::dsc, _RNG_rcb::dyn, _RNG_dsc::end, _RNG_dsc::msk, _RNG_dyn::que, _RNG_dyn::rd, _RNG_dyn::rdx, _RNG_dsc::rend, rng__wait(), RNG_K_PTR_ERROR, ROUND_TO, _RNG_rcb::rw, RW__tmr_destroy(), RW__tmr_init(), RW_M_OPT_PEND, RW_M_TIMEDOUT, _RNG_rcb::size, TOC_IS_NOWAIT, _RNG_dsc::type, _RNG_dyn::wr, and _RNG_dyn::wrx.
Referenced by RNG_get(), RNG_getW(), RNG_getW_toc(), RNG_grab(), RNG_grabW(), and RNG_grabW_toc().
int RNG_destroy | ( | RNG_rcb * | rcb | ) |
Returns any resources associated with this ring buffer.
rcb | The Ring Control Block |
Status | Frees any internally gathered resources associated with the specified ring buffer. The rcb is no longer usable as ring buffer after this call. |
References _RNG_rcb::rw, and RW_destroy().
void * RNG_dsc_get | ( | const RNG_rcb * | rcb | ) |
Query routine to return a pointer to the ring buffer description structure.
rcb | The ring control block |
A | pointer to ring buffer description |
Here is a overview of the elements and there use.
beg This a pointer to the top of the underflow portion of the buffer. If if there is no underflow area, this will be the same as rbeg. Because of alignment reason, this pointer may or may not agree with the original buffer pointer passed in by the user.
rbeg Pointer to the top of the ring buffer proper.
rend Pointer to the bottom of the ring buffer proper. Also, by definition, the start of the overflow area.
end Pointer to the bottom of the overflow area.
msk The alignment mask, for shorts = 1, ints = 3, long long = 7
buf The original buffer pointer passed into RCB_init by the user. This routine along with bufsize allows the user to recover the original address and size of the pool of memory the RNG utilities where requested to manage. This may be useful when closing the ring buffer, allowing the user to return the managed memory to where ever it came from.
bufsize The size of the original buffer
References _RNG_rcb::dsc.
Query routine to return a pointer to the ring buffer dynamic quantities.
rcb | The ring control block |
A | pointer to ring buffer description |
rd
wr Whereas many of the other query routines return pointers or values that are static and valid once the ring buffer has been initialized, this pointer is dynamic. Let the user beware.
shard Fetch a pointer to an potential shard. A shard is defined as an internally allocated piece of memory. The shard, by definition, occurs at the end of the buffer, absorbing the unallocated memory from the last allocation to the end of the buffer. The shard is left when the next allocation cannot be fulfilled by this remaining piece of memory, but there is enough memory at the top of the buffer. In this case, the allocation routine abandons this shard of memory, but notes it as such. When the memory preceding this shard is freed, the shard will be freed also.
Almost by definition, ring buffers configured with an overflow area will never have a shard. The caller has agreed that the overflow are will always cover any allocation, hence no shard will ever exist in this case.
References _RNG_rcb::dyn.
int RNG_free | ( | RNG_rcb * | rcb, | |
const void * | packet, | |||
int | amount | |||
) |
Frees the requested amount of memory from the specified address.
rcb | The Ring Control Block | |
packet | The pointer where the free begins | |
amount | The amount of memory to free |
0 | Successful | |
-1 | Packet being freed is not contigous with the previous packet being freed | |
-2 | Packet being freed extended into the shard area. Since this area is owned by the ring buffer and cannot belong to the user, this is a user specification error. |
If fails, the current read pointer is returned. The only practical reason for failing is that the packet being freed is does not match the current read pointer. Currently there is no sanity check to prevent the user from freeing more memory than is actually allocated. That is fairly expensive and, the thought is, if one does this, the next free is going to fail. This is a little dicey, but see how this works. If it doesn't will add the proper sanity check.
There is one case where overfreeing is detected, that is when the packet being freed extends into the user area. As compared with detecting an arbritary overfree, this one is relatively cheap, so it is done.
References _RNG_dsc::beg, _RNG_rcb::dsc, _RNG_rcb::dyn, _RNG_dsc::end, _RNG_dsc::msk, _RNG_dyn::que, _RNG_dyn::rd, _RNG_dyn::rdx, _RNG_dsc::rend, ROUND_TO, _RNG_rcb::rw, RW__lock(), RW__unlock(), RW__wake(), RW_M_OPT_PEND, _RNG_rcb::size, _RNG_dsc::type, and _RNG_dyn::wr.
void * RNG_get | ( | RNG_rcb * | rcb, | |
int | request, | |||
const void * | write | |||
) |
Non-blocking allocation request for a specified amount of memory.
rcb | The Ring Control Block | |
request | The size of the request, in bytes. | |
write | The end of the previously allocated block. Given the loose nature of ring buffers, this is used as an integrity check. If one is feeling brave, this may be specified as NULL. Doing this will skip the integrity checking. |
References _RNG_rcb::dyn, rng_allocate(), TOC_NOWAIT, and _RNG_dyn::wrx.
void * RNG_getW | ( | RNG_rcb * | rcb, | |
int | request, | |||
const void * | write | |||
) |
Blocking allocation request for a specified amount of memory.
rcb | The Ring Control Block | |
request | The size of the request, in bytes. | |
write | The end of the previously allocated block. Given the loose nature of ring buffers, this is used as an integrity check. If one is feeling brave, this may be specified as NULL. Doing this will skip the integrity checking. |
If the write pointer is inconsistent with the internal write pointer, NULL is returned. The user can distinguish these two cases by calling RNG_wr(), to fetch the current value of the write pointer. The user may also live dangerously and specify NULL for the write argument, in which case the consistency check is bypassed.
References _RNG_rcb::dyn, rng_allocate(), TOC_FOREVER, and _RNG_dyn::wrx.
Blocking allocation request for a specified amount of memory, with timeout.
rcb | The Ring Control Block | |
request | The size of the request, in bytes | |
write | The end of the previously allocated block. Given the loose nature of ring buffers, this is used as an integrity check. If one is feeling brave, this may be specified as NULL. Doing this will skip the integrity checking. | |
toc | The timeout control structure. This specifies the timeout value. TOC_NOWAIT and TOC_FOREVER may be specified here, although in this case the user should consider using RNG_get or RNG_getW. |
If the write pointer is inconsistent with the internal write pointer, NULL is returned. The user can distinguish these two cases by calling RNG_wr(), to fetch the current value of the write pointer. The user may also live dangerously and specify NULL for the write argument, in which case the consistency check is bypassed.
References _RNG_rcb::dyn, rng_allocate(), and _RNG_dyn::wrx.
void * RNG_grab | ( | RNG_rcb * | rcb, | |
int | minimum, | |||
const void * | write, | |||
int * | allocated | |||
) |
Non-blocking allocation request for all the remaining contigious memory, i.e. a greedy form of RNG_get.
rcb | The Ring Control Block | |
minimum | The minimum size requested, in bytes. | |
write | The end of the previously allocated block. Given the loose nature of ring buffers, this is used as an integrity check. If one is feeling brave, this may be specified as NULL. Doing this will skip the integrity checking. | |
allocated | Pointer to receive the actual amount, in bytes, that was allocated. |
If there is less than the minimum amount of memory in the pool, NULL is returned.
References rng_allocate(), and TOC_NOWAIT.
void * RNG_grabW | ( | RNG_rcb * | rcb, | |
int | minimum, | |||
const void * | write, | |||
int * | allocated | |||
) |
Blocking allocation request for all the remaining contigious memory, i.e. a greedy form of RNG_getW.
rcb | The Ring Control Block | |
minimum | The minimum size requested, in bytes. | |
write | The end of the previously allocated block. Given the loose nature of ring buffers, this is used as an integrity check. If one is feeling brave, this may be specified as NULL. Doing this will skip the integrity checking. | |
allocated | Pointer to receive the actual amount, in bytes, that was allocated. |
If there is less than the minimum amount of memory in the pool, RNG_grabW waits until the memory shows up. NULL is only on an internal error.
References rng_allocate(), and TOC_FOREVER.
void * RNG_grabW_toc | ( | RNG_rcb * | rcb, | |
int | minimum, | |||
const void * | write, | |||
int * | allocated, | |||
const TOC * | toc | |||
) |
Blocking allocation request for all the remaining contigious memory with a timeout, i.e. a greedy form of RNG_getWtos.
rcb | The Ring Control Block | |
minimum | The minimum size of the request, in bytes. | |
write | The end of the previously allocated block. Given the loose nature of ring buffers, this is used as an integrity check. If one is feeling brave, this may be specified as NULL. Doing this will skip the integrity checking. | |
allocated | Returned as the amount of memory actually allocated. | |
toc | The timeout control structure. This specifies the timeout value. TOC_NOWAIT and TOC_FOREVER may be specified here, although in this case the user should consider using RNG_grab or RNG_grabW. |
If the write pointer is inconsistent with the internal write pointer, NULL is returned. The user can distinguish these two cases by calling RNG_wr(), to fetch the current value of the write pointer. The user may also live dangerously and specify NULL for the write argument, in which case the consistency check is bypassed.
References rng_allocate().
int RNG_init | ( | RNG_rcb * | rcb, | |
RNG_type | type, | |||
void * | buffer, | |||
int | size, | |||
int | underflow, | |||
int | overflow, | |||
int | alignment | |||
) |
Initializes the control structure for a Ring buffer.
rcb | Pointer to the ring buffer control block structure to be initialized. | |
type | Indicates the type of ring buffer. This mainly controls the blocking. If insufficient memory is available, the allocation calls will block until it becomes available or a timeout occurs. | |
buffer | The buffer to be managed | |
size | The total size of the buffer (in bytes) to be managed | |
underflow | The size (in bytes) to be assigned to the underflow area. This area is an area immediately preceeding the ring buffer area. |
overflow | The size (in bytes) to be assigned to the overflow area. This area carved from the end buf. The useful property of the overflow area is that while memory may be allocated from the overflow area, an initial allocation never begins in the overflow area. This allows some continuity when the wrap-around point of the ring buffer is encountered. |
alignment | The byte alignment, expressed in binary powers of 2, eg
|
Status | Initializes a Ring Control Block to manage a pool of memory. The memory is carved into three pieces, an underflow area, a ring buffer area, and an overflow area. The detailed use and meaning of these areas is described elsewhere. |
References _RNG_dsc::beg, _RNG_dsc::buf, _RNG_dsc::bufsize, _RNG_rcb::dsc, _RNG_rcb::dyn, _RNG_dsc::end, _RNG_dsc::msk, _RNG_dyn::que, _RNG_dsc::rbeg, _RNG_dyn::rd, _RNG_dyn::rdx, _RNG_dsc::rend, ROUND_TO, _RNG_rcb::rw, RW_init(), _RNG_rcb::size, _RNG_dsc::type, _RNG_dyn::wr, and _RNG_dyn::wrx.
int RNG_reset | ( | RNG_rcb * | rcb | ) |
If the ring buffer is empty, reset the read and write pointers to their initial positions. This can only be called if the user knows that the buffer is empty.
rcb | The Ring Control Block |
So, one may ask, why not just reset the pointers to the empty state any time the ring buffer is totally empty. The answer is that this destroys any history that the ring buffer may accumulate. Imagine the case where one allocates some memory and then immediately frees it. The current implementation would deliver a different memory block each time. In a debugging mode, one could go back and examine this memory for some clues. If the buffer pointers where to be continually reset, this the memory would always be allocated from the top of the pool, and this debugging feature would be lost.
One possible alternative would be to make this resetting a optional configuration parameter on the ring buffer initialization. That way this would happen automatically.
References _RNG_dsc::beg, _RNG_rcb::dsc, _RNG_rcb::dyn, _RNG_dsc::end, _RNG_dyn::rd, _RNG_dyn::rdx, _RNG_rcb::size, _RNG_dyn::wr, and _RNG_dyn::wrx.
void * RNG_shrink | ( | RNG_rcb * | rcb, | |
const void * | write, | |||
int | left | |||
) |
Shrinks the previously allocated packet back to the specified address.
rcb | The Ring Control Block | |
write | The address to shrink to. The current write pointer, up to alignment factors, is moved to this address. | |
left | The unused amount, in bytes, of the previously allocated packet. This value + write addresss must match the current write pointer. If not, error. Note that the amount being returned must be consistent with the alignment factors. Concretely stated, if one demands 8-byte alignment, one cannot return in units less than 8-bytes. |
Typically one would allocate a block of memory, and fill it by advancing the pointer returned and decreasing the amount left. After filling the buffer, one would then call RNG_shrink to return the unused portion. The parameters to RNG_shrink will be the address of the next location to be written and the amount left.
Note also that this has no consequences on waking anyone up who may be waiting for memory. By definition, this is a single allocator system. Since, RNG_shrink is really just extension of the allocation process, no one can be waiting.
EXAMPLE
-------
amount = 100; ptr = RNG_get (rcb, amount, prv); if (ptr == NULL) perror ("No memory\n"); *ptr++ = 0xdeadbeef; amount -= 1; *ptr++ = 0xabadbabe; amount -= 1; chk = RNG_shrink (rcb, ptr, amount); if (chk == NULL) perror ("Bad shrink\n");
References _RNG_dsc::beg, _RNG_rcb::dsc, _RNG_rcb::dyn, _RNG_dsc::msk, _RNG_dyn::que, _RNG_dyn::rd, _RNG_dyn::rdx, _RNG_dsc::rend, _RNG_rcb::size, _RNG_dyn::wr, and _RNG_dyn::wrx.
int RNG_sizeof_rcb | ( | void | ) |
Returns the size of the Ring Contol Block.
The | size of a Ring Control Block |