Skip to content

Commit

Permalink
add ringbuffer interface
Browse files Browse the repository at this point in the history
Signed-off-by: yayanyang <yayan.yang@gh-ca.com>
  • Loading branch information
yayanyang committed Jun 6, 2012
1 parent 11c2470 commit 9f645c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 10 additions & 2 deletions memory/ringbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ LEMON_IMPLEMENT_HANDLE(LemonRingBuffer){

size_t ValidBlocks;

size_t Capacity;

size_t BlockSize;

size_t PageSize;
Expand Down Expand Up @@ -98,7 +100,7 @@ LEMON_MEMORY_API

buffer->Back->Next = buffer->Front;

buffer->ValidBlocks = pages * blocksPerPage;
buffer->Capacity = buffer->ValidBlocks = pages * blocksPerPage;

return buffer;
}
Expand Down Expand Up @@ -218,5 +220,11 @@ LEMON_MEMORY_API
LEMON_MEMORY_API
size_t LemonRingBufferCapacity(__lemon_in LemonRingBuffer buffer)
{
return buffer->ValidBlocks;
return buffer->Capacity;
}

LEMON_MEMORY_API
size_t LemonRingBufferLength(__lemon_in LemonRingBuffer buffer)
{
return buffer->Capacity - buffer->ValidBlocks;
}
3 changes: 3 additions & 0 deletions memory/ringbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,8 @@ LEMON_MEMORY_API
LEMON_MEMORY_API
size_t LemonRingBufferCapacity(__lemon_in LemonRingBuffer buffer);

LEMON_MEMORY_API
size_t LemonRingBufferLength(__lemon_in LemonRingBuffer buffer);


#endif //LEMON_MEMORY_RINGBUFFER_H

0 comments on commit 9f645c7

Please sign in to comment.