ReactOS  0.4.14-dev-323-g6fe6a88
circularbuffer.c File Reference
#include "serial.h"
#include <debug.h>
Include dependency graph for circularbuffer.c:

Go to the source code of this file.

Functions

NTSTATUS InitializeCircularBuffer (IN PCIRCULAR_BUFFER pBuffer, IN ULONG BufferSize)
 
NTSTATUS FreeCircularBuffer (IN PCIRCULAR_BUFFER pBuffer)
 
BOOLEAN IsCircularBufferEmpty (IN PCIRCULAR_BUFFER pBuffer)
 
ULONG GetNumberOfElementsInCircularBuffer (IN PCIRCULAR_BUFFER pBuffer)
 
NTSTATUS PushCircularBufferEntry (IN PCIRCULAR_BUFFER pBuffer, IN UCHAR Entry)
 
NTSTATUS PopCircularBufferEntry (IN PCIRCULAR_BUFFER pBuffer, OUT PUCHAR Entry)
 
NTSTATUS IncreaseCircularBufferSize (IN PCIRCULAR_BUFFER pBuffer, IN ULONG NewBufferSize)
 

Function Documentation

◆ FreeCircularBuffer()

NTSTATUS FreeCircularBuffer ( IN PCIRCULAR_BUFFER  pBuffer)

Definition at line 30 of file circularbuffer.c.

32 {
33  TRACE_(SERIAL, "FreeCircularBuffer(pBuffer %p)\n", pBuffer);
34  ASSERT(pBuffer);
35  if (pBuffer->Buffer != NULL)
37  return STATUS_SUCCESS;
38 }
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
#define SERIAL_TAG
Definition: serial.h:100
#define TRACE_(x)
Definition: compat.h:66
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by SerialAddDeviceInternal().

◆ GetNumberOfElementsInCircularBuffer()

ULONG GetNumberOfElementsInCircularBuffer ( IN PCIRCULAR_BUFFER  pBuffer)

Definition at line 50 of file circularbuffer.c.

52 {
53  TRACE_(SERIAL, "GetNumberOfElementsInCircularBuffer(pBuffer %p)\n", pBuffer);
54  ASSERT(pBuffer);
55  return (pBuffer->WritePosition + pBuffer->Length - pBuffer->ReadPosition) % pBuffer->Length;
56 }
PVOID pBuffer
#define TRACE_(x)
Definition: compat.h:66
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by SerialInterruptService().

◆ IncreaseCircularBufferSize()

NTSTATUS IncreaseCircularBufferSize ( IN PCIRCULAR_BUFFER  pBuffer,
IN ULONG  NewBufferSize 
)

Definition at line 91 of file circularbuffer.c.

94 {
95  PUCHAR NewBuffer;
96 
97  TRACE_(SERIAL, "IncreaseCircularBufferSize(pBuffer %p, NewBufferSize %lu)\n", pBuffer, NewBufferSize);
98  ASSERT(pBuffer);
99  ASSERT(pBuffer->Length);
100  if (pBuffer->Length > NewBufferSize)
102  else if (pBuffer->Length == NewBufferSize)
103  return STATUS_SUCCESS;
104 
105  NewBuffer = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, NewBufferSize * sizeof(UCHAR), SERIAL_TAG);
106  if (!NewBuffer)
108  RtlCopyMemory(NewBuffer, pBuffer->Buffer, pBuffer->Length * sizeof(UCHAR));
110  pBuffer->Buffer = NewBuffer;
111  pBuffer->Length = NewBufferSize;
112  return STATUS_SUCCESS;
113 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
unsigned char * PUCHAR
Definition: retypes.h:3
PVOID pBuffer
#define SERIAL_TAG
Definition: serial.h:100
#define TRACE_(x)
Definition: compat.h:66
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by SerialDeviceControl().

◆ InitializeCircularBuffer()

NTSTATUS InitializeCircularBuffer ( IN PCIRCULAR_BUFFER  pBuffer,
IN ULONG  BufferSize 
)

Definition at line 15 of file circularbuffer.c.

18 {
19  TRACE_(SERIAL, "InitializeCircularBuffer(pBuffer %p, BufferSize %lu)\n", pBuffer, BufferSize);
20  ASSERT(pBuffer);
22  if (!pBuffer->Buffer)
24  pBuffer->Length = BufferSize;
25  pBuffer->ReadPosition = pBuffer->WritePosition = 0;
26  return STATUS_SUCCESS;
27 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
unsigned char * PUCHAR
Definition: retypes.h:3
PVOID pBuffer
#define SERIAL_TAG
Definition: serial.h:100
#define TRACE_(x)
Definition: compat.h:66
#define BufferSize
Definition: classpnp.h:419
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by SerialAddDeviceInternal().

◆ IsCircularBufferEmpty()

BOOLEAN IsCircularBufferEmpty ( IN PCIRCULAR_BUFFER  pBuffer)

Definition at line 41 of file circularbuffer.c.

43 {
44  TRACE_(SERIAL, "IsCircularBufferEmpty(pBuffer %p)\n", pBuffer);
45  ASSERT(pBuffer);
46  return (pBuffer->ReadPosition == pBuffer->WritePosition);
47 }
PVOID pBuffer
#define TRACE_(x)
Definition: compat.h:66
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by PopCircularBufferEntry(), ReadBytes(), and SerialSendByte().

◆ PopCircularBufferEntry()

NTSTATUS PopCircularBufferEntry ( IN PCIRCULAR_BUFFER  pBuffer,
OUT PUCHAR  Entry 
)

Definition at line 76 of file circularbuffer.c.

79 {
80  TRACE_(SERIAL, "PopCircularBufferEntry(pBuffer %p)\n", pBuffer);
81  ASSERT(pBuffer);
82  ASSERT(pBuffer->Length);
85  *Entry = pBuffer->Buffer[pBuffer->ReadPosition];
86  pBuffer->ReadPosition = (pBuffer->ReadPosition + 1) % pBuffer->Length;
87  return STATUS_SUCCESS;
88 }
BOOLEAN IsCircularBufferEmpty(IN PCIRCULAR_BUFFER pBuffer)
PVOID pBuffer
#define TRACE_(x)
Definition: compat.h:66
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define STATUS_ARRAY_BOUNDS_EXCEEDED
Definition: ntstatus.h:362
base of all file and directory entries
Definition: entries.h:82

Referenced by ReadBytes(), and SerialSendByte().

◆ PushCircularBufferEntry()

NTSTATUS PushCircularBufferEntry ( IN PCIRCULAR_BUFFER  pBuffer,
IN UCHAR  Entry 
)

Definition at line 59 of file circularbuffer.c.

62 {
63  ULONG NextPosition;
64  TRACE_(SERIAL, "PushCircularBufferEntry(pBuffer %p, Entry 0x%x)\n", pBuffer, Entry);
65  ASSERT(pBuffer);
66  ASSERT(pBuffer->Length);
67  NextPosition = (pBuffer->WritePosition + 1) % pBuffer->Length;
68  if (NextPosition == pBuffer->ReadPosition)
70  pBuffer->Buffer[pBuffer->WritePosition] = Entry;
71  pBuffer->WritePosition = NextPosition;
72  return STATUS_SUCCESS;
73 }
struct _Entry Entry
Definition: kefuncs.h:640
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
PVOID pBuffer
#define TRACE_(x)
Definition: compat.h:66
if(!(yy_init))
Definition: macro.lex.yy.c:714
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938
base of all file and directory entries
Definition: entries.h:82

Referenced by SerialReceiveByte(), and SerialWrite().