PVOID
FASTCALL
WmipReserveTraceBuffer(
  IN  PWMI_LOGGER_CONTEXT LoggerContext,
  IN  ULONG RequiredSize,
  OUT PWMI_BUFFER_HEADER *BufferResource,
  OUT PLARGE_INTEGER TimeStamp
  );

Routine Description:
    This function is the main logging function that reserves spaces for any events.
    The algorithm is as follows:

    Every time a space is needed, we InterlockedExchangeAdd CurrentOffset.
    A local variable Offset is used to track the initial value when 
    InterlockedExchangeAdd is taken.  If there is enough space for this
    event (i.e., (Offset + RequiredSize) <= BufferSize), then we have successfully
    reserved the space.
    
    If there is not enough space left on this buffer, we will call WmipSwitchBuffer 
    for a new buffer.  In this case, CurrentOffset should be larger than the buffersize.
    Since other thread can still be trying to reserve space using thie buffer, we
    saved the offset on SavedOffset the the logger thread knows the real offset to be
    written to disk.

    Note that, since the CurrentOffset if growing monotonically, only one thread is
    advancing the CurrentOffset from below BufferSize to beyond BufferSize.  
    It is this thread's responsibility to set the SavedOffset properly.

Arguments:

    LoggerContext - Logger context from current logging session.

    RequiredSize  - The space needed for logging the data.

    Buffer        - Pointer to a buffer header

    TimeStamp     - TimeStamp of the event

Return Value:

    The status of running the buffer manager

Environment:

    Kernel mode.  This routine should work at any IRQL.