On Thu, 12 Aug 2010, Enlightenment SVN wrote:
> Log: > more variable renames, null check alloc, malloc+memset0 -> calloc, rwlocks > in structs > > Author: discomfitor > Date: 2010-08-12 23:58:43 -0700 (Thu, 12 Aug 2010) > New Revision: 51066 > > Modified: > trunk/eina/src/lib/eina_hash.c > > Modified: trunk/eina/src/lib/eina_hash.c > =================================================================== > --- trunk/eina/src/lib/eina_hash.c 2010-08-13 06:36:33 UTC (rev 51065) > +++ trunk/eina/src/lib/eina_hash.c 2010-08-13 06:58:43 UTC (rev 51066) > @@ -86,6 +86,11 @@ > > int population; > > +#ifdef EINA_RWLOCKS_ENABLED please use the other macro for that check (same below) Vincent > + pthread_rwlock_t lock; > + Eina_Bool threadsafe:1; > +#endif > + > EINA_MAGIC > }; > > @@ -102,6 +107,10 @@ > EINA_RBTREE; > Eina_Hash_Tuple tuple; > Eina_Bool begin : 1; > +#ifdef EINA_RWLOCKS_ENABLED > + pthread_rwlock_t lock; > + int threadcount; > +#endif > }; > > struct _Eina_Hash_Foreach_Data > @@ -210,7 +219,7 @@ > int key_hash, > const void *data) > { > - Eina_Hash_Element *hash_element = NULL; > + Eina_Hash_Element *new_hash_element = NULL; > Eina_Hash_Head *hash_head; > Eina_Error error = 0; > int hash_num; > @@ -227,18 +236,17 @@ > > if (!hash->buckets) > { > - hash->buckets = malloc(sizeof (Eina_Rbtree *) * hash->size); > - memset(hash->buckets, 0, sizeof (Eina_Rbtree *) * hash->size); > + hash->buckets = calloc(sizeof (Eina_Rbtree *), hash->size); > + if (!hash->buckets) goto on_error; > > hash_head = NULL; > } > else > /* Look up for head node. */ > hash_head = (Eina_Hash_Head > *)eina_rbtree_inline_lookup(hash->buckets[hash_num], > - &key_hash, 0, > - > EINA_RBTREE_CMP_KEY_CB( > - > _eina_hash_hash_rbtree_cmp_hash), > - NULL); > + &key_hash, 0, > + > EINA_RBTREE_CMP_KEY_CB(_eina_hash_hash_rbtree_cmp_hash), > + NULL); > > if (!hash_head) > { > @@ -255,36 +263,36 @@ > EINA_RBTREE_CMP_NODE_CB( > _eina_hash_hash_rbtree_cmp_node), > NULL); > > - hash_element = (Eina_Hash_Element *)(hash_head + 1); > - hash_element->begin = EINA_TRUE; > + new_hash_element = (Eina_Hash_Element *)(hash_head + 1); > + new_hash_element->begin = EINA_TRUE; > } > > - if (!hash_element) > + if (!new_hash_element) > { > /* > Alloc every needed things > (No more lookup as we expect to support more than one item for one > key). > */ > - hash_element = malloc(sizeof (Eina_Hash_Element) + alloc_length); > - if (!hash_element) > + new_hash_element = malloc(sizeof (Eina_Hash_Element) + alloc_length); > + if (!new_hash_element) > goto on_error; > > - hash_element->begin = EINA_FALSE; > + new_hash_element->begin = EINA_FALSE; > } > > /* Setup the element */ > - hash_element->tuple.key_length = key_length; > - hash_element->tuple.data = (void *)data; > + new_hash_element->tuple.key_length = key_length; > + new_hash_element->tuple.data = (void *)data; > if (alloc_length > 0) > { > - hash_element->tuple.key = (char *)(hash_element + 1); > - memcpy((char *)hash_element->tuple.key, key, alloc_length); > + new_hash_element->tuple.key = (char *)(new_hash_element + 1); > + memcpy((char *)new_hash_element->tuple.key, key, alloc_length); > } > else > - hash_element->tuple.key = key; > + new_hash_element->tuple.key = key; > > /* add the new element to the hash. */ > - hash_head->head = eina_rbtree_inline_insert(hash_head->head, > EINA_RBTREE_GET(hash_element), > + hash_head->head = eina_rbtree_inline_insert(hash_head->head, > EINA_RBTREE_GET(new_hash_element), > EINA_RBTREE_CMP_NODE_CB( > _eina_hash_key_rbtree_cmp_node), > (const void *)hash->key_cmp_cb); > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by > > Make an app they can't live without > Enter the BlackBerry Developer Challenge > http://p.sf.net/sfu/RIM-dev2dev > _______________________________________________ > enlightenment-svn mailing list > enlightenment-...@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/enlightenment-svn > > ------------------------------------------------------------------------------ This SF.net email is sponsored by Make an app they can't live without Enter the BlackBerry Developer Challenge http://p.sf.net/sfu/RIM-dev2dev _______________________________________________ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel