diff --git a/src/rm_tree.c b/src/rm_tree.c
index 8b2ab4de03148922aa4ce2f786511ab094b21630..bc332090ef835f75d0bfc474893f8a748f96d0fc 100644 (file)
--- a/src/rm_tree.c
+++ b/src/rm_tree.c
* @file rm_tree.c
*
* @brief
- * Resource Manager Tree Manipulation Source.
+ * Resource Manager Tree Manipulation.
*
* \par
* ============================================================================
- * @n (C) Copyright 2012-2014, Texas Instruments, Inc.
+ * @n (C) Copyright 2012-2015, Texas Instruments, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
newNode = Rm_osalMalloc(sizeof(Rm_NameServerNode));
if (newNode) {
rm_strncpy(newNode->objName, nodeCfg->objName, RM_NAME_MAX_CHARS);
- rm_strncpy(newNode->resourceName, nodeCfg->resourceName, RM_NAME_MAX_CHARS);
+ rm_strncpy(newNode->resourceName, nodeCfg->resourceName,
+ RM_NAME_MAX_CHARS);
newNode->resourceBase = nodeCfg->resourceBase;
newNode->resourceLength = nodeCfg->resourceLength;
}
-
+
return(newNode);
}
void rmNameServerNodeFree(Rm_NameServerNode *node)
{
if (node) {
- Rm_osalFree((void *)node, sizeof(Rm_NameServerNode));
+ Rm_osalFree((void *)node, sizeof(*node));
}
}
}
/* Generate the NameServer tree manipulation functions */
-RB_GENERATE(_Rm_NameServerTree, _Rm_NameServerNode, linkage, rmNameServerNodeCompare, rmNameServerNodeInv);
+RB_GENERATE(_Rm_NameServerTree, _Rm_NameServerNode, linkage,
+ rmNameServerNodeCompare, rmNameServerNodeInv);
/**********************************************************************
*************** Policy Valid Instance Tree Functions *****************
Rm_PolicyValidInstNode *newNode = NULL;
newNode = Rm_osalMalloc(sizeof(Rm_PolicyValidInstNode));
-
+
rm_strncpy(newNode->name, instName, RM_NAME_MAX_CHARS);
newNode->allocRefCount = 0;
newNode->deletePending = RM_FALSE;
-
+
return(newNode);
}
*/
void rmPolicyValidInstNodeFree(Rm_PolicyValidInstNode *node)
{
- /* TODO: Add allocation reference count check when reference count addition/subtraction
- * bugs are resolved */
+ /* TODO: Add allocation reference count check when reference count
+ * addition/subtraction bugs are resolved */
// if (node->allocRefCount == 0) {
- Rm_osalFree((void *)node, sizeof(Rm_PolicyValidInstNode));
+ Rm_osalFree((void *)node, sizeof(*node));
// }
}
* node1 name = node2 name --> return 0
* node1 name > node2 name --> return > 0
*/
-int rmPolicyValidInstNodeCompare(Rm_PolicyValidInstNode *node1, Rm_PolicyValidInstNode *node2)
+int rmPolicyValidInstNodeCompare(Rm_PolicyValidInstNode *node1,
+ Rm_PolicyValidInstNode *node2)
{
return(strncmp(node1->name, node2->name, RM_NAME_MAX_CHARS));
}
}
/* Generate the valid instance tree manipulation functions */
-RB_GENERATE(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode, linkage, rmPolicyValidInstNodeCompare, rmPolicyValidInstNodeInv);
+RB_GENERATE(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode, linkage,
+ rmPolicyValidInstNodeCompare, rmPolicyValidInstNodeInv);
/**********************************************************************
***************** Allocator Resource Tree Functions ******************
* DESCRIPTION: Creates a new resource tree node with the
* specified name resource values.
*/
-Rm_ResourceNode *rmResourceNodeNew(uint32_t resourceBase, uint32_t resourceLength)
+Rm_ResourceNode *rmResourceNodeNew(uint32_t resourceBase,
+ uint32_t resourceLength)
{
Rm_ResourceNode *newNode = NULL;
@@ -322,7 +327,7 @@ Rm_ResourceNode *rmResourceNodeNew(uint32_t resourceBase, uint32_t resourceLengt
void rmResourceNodeFree(Rm_ResourceNode *node)
{
if (node->allocationCount == 0) {
- Rm_osalFree((void *)node, sizeof(Rm_ResourceNode));
+ Rm_osalFree((void *)node, sizeof(*node));
}
}
uint32_t node2End = node2->base + node2->length - 1;
if (node1End < node2->base) {
- /* End of node1 range is less than the start of node2's range. Return a negative
- * value */
- return (-1);
+ /* End of node1 range is less than the start of node2's range. Return
+ * a negative value */
+ return(-1);
}
else if (node1->base > node2End) {
- /* Start of node1 range is after end of node2's range. Return a positive value */
- return (1);
+ /* Start of node1 range is after end of node2's range. Return a
+ * positive value */
+ return(1);
}
else {
- /* If neither of the latter conditions were satisfied there is some overlap between
- * node1 and node2. Return 0 since the application must handle this overlap. */
- return (0);
+ /* If neither of the latter conditions were satisfied there is some
+ * overlap between node1 and node2. Return 0 since the application
+ * must handle this overlap. */
+ return(0);
}
}
}
/* Generate the resource tree manipulation functions */
-RB_GENERATE(_Rm_AllocatorResourceTree, _Rm_ResourceNode, linkage, rmResourceNodeCompare, rmResourceNodeInv)
+RB_GENERATE(_Rm_AllocatorResourceTree, _Rm_ResourceNode, linkage,
+ rmResourceNodeCompare, rmResourceNodeInv);
+
+/**********************************************************************
+ ********************* Allocator Tree Functions ***********************
+ **********************************************************************/
+
+/* FUNCTION PURPOSE: Invalidates an entire allocator tree
+ ***********************************************************************
+ * DESCRIPTION: Uses the cache handling versions of the RB tree
+ * macros to walk and invalidate an entire allocator tree.
+ */
+void rmAllocatorTreeInv(Rm_AllocatorTree *treeRoot)
+{
+ Rm_AllocatorNode *node;
+
+ /* Invalidate the tree root */
+ Rm_osalBeginMemAccess((void *)treeRoot, sizeof(Rm_AllocatorTree));
+ /* Walk the tree which will invalidate each element in the tree */
+ node = RB_MIN_CACHED(_Rm_AllocatorTree, treeRoot);
+ while (node) {
+ node = RB_NEXT_CACHED(_Rm_AllocatorTree, treeRoot, node);
+ }
+}
+
+/* FUNCTION PURPOSE: Writebacks an entire allocator tree
+ ***********************************************************************
+ * DESCRIPTION: Walks the entire allocator tree writing back
+ * each element to shared memory
+ */
+void rmAllocatorTreeWb(Rm_AllocatorTree *treeRoot)
+{
+ Rm_AllocatorNode *node;
+
+ /* Writeback each element in the tree */
+ node = RB_MIN(_Rm_AllocatorTree, treeRoot);
+ do {
+ Rm_osalEndMemAccess((void *)node, sizeof(Rm_AllocatorNode));
+ node = RB_NEXT(_Rm_AllocatorTree, treeRoot, node);
+ } while (node);
+
+ /* Writeback the tree root */
+ Rm_osalEndMemAccess((void *)treeRoot, sizeof(Rm_AllocatorTree));
+}
+
+/* FUNCTION PURPOSE: Creates a new allocator node
+ ***********************************************************************
+ * DESCRIPTION: Creates a new allocator node with the
+ * specified resource name.
+ */
+Rm_AllocatorNode *rmAllocatorNodeNew(const char *resourceName)
+{
+ Rm_AllocatorNode *newNode = NULL;
+
+ newNode = Rm_osalMalloc(sizeof(Rm_AllocatorNode));
+
+ rm_strncpy(newNode->resourceName, resourceName, RM_NAME_MAX_CHARS);
+ newNode->resourceRootEntry = NULL;
+
+ return(newNode);
+}
+
+/* FUNCTION PURPOSE: Deletes an allocator node
+ ***********************************************************************
+ * DESCRIPTION: Deletes the specified allocator node.
+ */
+void rmAllocatorNodeFree(Rm_AllocatorNode *node)
+{
+ Rm_osalFree((void *)node, sizeof(*node));
+}
+
+/* FUNCTION PURPOSE: Compares two allocator nodes
+ ***********************************************************************
+ * DESCRIPTION: Returns the result of a comparison of two
+ * allocator node resource names.
+ * node1 name < node2 name --> return < 0
+ * node1 name = node2 name --> return 0
+ * node1 name > node2 name --> return > 0
+ */
+int rmAllocatorNodeCompare(Rm_AllocatorNode *node1, Rm_AllocatorNode *node2)
+{
+ return(strncmp(node1->resourceName, node2->resourceName,
+ RM_NAME_MAX_CHARS));
+}
+
+/* FUNCTION PURPOSE: Invalidates an allocator tree node
+ ***********************************************************************
+ * DESCRIPTION: Uses RM OSAL layer to invalidate the specified
+ * allocator tree node.
+ */
+void rmAllocatorNodeInv(Rm_AllocatorNode *node)
+{
+ Rm_osalBeginMemAccess((void *)node, sizeof(Rm_AllocatorNode));
+}
+/* Generate the allocator tree manipulation functions */
+RB_GENERATE(_Rm_AllocatorTree, _Rm_AllocatorNode, linkage,
+ rmAllocatorNodeCompare, rmAllocatorNodeInv);