Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.c/src/common/base')
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory.h94
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FixedSize.c172
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FixedSize.h60
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c414
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.h70
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.c204
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.h98
7 files changed, 556 insertions, 556 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory.h b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory.h
index 32683d8dd..b1c7d7cae 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory.h
@@ -1,47 +1,47 @@
-/*******************************************************************************
- * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-#ifndef _ETMEMORY_H_
-#define _ETMEMORY_H_
-
-#include "etDatatypes.h"
-
-#define CEIL_ALIGN(n) ((n)+((ALIGNMENT-((n)&(ALIGNMENT-1)))&(ALIGNMENT-1)))
-
-struct etMemory;
-
-/**
- * allocates memory from the heap
- *
- * \param heap pointer to the heap memory
- * \param size the size of the requested memory in bytes
- */
-typedef void* etMemory_alloc(struct etMemory* heap, etUInt16 size);
-
-/**
- * frees memory previously allocated from the heap
- *
- * \param heap pointer to the heap memory
- * \param obj pointer to the memory returned
- * \param size the size in bytes of the memory returned
- */
-typedef void etMemory_free(struct etMemory* heap, void* obj, etUInt16 size);
-
-typedef struct etMemory {
- /** size of the heap in bytes */
- etUInt32 size;
-
- etMemory_alloc* alloc;
- etMemory_free* free;
-} etMemory;
-
-#endif /* _ETMEMORY_H_ */
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef _ETMEMORY_H_
+#define _ETMEMORY_H_
+
+#include "etDatatypes.h"
+
+#define CEIL_ALIGN(n) ((n)+((ALIGNMENT-((n)&(ALIGNMENT-1)))&(ALIGNMENT-1)))
+
+struct etMemory;
+
+/**
+ * allocates memory from the heap
+ *
+ * \param heap pointer to the heap memory
+ * \param size the size of the requested memory in bytes
+ */
+typedef void* etMemory_alloc(struct etMemory* heap, etUInt16 size);
+
+/**
+ * frees memory previously allocated from the heap
+ *
+ * \param heap pointer to the heap memory
+ * \param obj pointer to the memory returned
+ * \param size the size in bytes of the memory returned
+ */
+typedef void etMemory_free(struct etMemory* heap, void* obj, etUInt16 size);
+
+typedef struct etMemory {
+ /** size of the heap in bytes */
+ etUInt32 size;
+
+ etMemory_alloc* alloc;
+ etMemory_free* free;
+} etMemory;
+
+#endif /* _ETMEMORY_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FixedSize.c b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FixedSize.c
index 2bb385725..b347c171e 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FixedSize.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FixedSize.c
@@ -1,86 +1,86 @@
-/*******************************************************************************
- * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-#include "base/etMemory_FixedSize.h"
-#include "base/etQueue.h"
-#include "debugging/etLogger.h"
-#include "debugging/etMSCLogger.h"
-
-
-typedef struct etFixedSizeMemory {
- etMemory base;
-
- etUInt8 *buffer;
- etUInt16 maxBlocks;
- etUInt16 blockSize;
- etQueue blockPool;
-} etFixedSizeMemory;
-
-
-void* etMemory_FixedSize_alloc(etMemory* heap, etUInt16 size) {
- etFixedSizeMemory* self = (etFixedSizeMemory*) heap;
- void* mem = NULL;
- size = CEIL_ALIGN(size);
-
- ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "alloc")
-
- if (size<=self->blockSize){
- if (self->blockPool.size>0) {
- mem = etQueue_pop(&self->blockPool);
- }
- }
-
- ET_MSC_LOGGER_SYNC_EXIT
- return mem;
-}
-
-void etMemory_FixedSize_free(etMemory* heap, void* obj, etUInt16 size) {
- etFixedSizeMemory* self = (etFixedSizeMemory*) heap;
-
- ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "free")
-
- etQueue_push(&self->blockPool, obj);
-
- ET_MSC_LOGGER_SYNC_EXIT
-}
-
-/*
- * the public interface
- */
-etMemory* etMemory_FixedSize_init(void* heap, etUInt32 size, etUInt16 blockSize) {
- etFixedSizeMemory* self = (etFixedSizeMemory*) heap;
- size_t data_size = CEIL_ALIGN(sizeof(etFixedSizeMemory));
- int i;
-
- ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "init")
-
- self->base.size = size;
- self->base.alloc = etMemory_FixedSize_alloc;
- self->base.free = etMemory_FixedSize_free;
-
- if (size > data_size) {
- self->buffer = ((etUInt8*) self) + data_size;
- self->blockSize = blockSize;
- self->maxBlocks = (size - data_size) / self->blockSize;
- for (i=0; i<self->maxBlocks; i++){
- void* block = &(self->buffer[i*self->blockSize]);
- etQueue_push(&self->blockPool, block);
- }
- }
- else {
- self->blockSize = 0;
- }
-
- ET_MSC_LOGGER_SYNC_EXIT
-
- return &self->base;
-}
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "base/etMemory_FixedSize.h"
+#include "base/etQueue.h"
+#include "debugging/etLogger.h"
+#include "debugging/etMSCLogger.h"
+
+
+typedef struct etFixedSizeMemory {
+ etMemory base;
+
+ etUInt8 *buffer;
+ etUInt16 maxBlocks;
+ etUInt16 blockSize;
+ etQueue blockPool;
+} etFixedSizeMemory;
+
+
+void* etMemory_FixedSize_alloc(etMemory* heap, etUInt16 size) {
+ etFixedSizeMemory* self = (etFixedSizeMemory*) heap;
+ void* mem = NULL;
+ size = CEIL_ALIGN(size);
+
+ ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "alloc")
+
+ if (size<=self->blockSize){
+ if (self->blockPool.size>0) {
+ mem = etQueue_pop(&self->blockPool);
+ }
+ }
+
+ ET_MSC_LOGGER_SYNC_EXIT
+ return mem;
+}
+
+void etMemory_FixedSize_free(etMemory* heap, void* obj, etUInt16 size) {
+ etFixedSizeMemory* self = (etFixedSizeMemory*) heap;
+
+ ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "free")
+
+ etQueue_push(&self->blockPool, obj);
+
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+/*
+ * the public interface
+ */
+etMemory* etMemory_FixedSize_init(void* heap, etUInt32 size, etUInt16 blockSize) {
+ etFixedSizeMemory* self = (etFixedSizeMemory*) heap;
+ size_t data_size = CEIL_ALIGN(sizeof(etFixedSizeMemory));
+ int i;
+
+ ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "init")
+
+ self->base.size = size;
+ self->base.alloc = etMemory_FixedSize_alloc;
+ self->base.free = etMemory_FixedSize_free;
+
+ if (size > data_size) {
+ self->buffer = ((etUInt8*) self) + data_size;
+ self->blockSize = blockSize;
+ self->maxBlocks = (size - data_size) / self->blockSize;
+ for (i=0; i<self->maxBlocks; i++){
+ void* block = &(self->buffer[i*self->blockSize]);
+ etQueue_push(&self->blockPool, block);
+ }
+ }
+ else {
+ self->blockSize = 0;
+ }
+
+ ET_MSC_LOGGER_SYNC_EXIT
+
+ return &self->base;
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FixedSize.h b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FixedSize.h
index eb037e92a..1a8715f0d 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FixedSize.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FixedSize.h
@@ -1,30 +1,30 @@
-/*******************************************************************************
- * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-#ifndef _ETMEMORY_FIXED_SIZE_H_
-#define _ETMEMORY_FIXED_SIZE_H_
-
-#include "base/etMemory.h"
-#include "base/etQueue.h"
-
-/**
- * initializes the heap with a simple block management
- *
- * \param heap pointer to the heap to be managed
- * \param size the size in bytes of the heap
- * \param blockSize the size of the (equal sized) blocks
- *
- * \return the pointer to the initialized etMemory struct
- */
-etMemory* etMemory_FixedSize_init(void* heap, etUInt32 size, etUInt16 blockSize);
-
-#endif /* _ETMEMORY_FIXED_SIZE_H_ */
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef _ETMEMORY_FIXED_SIZE_H_
+#define _ETMEMORY_FIXED_SIZE_H_
+
+#include "base/etMemory.h"
+#include "base/etQueue.h"
+
+/**
+ * initializes the heap with a simple block management
+ *
+ * \param heap pointer to the heap to be managed
+ * \param size the size in bytes of the heap
+ * \param blockSize the size of the (equal sized) blocks
+ *
+ * \return the pointer to the initialized etMemory struct
+ */
+etMemory* etMemory_FixedSize_init(void* heap, etUInt32 size, etUInt16 blockSize);
+
+#endif /* _ETMEMORY_FIXED_SIZE_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c
index 4f23cb7bc..69fea62fb 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c
@@ -1,207 +1,207 @@
-/*******************************************************************************
- * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-#include "base/etMemory_FreeList.h"
-#include "debugging/etLogger.h"
-#include "debugging/etMSCLogger.h"
-
-#define UNUSED_LIST 0
-#define DEBUG_FREE_LISTS 1
-
-typedef struct etFreeListObj {
- struct etFreeListObj* next;
-} etFreeListObj;
-
-typedef struct etFreeListInfo {
- /** the size in bytes of the objects in this list */
- etUInt16 objsize;
-
- /** the list head */
- etFreeListObj* head;
-
-#if DEBUG_FREE_LISTS
- etUInt16 nobjects;
-#endif
-
-} etFreeListInfo;
-
-typedef struct etFreeListMemory {
- etMemory base;
-
- /** next free position on the heap */
- etUInt8* current;
-
- /** number of free lists */
- etUInt16 nslots;
-
- /** array of free list infos (array used with size nslots) */
- etFreeListInfo freelists[1];
-} etFreeListMemory;
-
-/*
- * private functions
- */
-static void* etMemory_getHeapMem(etFreeListMemory* self, etUInt16 size) {
- etUInt8* obj = NULL;
- ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "getHeapListMem")
-
- if (self->current < ((etUInt8*)self)+self->base.size)
- {
- obj = self->current;
- self->current += size;
- }
-
- ET_MSC_LOGGER_SYNC_EXIT
- return obj;
-}
-
-static void* etMemory_getFreeListMem(etFreeListMemory* self, etUInt16 size) {
- etUInt8* mem = NULL;
- int asize, slot_offset, slot, slot_size;
- ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "getFreeListMem")
-
- asize = (size / ALIGNMENT);
- for (slot_offset = 0; slot_offset < self->nslots; slot_offset++) {
- slot = (asize + slot_offset) % self->nslots;
- slot_size = self->freelists[slot].objsize;
- if (slot_size == size) {
- if (self->freelists[slot].head != NULL) {
- etFreeListObj* obj = self->freelists[slot].head;
- self->freelists[slot].head = obj->next;
- mem = (void *) obj;
-#if DEBUG_FREE_LISTS
- --self->freelists[slot].nobjects;
-#endif
- }
- break;
- }
- else if (slot_size == UNUSED_LIST)
- break;
- }
- ET_MSC_LOGGER_SYNC_EXIT
- return mem;
-}
-
-static void etMemory_putFreeListMem(etFreeListMemory* self, void* obj, etUInt16 size) {
- ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "putFreeListMem")
- {
- int asize, slot_offset, slot, slot_size;
-
- asize = (size / ALIGNMENT);
- for (slot_offset = 0; slot_offset < self->nslots; slot_offset++) {
- slot = (asize + slot_offset) % self->nslots;
- slot_size = self->freelists[slot].objsize;
- if (slot_size == size) {
- /* we insert the object as new head */
- ((etFreeListObj*)obj)->next = self->freelists[slot].head;
- self->freelists[slot].head = (etFreeListObj*)obj;
-#if DEBUG_FREE_LISTS
- ++self->freelists[slot].nobjects;
-#endif
- break;
- }
- else if (slot_size == UNUSED_LIST) {
- /* initialize unused list and insert the object as new head */
- self->freelists[slot].objsize = size;
- ((etFreeListObj*)obj)->next = NULL;
- self->freelists[slot].head = (etFreeListObj*)obj;
-#if DEBUG_FREE_LISTS
- self->freelists[slot].nobjects = 1;
-#endif
- break;
- }
- }
- }
- ET_MSC_LOGGER_SYNC_EXIT
-}
-
-void* etMemory_FreeList_alloc(etMemory* heap, etUInt16 size) {
- void* mem;
- size = CEIL_ALIGN(size);
- ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "alloc")
-
- mem = etMemory_getFreeListMem((etFreeListMemory*) heap, size);
- if (mem==NULL)
- mem = etMemory_getHeapMem((etFreeListMemory*) heap, size);
-
- ET_MSC_LOGGER_SYNC_EXIT
- return mem;
-}
-
-void etMemory_FreeList_free(etMemory* heap, void* obj, etUInt16 size) {
- ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "free")
- {
- size = CEIL_ALIGN(size);
- etMemory_putFreeListMem((etFreeListMemory*) heap, obj, size);
- }
- ET_MSC_LOGGER_SYNC_EXIT
-}
-
-/*
- * the public interface
- */
-etMemory* etMemory_FreeList_init(void* heap, etUInt32 size, etUInt16 nslots) {
- etFreeListMemory* self = (etFreeListMemory*) heap;
- ET_MSC_LOGGER_SYNC_ENTRY("etMemory_FreeList_init", "init")
-
- self->base.size = size;
- self->base.alloc = etMemory_FreeList_alloc;
- self->base.free = etMemory_FreeList_free;
- self->nslots = nslots;
- {
- int used = sizeof(etFreeListMemory)+(self->nslots-1)*sizeof(etFreeListObj);
- self->current = ((etUInt8*)self)+CEIL_ALIGN(used);
- }
-
- /* initialize the free lists */
- {
- int i;
- for (i=0; i<self->nslots; ++i)
- self->freelists[i].objsize = UNUSED_LIST;
- }
- ET_MSC_LOGGER_SYNC_EXIT
-
- return &self->base;
-}
-
-etUInt32 etMemory_FreeList_freeHeapMem(void* heap) {
- etFreeListMemory* self = (etFreeListMemory*) heap;
- return ((etUInt8*)self)+self->base.size - self->current;
-}
-
-etUInt16 etMemory_FreeList_freeSlots(void* heap) {
- etFreeListMemory* self = (etFreeListMemory*) heap;
- etUInt16 free = 0;
- int slot;
-
- for (slot=0; slot<self->nslots; ++slot)
- if (self->freelists[slot].objsize==UNUSED_LIST)
- ++free;
-
- return free;
-}
-
-etUInt16 etMemory_FreeList_nObjects(void* heap, etUInt16 slot) {
-#if DEBUG_FREE_LISTS
- etFreeListMemory* self = (etFreeListMemory*) heap;
- if (slot<self->nslots)
- return self->freelists[slot].nobjects;
-#endif
- return 0;
-}
-
-etUInt16 etMemory_FreeList_sizeObjects(void* heap, etUInt16 slot) {
- etFreeListMemory* self = (etFreeListMemory*) heap;
- if (slot<self->nslots)
- return self->freelists[slot].objsize;
- return 0;
-}
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "base/etMemory_FreeList.h"
+#include "debugging/etLogger.h"
+#include "debugging/etMSCLogger.h"
+
+#define UNUSED_LIST 0
+#define DEBUG_FREE_LISTS 1
+
+typedef struct etFreeListObj {
+ struct etFreeListObj* next;
+} etFreeListObj;
+
+typedef struct etFreeListInfo {
+ /** the size in bytes of the objects in this list */
+ etUInt16 objsize;
+
+ /** the list head */
+ etFreeListObj* head;
+
+#if DEBUG_FREE_LISTS
+ etUInt16 nobjects;
+#endif
+
+} etFreeListInfo;
+
+typedef struct etFreeListMemory {
+ etMemory base;
+
+ /** next free position on the heap */
+ etUInt8* current;
+
+ /** number of free lists */
+ etUInt16 nslots;
+
+ /** array of free list infos (array used with size nslots) */
+ etFreeListInfo freelists[1];
+} etFreeListMemory;
+
+/*
+ * private functions
+ */
+static void* etMemory_getHeapMem(etFreeListMemory* self, etUInt16 size) {
+ etUInt8* obj = NULL;
+ ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "getHeapListMem")
+
+ if (self->current < ((etUInt8*)self)+self->base.size)
+ {
+ obj = self->current;
+ self->current += size;
+ }
+
+ ET_MSC_LOGGER_SYNC_EXIT
+ return obj;
+}
+
+static void* etMemory_getFreeListMem(etFreeListMemory* self, etUInt16 size) {
+ etUInt8* mem = NULL;
+ int asize, slot_offset, slot, slot_size;
+ ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "getFreeListMem")
+
+ asize = (size / ALIGNMENT);
+ for (slot_offset = 0; slot_offset < self->nslots; slot_offset++) {
+ slot = (asize + slot_offset) % self->nslots;
+ slot_size = self->freelists[slot].objsize;
+ if (slot_size == size) {
+ if (self->freelists[slot].head != NULL) {
+ etFreeListObj* obj = self->freelists[slot].head;
+ self->freelists[slot].head = obj->next;
+ mem = (void *) obj;
+#if DEBUG_FREE_LISTS
+ --self->freelists[slot].nobjects;
+#endif
+ }
+ break;
+ }
+ else if (slot_size == UNUSED_LIST)
+ break;
+ }
+ ET_MSC_LOGGER_SYNC_EXIT
+ return mem;
+}
+
+static void etMemory_putFreeListMem(etFreeListMemory* self, void* obj, etUInt16 size) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "putFreeListMem")
+ {
+ int asize, slot_offset, slot, slot_size;
+
+ asize = (size / ALIGNMENT);
+ for (slot_offset = 0; slot_offset < self->nslots; slot_offset++) {
+ slot = (asize + slot_offset) % self->nslots;
+ slot_size = self->freelists[slot].objsize;
+ if (slot_size == size) {
+ /* we insert the object as new head */
+ ((etFreeListObj*)obj)->next = self->freelists[slot].head;
+ self->freelists[slot].head = (etFreeListObj*)obj;
+#if DEBUG_FREE_LISTS
+ ++self->freelists[slot].nobjects;
+#endif
+ break;
+ }
+ else if (slot_size == UNUSED_LIST) {
+ /* initialize unused list and insert the object as new head */
+ self->freelists[slot].objsize = size;
+ ((etFreeListObj*)obj)->next = NULL;
+ self->freelists[slot].head = (etFreeListObj*)obj;
+#if DEBUG_FREE_LISTS
+ self->freelists[slot].nobjects = 1;
+#endif
+ break;
+ }
+ }
+ }
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+void* etMemory_FreeList_alloc(etMemory* heap, etUInt16 size) {
+ void* mem;
+ size = CEIL_ALIGN(size);
+ ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "alloc")
+
+ mem = etMemory_getFreeListMem((etFreeListMemory*) heap, size);
+ if (mem==NULL)
+ mem = etMemory_getHeapMem((etFreeListMemory*) heap, size);
+
+ ET_MSC_LOGGER_SYNC_EXIT
+ return mem;
+}
+
+void etMemory_FreeList_free(etMemory* heap, void* obj, etUInt16 size) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "free")
+ {
+ size = CEIL_ALIGN(size);
+ etMemory_putFreeListMem((etFreeListMemory*) heap, obj, size);
+ }
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+/*
+ * the public interface
+ */
+etMemory* etMemory_FreeList_init(void* heap, etUInt32 size, etUInt16 nslots) {
+ etFreeListMemory* self = (etFreeListMemory*) heap;
+ ET_MSC_LOGGER_SYNC_ENTRY("etMemory_FreeList_init", "init")
+
+ self->base.size = size;
+ self->base.alloc = etMemory_FreeList_alloc;
+ self->base.free = etMemory_FreeList_free;
+ self->nslots = nslots;
+ {
+ int used = sizeof(etFreeListMemory)+(self->nslots-1)*sizeof(etFreeListObj);
+ self->current = ((etUInt8*)self)+CEIL_ALIGN(used);
+ }
+
+ /* initialize the free lists */
+ {
+ int i;
+ for (i=0; i<self->nslots; ++i)
+ self->freelists[i].objsize = UNUSED_LIST;
+ }
+ ET_MSC_LOGGER_SYNC_EXIT
+
+ return &self->base;
+}
+
+etUInt32 etMemory_FreeList_freeHeapMem(void* heap) {
+ etFreeListMemory* self = (etFreeListMemory*) heap;
+ return ((etUInt8*)self)+self->base.size - self->current;
+}
+
+etUInt16 etMemory_FreeList_freeSlots(void* heap) {
+ etFreeListMemory* self = (etFreeListMemory*) heap;
+ etUInt16 free = 0;
+ int slot;
+
+ for (slot=0; slot<self->nslots; ++slot)
+ if (self->freelists[slot].objsize==UNUSED_LIST)
+ ++free;
+
+ return free;
+}
+
+etUInt16 etMemory_FreeList_nObjects(void* heap, etUInt16 slot) {
+#if DEBUG_FREE_LISTS
+ etFreeListMemory* self = (etFreeListMemory*) heap;
+ if (slot<self->nslots)
+ return self->freelists[slot].nobjects;
+#endif
+ return 0;
+}
+
+etUInt16 etMemory_FreeList_sizeObjects(void* heap, etUInt16 slot) {
+ etFreeListMemory* self = (etFreeListMemory*) heap;
+ if (slot<self->nslots)
+ return self->freelists[slot].objsize;
+ return 0;
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.h b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.h
index 3f46272cf..b5842d523 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.h
@@ -1,35 +1,35 @@
-/*******************************************************************************
- * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-#ifndef _ETMEMORY_FREE_LIST_H_
-#define _ETMEMORY_FREE_LIST_H_
-
-#include "base/etMemory.h"
-
-/**
- * initializes the free list memory management on the given heap
- *
- * \param heap pointer to the heap to be managed
- * \param size the size in bytes of the heap
- * \param nslots the number of slots to be used (should be greater or equal the number of different object sizes)
- *
- * \return the pointer to the initialized etMemory struct
- */
-
-etMemory* etMemory_FreeList_init(void* heap, etUInt32 size, etUInt16 nslots);
-
-etUInt32 etMemory_FreeList_freeHeapMem(void* heap);
-etUInt16 etMemory_FreeList_nObjects(void* heap, etUInt16 slot);
-etUInt16 etMemory_FreeList_sizeObjects(void* heap, etUInt16 slot);
-etUInt16 etMemory_FreeList_freeSlots(void* heap);
-
-#endif /* _ETMEMORY_FREE_LIST_H_ */
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef _ETMEMORY_FREE_LIST_H_
+#define _ETMEMORY_FREE_LIST_H_
+
+#include "base/etMemory.h"
+
+/**
+ * initializes the free list memory management on the given heap
+ *
+ * \param heap pointer to the heap to be managed
+ * \param size the size in bytes of the heap
+ * \param nslots the number of slots to be used (should be greater or equal the number of different object sizes)
+ *
+ * \return the pointer to the initialized etMemory struct
+ */
+
+etMemory* etMemory_FreeList_init(void* heap, etUInt32 size, etUInt16 nslots);
+
+etUInt32 etMemory_FreeList_freeHeapMem(void* heap);
+etUInt16 etMemory_FreeList_nObjects(void* heap, etUInt16 slot);
+etUInt16 etMemory_FreeList_sizeObjects(void* heap, etUInt16 slot);
+etUInt16 etMemory_FreeList_freeSlots(void* heap);
+
+#endif /* _ETMEMORY_FREE_LIST_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.c b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.c
index 418bf5867..7659bafb6 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.c
@@ -1,102 +1,102 @@
-/*******************************************************************************
- * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz (initial contribution)
- *
- *******************************************************************************/
-
-#include "base/etQueue.h"
-#include "debugging/etMSCLogger.h"
-
-void etQueue_init(etQueue* self){
- ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "init")
-
- self->first = NULL;
- self->last = NULL;
- self->highWaterMark = 0;
- self->size = 0;
-
- ET_MSC_LOGGER_SYNC_EXIT
-}
-
-
-void etQueue_push(etQueue* self, etQueueObj* obj){
- ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "push")
-
- if (self->first == NULL) {
- /*no object in queue*/
- self->first = self->last = obj;
- }
- else {
- /*at least one object in queue*/
- self->last->next = obj;
- self->last = obj;
- }
- obj->next = NULL; /*TODO: optimization: this line could be removed if we assume that all objects are initialized*/
-
- if (++self->size > self->highWaterMark)
- self->highWaterMark++;
-
- ET_MSC_LOGGER_SYNC_EXIT
-}
-
-etQueueObj* etQueue_pop(etQueue* self){
- etQueueObj* pop_msg = self->first;
-
- ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "pop")
-
- if (self->first == NULL){
- /*no message in queue*/
- ET_MSC_LOGGER_SYNC_EXIT
- return NULL;
- }
- if (self->first->next==NULL){
- /*only one message in queue*/
- self->first = self->last = NULL;
- }
- else {
- /*more than one message in queue -> set first to nex message*/
- self->first = self->first->next;
- }
-
- pop_msg->next=NULL;
- self->size--;
-
- ET_MSC_LOGGER_SYNC_EXIT
- return pop_msg;
-}
-
-etInt16 etQueue_getSize(etQueue* self) {
- ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "getSize")
- ET_MSC_LOGGER_SYNC_EXIT
- return self->size;
-}
-
-etQueueObj* etQueue_getFirst(etQueue* self){
- ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "getFirst")
- ET_MSC_LOGGER_SYNC_EXIT
- return self->first;
-}
-
-etQueueObj* etQueue_getLast(etQueue* self){
- ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "getLast")
- ET_MSC_LOGGER_SYNC_EXIT
- return self->last;
-}
-
-etBool etQueue_isNotEmpty(etQueue* self){
- ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "isNotEmpty")
- ET_MSC_LOGGER_SYNC_EXIT
- return self->last != NULL;
-}
-
-etInt16 etQueue_getHighWaterMark(etQueue* self) {
- ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "getHightWaterMark")
- ET_MSC_LOGGER_SYNC_EXIT
- return self->highWaterMark;
-}
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "base/etQueue.h"
+#include "debugging/etMSCLogger.h"
+
+void etQueue_init(etQueue* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "init")
+
+ self->first = NULL;
+ self->last = NULL;
+ self->highWaterMark = 0;
+ self->size = 0;
+
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+
+void etQueue_push(etQueue* self, etQueueObj* obj){
+ ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "push")
+
+ if (self->first == NULL) {
+ /*no object in queue*/
+ self->first = self->last = obj;
+ }
+ else {
+ /*at least one object in queue*/
+ self->last->next = obj;
+ self->last = obj;
+ }
+ obj->next = NULL; /*TODO: optimization: this line could be removed if we assume that all objects are initialized*/
+
+ if (++self->size > self->highWaterMark)
+ self->highWaterMark++;
+
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+etQueueObj* etQueue_pop(etQueue* self){
+ etQueueObj* pop_msg = self->first;
+
+ ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "pop")
+
+ if (self->first == NULL){
+ /*no message in queue*/
+ ET_MSC_LOGGER_SYNC_EXIT
+ return NULL;
+ }
+ if (self->first->next==NULL){
+ /*only one message in queue*/
+ self->first = self->last = NULL;
+ }
+ else {
+ /*more than one message in queue -> set first to nex message*/
+ self->first = self->first->next;
+ }
+
+ pop_msg->next=NULL;
+ self->size--;
+
+ ET_MSC_LOGGER_SYNC_EXIT
+ return pop_msg;
+}
+
+etInt16 etQueue_getSize(etQueue* self) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "getSize")
+ ET_MSC_LOGGER_SYNC_EXIT
+ return self->size;
+}
+
+etQueueObj* etQueue_getFirst(etQueue* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "getFirst")
+ ET_MSC_LOGGER_SYNC_EXIT
+ return self->first;
+}
+
+etQueueObj* etQueue_getLast(etQueue* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "getLast")
+ ET_MSC_LOGGER_SYNC_EXIT
+ return self->last;
+}
+
+etBool etQueue_isNotEmpty(etQueue* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "isNotEmpty")
+ ET_MSC_LOGGER_SYNC_EXIT
+ return self->last != NULL;
+}
+
+etInt16 etQueue_getHighWaterMark(etQueue* self) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etQueue", "getHightWaterMark")
+ ET_MSC_LOGGER_SYNC_EXIT
+ return self->highWaterMark;
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.h b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.h
index ab656d154..aee2780f0 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etQueue.h
@@ -1,49 +1,49 @@
-/*******************************************************************************
- * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Thomas Schuetz (initial contribution)
- *
- *******************************************************************************/
-
-#ifndef _ETQUEUE_H_
-#define _ETQUEUE_H_
-
-#include <stddef.h>
-#include "etDatatypes.h"
-
-typedef struct etQueueObj {
- struct etQueueObj* next;
-} etQueueObj;
-
-typedef struct etQueue {
- etQueueObj* first;
- etQueueObj* last;
- etInt16 highWaterMark;
- etInt16 size;
-
-} etQueue;
-
-void etQueue_init(etQueue* self);
-
-void etQueue_push(etQueue* self, etQueueObj* obj);
-
-etQueueObj* etQueue_pop(etQueue* self);
-
-etQueueObj* etQueue_getFirst(etQueue* self);
-
-etQueueObj* etQueue_getLast(etQueue* self);
-
-etBool etQueue_isNotEmpty(etQueue* self);
-
-etInt16 etQueue_getHighWaterMark(etQueue* self);
-
-etInt16 etQueue_getSize(etQueue* self);
-
-
-
-#endif /* _ETQUEUE_H_ */
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef _ETQUEUE_H_
+#define _ETQUEUE_H_
+
+#include <stddef.h>
+#include "etDatatypes.h"
+
+typedef struct etQueueObj {
+ struct etQueueObj* next;
+} etQueueObj;
+
+typedef struct etQueue {
+ etQueueObj* first;
+ etQueueObj* last;
+ etInt16 highWaterMark;
+ etInt16 size;
+
+} etQueue;
+
+void etQueue_init(etQueue* self);
+
+void etQueue_push(etQueue* self, etQueueObj* obj);
+
+etQueueObj* etQueue_pop(etQueue* self);
+
+etQueueObj* etQueue_getFirst(etQueue* self);
+
+etQueueObj* etQueue_getLast(etQueue* self);
+
+etBool etQueue_isNotEmpty(etQueue* self);
+
+etInt16 etQueue_getHighWaterMark(etQueue* self);
+
+etInt16 etQueue_getSize(etQueue* self);
+
+
+
+#endif /* _ETQUEUE_H_ */

Back to the top