Skip to content

Commit

Permalink
implement AlwaysContiguous mode of rawcircularbuffer, refactor socket…
Browse files Browse the repository at this point in the history
…thread
  • Loading branch information
bha-evs committed Nov 28, 2023
1 parent b97b2b4 commit 0b6bc42
Show file tree
Hide file tree
Showing 11 changed files with 517 additions and 298 deletions.
40 changes: 31 additions & 9 deletions lib/include/bofstd/bofcircularbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ class BofCircularBuffer
uint32_t GetMaxLevel() const;
bool IsBufferOverflow();
void Reset();
uint32_t GetPushIndex();
uint32_t GetPopIndex();
DataType *GetInternalDataBuffer() const;
BOFERR Push(const DataType *_pData, uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pIndexOf_U32);
BOFERR Push(const DataType *_pData, uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pIndexOf_U32, DataType **_ppStorage_X);
BOFERR PushForNextPop(const DataType *_pData, bool _ForceIfFull_B, uint32_t _BlockingTimeouItInMs_U32); // Old InsertAsFirst
BOFERR Pop(DataType *_pData, uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pIndexOf_U32, DataType **_ppStorage); //_ppStorage is mainly used in mCircularBufferParam_X.PopLockMode_B to provide write access to the locked storage cell
BOFERR PopLastPush(DataType *_pData, uint32_t *_pIndexOf_U32, DataType **_ppStorage);
Expand Down Expand Up @@ -150,11 +152,11 @@ BofCircularBuffer<DataType>::BofCircularBuffer(const BOF_CIRCULAR_BUFFER_PARAM &

if (mCircularBufferParam_X.NbMaxElement_U32)
{
if (mCircularBufferParam_X.Blocking_B)
{
mErrorCode_E = (_rCircularBufferParam_X.MultiThreadAware_B) ? BOF_ERR_NO_ERROR : BOF_ERR_WRONG_MODE;
}
else
//if (mCircularBufferParam_X.Blocking_B)
//{
// mErrorCode_E = (_rCircularBufferParam_X.MultiThreadAware_B) ? BOF_ERR_NO_ERROR : BOF_ERR_WRONG_MODE;
//}
//else
{
mErrorCode_E = BOF_ERR_NO_ERROR;
}
Expand Down Expand Up @@ -210,6 +212,10 @@ BofCircularBuffer<DataType>::BofCircularBuffer(const BOF_CIRCULAR_BUFFER_PARAM &
{
mErrorCode_E = BOF_ERR_EINVAL;
}
if (mpLock_U8 == nullptr)
{
printf("jj");
}
}

template <typename DataType>
Expand Down Expand Up @@ -320,7 +326,16 @@ bool BofCircularBuffer<DataType>::IsBufferOverflow()
mOverflow_B = false;
return Rts_B;
}

template <typename DataType>
uint32_t BofCircularBuffer<DataType>::GetPushIndex()
{
return mPushIndex_U32;
}
template <typename DataType>
uint32_t BofCircularBuffer<DataType>::GetPopIndex()
{
return mPopIndex_U32;
}
template <typename DataType>
void BofCircularBuffer<DataType>::Reset()
{
Expand Down Expand Up @@ -349,9 +364,13 @@ DataType *BofCircularBuffer<DataType>::GetInternalDataBuffer() const
}

template <typename DataType>
BOFERR BofCircularBuffer<DataType>::Push(const DataType *_pData, uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pIndexOf_U32)
BOFERR BofCircularBuffer<DataType>::Push(const DataType *_pData, uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pIndexOf_U32, DataType **_ppStorage_X)
{
BOFERR Rts_E = BOF_ERR_EINVAL;
if (mpLock_U8 == nullptr)
{
printf("jj");
}

if (_pData)
{
Expand All @@ -374,6 +393,10 @@ BOFERR BofCircularBuffer<DataType>::Push(const DataType *_pData, uint32_t _Block
{
*_pIndexOf_U32 = mPushIndex_U32;
}
if (_ppStorage_X)
{
*_ppStorage_X = &mpData_T[mPushIndex_U32];
}
mpData_T[mPushIndex_U32] = *_pData;
BOF_ASSERT(mPushIndex_U32 < mCircularBufferParam_X.NbMaxElement_U32);
mPushIndex_U32++;
Expand Down Expand Up @@ -739,7 +762,6 @@ BOFERR BofCircularBuffer<DataType>::Peek(DataType *_pData, uint32_t _BlockingTim
else
{
Rts_E = BOF_ERR_LOCK;
;
}
}
else
Expand Down
12 changes: 8 additions & 4 deletions lib/include/bofstd/bofrawcircularbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ struct BOF_RAW_CIRCULAR_BUFFER_PARAM
bool MultiThreadAware_B; /*! true if the object is used in a multi threaded application (use mCs)*/
uint32_t BufferSizeInByte_U32; /*! Specifies the maximum number of byte inside inside the queue*/
bool SlotMode_B; /* If true, the mpData_U8 buffer of BufferSizeInByte_U32 will be divided by NbMaxBufferEntry_U32 and each slot will be BufferSizeInByte_U32/NbMaxBufferEntry_U32 */
bool AlwaysContiguous_B; /*! No sens for SlotMode_B (data are always contiguous in SlotMode_B). With non SlotMode_B buffer, if this parameter is true all data element stored in the buffer
will always be contiguous, so an element at the end of the buffer will never be splitted between the end and the beginning of the buffer. If this case is detected
an empy zone will be created to align the buffer to the start and if you call GetBufferPtr(..., uint32_t *_pNb1_U32, uint8_t **_ppData1_U8, uint32_t *_pNb2_U32, uint8_t **_ppData2_U8)
*_pNb2_U32 will ALWAYS BE 0 */
uint32_t NbMaxBufferEntry_U32; /*! Specifies the maximum number of buffer which will be tracked inside the mpData_U8 buffer of BufferSizeInByte_U32*/
uint8_t *pData_U8; /*! Pointer to queue storage buffer used to record queue element*/
bool Overwrite_B; /*! true if new data overwritte the oldest one when the queue is full. */
Expand Down Expand Up @@ -142,9 +146,9 @@ class BOFSTD_EXPORT BofRawCircularBuffer
void Reset();
uint32_t GetNbFreeElement(uint32_t *_pRemainingSize_U32);
BOFERR SetOverWriteMode(bool _Overwrite_B);
BOFERR SetAppendMode(uint32_t _BlockingTimeouItInMs_U32, bool _Append_B);
BOFERR SetAppendMode(uint32_t _BlockingTimeouItInMs_U32, bool _Append_B, BOF_RAW_BUFFER **_ppStorage_X);
bool IsBufferOverflow();
BOFERR PushBuffer(uint32_t _BlockingTimeouItInMs_U32, uint32_t _Nb_U32, const uint8_t *_pData_U8);
BOFERR PushBuffer(uint32_t _BlockingTimeouItInMs_U32, uint32_t _Nb_U32, const uint8_t *_pData_U8, BOF_RAW_BUFFER **_ppStorage_X);
BOFERR PopBuffer(uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pNbMax_U32, uint8_t *_pData_U8);
BOFERR Peek(uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pNbMax_U32, uint8_t *_pData_U8);
//Need to call Skip after GetBufferPtr
Expand All @@ -153,8 +157,8 @@ class BOFSTD_EXPORT BofRawCircularBuffer
BOFERR Skip(bool _SignalIfNeeded_B, bool *_pLocked_B);

private:
BOFERR PushRawBuffer(uint32_t _BlockingTimeouItInMs_U32);
BOFERR UpdatePushRawBuffer(uint32_t _Size_U32, const uint8_t *_pData_U8);
BOFERR PushRawBuffer(uint32_t _BlockingTimeouItInMs_U32, BOF_RAW_BUFFER **_ppStorage_X);
BOFERR UpdatePushRawBuffer(uint32_t _SizeUpToTheEnd_U32, uint32_t _Size_U32, const uint8_t *_pData_U8);
BOFERR PopOrPeekBuffer(bool _Pop_B, uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pNbMax_U32, uint8_t *_pData_U8);
};

Expand Down
23 changes: 10 additions & 13 deletions lib/include/bofstd/bofsocketthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,16 @@ struct BOF_SOCKET_OPERATION_PARAM
uint32_t Ticket_U32;
uint32_t TimeOut_U32;
uint32_t Timer_U32; /*! The associated timer */
// Using an union create problem: warning C4624: 'onbings::bof::BOF_SOCKET_OPERATION_PARAM': destructor was implicitly defined as deleted
// So I inline them
BOF_SOCKET_EXIT_PARAM Exit_X; /*! The exit operation params */
BOF_SOCKET_LISTEN_PARAM Listen_X; /*! The listen operation params */
BOF_SOCKET_CONNECT_PARAM Connect_X; /*! The connect operation params */
BOF_SOCKET_READ_PARAM Read_X; /*! The read operation params */
BOF_SOCKET_WRITE_PARAM Write_X; /*! The write operation params */
BOF_SOCKET_DISCONNECT_PARAM Disconnect_X;
union _OpParam
{
_OpParam() {}
BOF_SOCKET_EXIT_PARAM Exit_X; /*! The exit operation params */
BOF_SOCKET_LISTEN_PARAM Listen_X; /*! The listen operation params */
BOF_SOCKET_CONNECT_PARAM Connect_X; /*! The connect operation params */
BOF_SOCKET_READ_PARAM Read_X; /*! The read operation params */
BOF_SOCKET_WRITE_PARAM Write_X; /*! The write operation params */
BOF_SOCKET_DISCONNECT_PARAM Disconnect_X;
} OpParam;
BOF_SOCKET_OPERATION_PARAM()
{
Reset();
Expand All @@ -212,11 +214,6 @@ struct BOF_SOCKET_OPERATION_PARAM
Ticket_U32 = 0;
TimeOut_U32 = 0;
Timer_U32 = 0;
Listen_X.Reset();
Connect_X.Reset();
Read_X.Reset();
Write_X.Reset();
Disconnect_X.Reset();
}
};

Expand Down
2 changes: 1 addition & 1 deletion lib/src/bofasync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ BOFERR BofCommandQueue::PostCommand(bool _OnlyOne_B, const BOF_COMMAND_QUEUE_ENT
}
if (Rts_E == BOF_ERR_NO_ERROR)
{
Rts_E = mpuCommandEntryCollection->Push(&_rCommand_X, 0, nullptr);
Rts_E = mpuCommandEntryCollection->Push(&_rCommand_X, 0, nullptr, nullptr);
}
}
return Rts_E;
Expand Down
Loading

0 comments on commit 0b6bc42

Please sign in to comment.