]> rtime.felk.cvut.cz Git - ulut.git/commitdiff
Structured comment added to unique IDs pool code and some memory leak correction.
authorppisa <ppisa>
Tue, 24 Jan 2006 11:18:24 +0000 (11:18 +0000)
committerppisa <ppisa>
Tue, 24 Jan 2006 11:18:24 +0000 (11:18 +0000)
ulut/ul_evcbase.c
ulut/ul_uniqid.c
ulut/ul_uniqid.h

index 5d1eb21fc904f100d580591299312e4a60205b00..353b6e4c16b0f7b1520170492fefee505fd1de99 100644 (file)
@@ -245,7 +245,7 @@ int evc_tx_hub_init(evc_tx_hub_t *hub)
 }
 
 /**
- * evc_tx_hub_done - Initializes Event Transmition Hub
+ * evc_tx_hub_done - Finalize Event Transmition Hub
  * @hub:       pointer to the &evc_tx_hub_t type hub
  */
 void evc_tx_hub_done(evc_tx_hub_t *hub)
index 64ad4f9f0292e168e9177eda87836de51cadde4f..4b0e9f49d96b0030fceddf24f1e9e0728ee17a08 100644 (file)
@@ -49,6 +49,16 @@ GAVL_FLES_INT_IMP(ul_uniqid_pool, ul_uniqid_pool_t, ul_uniqid_pool_item_t, ul_un
        items, node, range, ul_uniqid_pool_cmp_fnc, GAVL_FANY, , , )
 
 
+/**
+ * ul_uniqid_pool_init - Initialize Unique IDs Pool
+ * @pool:      the pointer to the unique IDs pool
+ * @first:     the start of the available numeric range
+ * @last:      the end of the available numeric range
+ *
+ * Return Value: The function returns -1 if the @first>@last or if there
+ *     is not enough memory to allocate item for initial range representation.
+ *     The zero value indicates successful initialization.
+ */
 int ul_uniqid_pool_init(ul_uniqid_pool_t *pool, ul_uniqid_t first, ul_uniqid_t last)
 {
   ul_uniqid_pool_item_t *item;
@@ -71,6 +81,12 @@ int ul_uniqid_pool_init(ul_uniqid_pool_t *pool, ul_uniqid_t first, ul_uniqid_t l
   return 0;
 }
 
+/**
+ * ul_uniqid_pool_done - Finalize Unique IDs Pool
+ * @pool:      the pointer to the unique IDs pool
+ *
+ * Return Value: The zero value indicates success.
+ */
 int ul_uniqid_pool_done(ul_uniqid_pool_t *pool)
 {
   ul_uniqid_pool_item_t *item;
@@ -82,6 +98,20 @@ int ul_uniqid_pool_done(ul_uniqid_pool_t *pool)
   return 0;
 }
 
+/**
+ * ul_uniqid_pool_reserve - Reserve Range from the Unique IDs Pool
+ * @pool:      the pointer to the unique IDs pool
+ * @first:     the start value of the range
+ * @last:      the end value of the range
+ *
+ * The function checks if specified range @first..@last is free
+ * and reserves it from free pool.
+ *
+ * Return Value: The zero value indicates success. The value of -1 indicates,
+ *     that range overlaps with already reserved values or exceeds pool boundaries.
+ *     The value 1 is returned in the case, that there is not enough free memory
+ *     to represent new non-continuous ranges.
+ */
 int ul_uniqid_pool_reserve(ul_uniqid_pool_t *pool, ul_uniqid_t first, ul_uniqid_t last)
 {
   ul_uniqid_range_t range;
@@ -107,6 +137,7 @@ int ul_uniqid_pool_reserve(ul_uniqid_pool_t *pool, ul_uniqid_t first, ul_uniqid_
   if(range.first==item->range.first){
     if(range.last==item->range.last){
       ul_uniqid_pool_delete(pool, item);
+      free(item);
     }else{
       item->range.first=range.last+1;
     }
@@ -127,6 +158,18 @@ int ul_uniqid_pool_reserve(ul_uniqid_pool_t *pool, ul_uniqid_t first, ul_uniqid_
 }
 
 
+/**
+ * ul_uniqid_pool_release - Release Range Back to the Unique IDs Pool
+ * @pool:      the pointer to the unique IDs pool
+ * @first:     the start value of the range
+ * @last:      the end value of the range
+ *
+ * The range @first..@last is returned to the pool for subsequent reuse.
+ *
+ * Return Value: The zero value indicates success. The value of -1 indicates,
+ *     that range cannot be return back, because there is no free memory
+ *     to allocate space for returned range.
+ */
 int ul_uniqid_pool_release(ul_uniqid_pool_t *pool, ul_uniqid_t first, ul_uniqid_t last)
 {
   ul_uniqid_pool_item_t *post, *prev;
@@ -153,6 +196,7 @@ int ul_uniqid_pool_release(ul_uniqid_pool_t *pool, ul_uniqid_t first, ul_uniqid_
       if(post){
         post->range.first=prev->range.first;
         ul_uniqid_pool_delete(pool, prev);
+        free(prev);
       }else{
         prev->range.last=range.last;
       }
@@ -169,6 +213,18 @@ int ul_uniqid_pool_release(ul_uniqid_pool_t *pool, ul_uniqid_t first, ul_uniqid_
   return 0;
 }
 
+/**
+ * ul_uniqid_pool_alloc_one - Allocate/Generate One Unique ID from the Pool
+ * @pool:      the pointer to the unique IDs pool
+ * @ptrid:     pointer to ul_uniqid_t variable where unique ID is returned
+ *
+ * The function allocates lowest available ID from the pool and assigns
+ * its value to the space pointed by @ptrid.
+ *
+ * Return Value: The zero value indicates success. The value of -1 indicates,
+ *     that all IDs from the pool are taken. No other reason is possible,
+ *     because function does not call any memory allocation function.
+ */
 int ul_uniqid_pool_alloc_one(ul_uniqid_pool_t *pool, ul_uniqid_t *ptrid)
 {
   ul_uniqid_t id;
@@ -181,12 +237,28 @@ int ul_uniqid_pool_alloc_one(ul_uniqid_pool_t *pool, ul_uniqid_t *ptrid)
     item->range.first=id+1;
   }else{
     ul_uniqid_pool_delete(pool, item);
+    free(item);
   }
   *ptrid=id;
   
   return 0;
 }
 
+/**
+ * ul_uniqid_pool_alloc_one_after - Allocate One Unique ID Greater Than Value Specified
+ * @pool:      the pointer to the unique IDs pool
+ * @ptrid:     pointer to ul_uniqid_t variable where unique ID is returned
+ * @afterid:   the ID value after which free ID is searched
+ *
+ * The function allocates the first available ID after @afterid from the
+ * pool and assigns its value to the space pointed by @ptrid.
+ * If there is no available ID with value greater than @afterid, the first free ID
+ * from the whole pool is returned.
+ *
+ * Return Value: The zero value indicates success. The value of -1 indicates,
+ *     that all IDs from the pool are taken. No other reason is possible,
+ *     because function does not call any memory allocation function.
+ */
 int ul_uniqid_pool_alloc_one_after(ul_uniqid_pool_t *pool, ul_uniqid_t *ptrid, ul_uniqid_t afterid)
 {
   ul_uniqid_t id;
@@ -212,6 +284,7 @@ int ul_uniqid_pool_alloc_one_after(ul_uniqid_pool_t *pool, ul_uniqid_t *ptrid, u
     item->range.first=id+1;
   }else{
     ul_uniqid_pool_delete(pool, item);
+    free(item);
   }
   *ptrid=id;
   
@@ -219,6 +292,15 @@ int ul_uniqid_pool_alloc_one_after(ul_uniqid_pool_t *pool, ul_uniqid_t *ptrid, u
 }
 
 
+/**
+ * ul_uniqid_pool_free_one - Release One Previously Allocated Unique ID
+ * @pool:      the pointer to the unique IDs pool
+ * @id:                the released ID value
+ *
+ * Return Value: The zero value indicates success. The value of -1 indicates,
+ *     that ID cannot be return back, because there is no free memory
+ *     to allocate space for range representing returned ID.
+ */
 int ul_uniqid_pool_free_one(ul_uniqid_pool_t *pool, ul_uniqid_t id)
 {
   return ul_uniqid_pool_release(pool, id, id);
index b19ab025951c815aadf43b65dd059be169922bba..32de471c2f5eb1a1f264d83a8da4d099c8cc7c56 100644 (file)
 
 typedef unsigned long ul_uniqid_t;
 
-typedef struct ul_uniqid_range {
+typedef struct ul_uniqid_range_t {
   ul_uniqid_t first;
   ul_uniqid_t last;
 } ul_uniqid_range_t;
 
-typedef struct ul_uniqid_pool {
+/**
+ * struct ul_uniqid_pool_t - The Unique Identifiers Pool
+ * @items:     GAVL tree of not allocated yet ranges
+ * @range:     numeric range to allocate IDs from
+ *
+ * The unique pool provides functions to manage unique numerical IDs.
+ * The pool is first initialized by function ul_uniqid_pool_init().
+ * The available range is specified at this time. The pool can be
+ * flushed and destroyed by call ul_uniqid_pool_done().
+ *
+ * The function ul_uniqid_pool_alloc_one() returns first free ID from
+ * range. The ID is returned to the pool by function ul_uniqid_pool_free_one().
+ * There are even functions to reserve and release specific IDs range.
+ */
+typedef struct ul_uniqid_pool_t {
   gavl_fles_int_root_field_t items;
   ul_uniqid_range_t range;
 } ul_uniqid_pool_t;