diff --git a/utils/include/hdf_block_buffer.h b/utils/include/hdf_block_buffer.h index 205897e25f3391eed1679a4285966a8ec80c4cde..43a6837dee99610d25372f2d2b5b621506460e61 100644 --- a/utils/include/hdf_block_buffer.h +++ b/utils/include/hdf_block_buffer.h @@ -25,7 +25,7 @@ struct HdfBlockBuffer { struct HdfBlockBuffer *HdfBlockBufferNew(uint16_t size); -void HdfBlockBufferFree(struct BlockBuffer *buffer); +void HdfBlockBufferFree(const struct BlockBuffer *buffer); uint16_t HdfBlockBufferGetDataSize(struct BlockBuffer *buffer); @@ -96,8 +96,7 @@ bool HdfBlockBufferWriteShort(struct BlockBuffer *buffer, uint16_t shortValue); * * @return the new instance of buff which contain specific packet. */ -struct HdfBlockBuffer *HdfBlockBufferDuplicate( - struct HdfBlockBuffer *buffer, uint16_t start, uint16_t end); +struct HdfBlockBuffer *HdfBlockBufferDuplicate(const struct HdfBlockBuffer *buffer, uint16_t start, uint16_t end); /* * @brief append an byte array packet into buffer. diff --git a/utils/include/hdf_blocking_queue.h b/utils/include/hdf_blocking_queue.h index 5cfda6ecdd941404fe10f3511e1656a5a98cbcb9..7b51f3a8d46e0601977ebc596adb9c7fbaba3849 100644 --- a/utils/include/hdf_blocking_queue.h +++ b/utils/include/hdf_blocking_queue.h @@ -17,15 +17,13 @@ extern "C" { #endif -struct HdfBlockingQueue -{ +struct HdfBlockingQueue { struct HdfSList list; struct OsalSem sem; struct OsalMutex mutex; }; -struct HdfSListEntry -{ +struct HdfSListEntry { struct HdfSListNode node; void *data; }; diff --git a/utils/include/hdf_ordered_list.h b/utils/include/hdf_ordered_list.h index ffb4ad02d4e477011e0f96ca04f4c024a3a282d7..6f9aa2ba6b3be9e1867a43ceefd93a93798e2e97 100644 --- a/utils/include/hdf_ordered_list.h +++ b/utils/include/hdf_ordered_list.h @@ -28,9 +28,9 @@ struct HdfOrderedListEntity { long key; }; -typedef void(*HdfOrderedListEntityDeleter)(struct HdfOrderedListEntity *); +typedef void (*HdfOrderedListEntityDeleter)(struct HdfOrderedListEntity *); -typedef bool (*HdfOrderedListComparer)(long , void *); +typedef bool (*HdfOrderedListComparer)(long, void *); void HdfOrderedListInit(struct HdfOrderedList *list); diff --git a/utils/src/hdf_block_buffer.c b/utils/src/hdf_block_buffer.c index 7816114ed79aab289fa5d1134c1b7790dda94eed..1c61c57b495776b0c7846edf337df034d22342c6 100644 --- a/utils/src/hdf_block_buffer.c +++ b/utils/src/hdf_block_buffer.c @@ -6,11 +6,10 @@ * See the LICENSE file in the root of this repository for complete details. */ -#include -#include #include "hdf_block_buffer.h" #include "osal_mem.h" -#include "utils.h" + +static const unsigned int OFFSET = 8; struct HdfHdfBlockBuffer *HdfHdfBlockBufferNew(const uint8_t *data, uint16_t size) { @@ -25,17 +24,17 @@ struct HdfHdfBlockBuffer *HdfHdfBlockBufferNew(const uint8_t *data, uint16_t siz return NULL; } buffer->dataSize = size; - buffer->position = 0; - if (data != NULL) { - memcpy(buffer->data, data, size); - } + buffer->position = 0; + if (data != NULL) { + memcpy(buffer->data, data, size); + } return buffer; } -void HdfBlockBufferFree(struct HdfBlockBuffer *buffer) +void HdfBlockBufferFree(const struct HdfBlockBuffer *buffer) { if (buffer != NULL) { - free(buffer); + OsalMemFree(buffer); } } @@ -46,7 +45,7 @@ uint16_t HdfBlockBufferGetDataSize(struct HdfBlockBuffer *buffer) uint16_t HdfBlockBufferGetAvailableSize(struct HdfBlockBuffer *buffer) { - return (buffer == NULL) ? 0 : buffer->dataSize - buffer->position; + return (buffer == NULL) ? 0 : (buffer->dataSize - buffer->position); } uint8_t *HdfBlockBufferRead(struct HdfBlockBuffer *buffer, uint16_t size) @@ -153,14 +152,14 @@ bool HdfBlockBufferWriteUint8(struct HdfBlockBuffer *buffer, uint8_t value) return false; } -bool HdfBlockBufferWriteUint16(struct HdfBlockBuffer *buffer, uint16_t in_value) +bool HdfBlockBufferWriteUint16(struct HdfBlockBuffer *buffer, uint16_t inValue) { if (buffer == NULL) { return false; } if (buffer->position + BYTES_UINT16 <= buffer->dataSize) { - buffer->data[buffer->position++] = (uint8_t) (in_value >> 8); - buffer->data[buffer->position++] = (uint8_t) (in_value & 0xFF); + buffer->data[buffer->position++] = (uint8_t) (inValue >> OFFSET); + buffer->data[buffer->position++] = (uint8_t) (inValue & 0xFF); return true; } return false; @@ -181,8 +180,7 @@ bool HdfBlockBufferWriteData(struct HdfBlockBuffer *buffer, uint8_t *data, size_ return true; } -struct HdfBlockBuffer *HdfBlockBufferDuplicate( - struct HdfBlockBuffer *buffer, uint16_t start, uint16_t end) +struct HdfBlockBuffer *HdfBlockBufferDuplicate(const struct HdfBlockBuffer *buffer, uint16_t start, uint16_t end) { uint16_t bufferSize = HdfBlockBufferGetDataSize(buffer); uint16_t newBufferSize; diff --git a/utils/src/hdf_blocking_queue.c b/utils/src/hdf_blocking_queue.c index 613849e9ede996df8a586b31602f81a48883ab53..ed419b58caa730a23f9294d78ea4fef9784bb00a 100644 --- a/utils/src/hdf_blocking_queue.c +++ b/utils/src/hdf_blocking_queue.c @@ -110,7 +110,7 @@ void *HdfBlockingQueuePoll(struct HdfBlockingQueue *queue, long timeout) int HdfBlockingQueueOffer(struct HdfBlockingQueue *queue, void *val, long timeout) { - struct HdfSListEntry *entry = NULL; + struct HdfSListEntry *entry = NULL; if (OsalSemWait(&queue->sem, timeout) != 0) { return -1; } @@ -120,6 +120,6 @@ int HdfBlockingQueueOffer(struct HdfBlockingQueue *queue, void *val, long timeou HdfSListAddTail(&queue->list, &entry->node); OsalMutexUnlock(&queue->mutex); } - OsalSemPost(&queue->sem); + OsalSemPost(&queue->sem); } diff --git a/utils/src/hdf_object_alloc.c b/utils/src/hdf_object_alloc.c index ba4774c751d175d0f43608ada1582d43802784a4..c923d4936f6bf418b7068eb639ac2d3cedcbf0e2 100644 --- a/utils/src/hdf_object_alloc.c +++ b/utils/src/hdf_object_alloc.c @@ -6,14 +6,10 @@ * See the LICENSE file in the root of this repository for complete details. */ -#include -#include - +#include "hdf_base.h" +#include "hdf_object_alloc.h" #include "hdf_slist.h" -#include "object_alloc.h" -#include "osal_mem.h" #include "osal_mutex.h" -#include "utils.h" struct HdfChunkLink { uint32_t buffSize; @@ -66,7 +62,6 @@ struct HdfObjectNode *HdfObjectAllocFindSuitableChunk( while (HdfSListIteratorHasNext(&it)) { objectNode = (struct HdfObjectNode *)HdfSListIteratorNext(&it); - if (size == objectNode->chunkSize) { bestFitNode = objectNode; break; @@ -87,7 +82,6 @@ static void HdfObjectAllocPushObjectNode( while (HdfSListIteratorHasNext(&it)) { objectNode = (struct HdfObjectNode *)HdfSListIteratorNext(&it); - if (node->chunkSize >= objectNode->chunkSize) { break; } @@ -128,7 +122,7 @@ static void HdfObjectAllocPreloadChunk( void HdfObjectAllocLoadConfigs(const struct HdfObjectPoolConfig *configs) { - uint32_t idx = 0; + uint32_t idx; char *chunkBuffBegin = configs->buffer; char *chunkBuffEnd = configs->buffer + configs->bufferSize; @@ -161,7 +155,6 @@ void *HdfObjectAllocAlloc(size_t size) struct HdfObjectAlloc *allocator = HdfObjectAllocGetInstance(); OsalMutexLock(&allocator->mutex); objectNode = HdfObjectAllocFindSuitableChunk(allocator, size); - if ((objectNode != NULL) && (objectNode->freeCount == 0)) { goto finished; } @@ -184,7 +177,6 @@ void HdfObjectAllocFree(void *object) struct HdfObjectAlloc *allocator = HdfObjectAllocGetInstance(); OsalMutexLock(&allocator->mutex); objectNode = HdfObjectAllocFindSuitableChunk(allocator, chunkLink->buffSize); - if (objectNode != NULL) { objectNode->chunkStack[objectNode->freeCount++] = chunkLink; diff --git a/utils/src/hdf_ordered_list.c b/utils/src/hdf_ordered_list.c index a3cc2e2b94e60d823584a58392d03712a288c7f8..3f45ac33b4cad3f717a2b9a1d8cbc6685bb0503e 100644 --- a/utils/src/hdf_ordered_list.c +++ b/utils/src/hdf_ordered_list.c @@ -6,7 +6,6 @@ * See the LICENSE file in the root of this repository for complete details. */ -#include "osal_mem.h" #include "hdf_ordered_list.h" void HdfOrderedListInit(struct HdfOrderedList *list) @@ -86,7 +85,7 @@ long HdfOrderedListPeekKey(struct HdfOrderedList *list) } struct HdfOrderedListEntity *HdfOrderedListFetch( - struct HdfOrderedList *list, long matchKey, HdfOrderedListComparer comparer) + struct HdfOrderedList *list, long matchKey, HdfOrderedListComparer comparer) { struct HdfSListIterator it; struct HdfOrderedListEntity *matchEntity = NULL;