From 4b1be5f17f2f9132d3b6e44d0f438af49c51b090 Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Mon, 14 May 2012 13:32:13 +0000 Subject: removed local function --- src/lockmanager/lockmanager_api.c | 68 ++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 15 deletions(-) (limited to 'src/lockmanager') diff --git a/src/lockmanager/lockmanager_api.c b/src/lockmanager/lockmanager_api.c index a6757d538..661064455 100644 --- a/src/lockmanager/lockmanager_api.c +++ b/src/lockmanager/lockmanager_api.c @@ -101,6 +101,28 @@ struct GNUNET_LOCKMANAGER_LockingRequest }; +/** + * Structure for matching a lock + */ +struct LockMatch +{ + /** + * The matched LockingRequest entry; Should be NULL if no entry is found + */ + struct GNUNET_LOCKMANAGER_LockingRequest *matched_entry; + + /** + * The locking domain name of the lock + */ + const char *domain; + + /** + * The lock number + */ + uint32_t lock; +}; + + /** * Get the key for the given lock in the 'lock_map'. * @@ -123,6 +145,31 @@ get_key (const char *domain_name, } +/** + * Hashmap iterator for matching a lock + * + * @param cls the LockMatch structure + * @param key current key code + * @param value value in the hash map (struct GNUNET_LOCKMANAGER_LockingRequest) + * @return GNUNET_YES if we should continue to + * iterate, + * GNUNET_NO if not. + */ +static int +match_iterator (void *cls, const GNUNET_HashCode *key, void *value) +{ + struct LockMatch *match = cls; + struct GNUNET_LOCKMANAGER_LockingRequest *lr = value; + + if ( (match->lock == lr->lock) && (0 == strcmp (match->domain, lr->domain)) ) + { + match->matched_entry = lr; + return GNUNET_NO; + } + return GNUNET_YES; +} + + /** * Function to find a LockingRequest associated with the given domain and lock * attributes in the map @@ -138,27 +185,18 @@ hashmap_find_lockingrequest (const struct GNUNET_CONTAINER_MultiHashMap *map, const char *domain, uint32_t lock) { - struct GNUNET_LOCKMANAGER_LockingRequest *lr; struct GNUNET_HashCode hash; - int match_found; + struct LockMatch lock_match; - int match_iterator (void *cls, const GNUNET_HashCode *key, void *value) - { - lr = value; - if ( (lock == lr->lock) && (0 == strcmp (domain, lr->domain)) ) - { - match_found = GNUNET_YES; - return GNUNET_NO; - } - return GNUNET_YES; - } + lock_match.matched_entry = NULL; + lock_match.domain = domain; + lock_match.lock = lock; get_key (domain, lock, &hash); - match_found = GNUNET_NO; GNUNET_CONTAINER_multihashmap_get_multiple (map, &hash, &match_iterator, - NULL); - return (GNUNET_YES == match_found) ? lr : NULL; + &lock_match); + return lock_match.matched_entry; } -- cgit v1.2.3