diff options
author | harsha <harsha@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-05-09 09:59:06 +0000 |
---|---|---|
committer | harsha <harsha@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-05-09 09:59:06 +0000 |
commit | b76e47cd62dc8d9fb678e9fa2cc181829a5d8b58 (patch) | |
tree | f1057bd048f1e07752dbb3f1ce4e5c65870fe95f | |
parent | dcd9bcc7e03669d72d4eb9dc9e2b2d31a50434e4 (diff) |
processing upon lock release
git-svn-id: https://gnunet.org/svn/gnunet@21369 140774ce-b5e7-0310-ab8b-a85725594a96
-rw-r--r-- | src/lockmanager/gnunet-service-lockmanager.c | 73 |
1 files changed, 53 insertions, 20 deletions
diff --git a/src/lockmanager/gnunet-service-lockmanager.c b/src/lockmanager/gnunet-service-lockmanager.c index f959a3c5e9..f7c01b1afa 100644 --- a/src/lockmanager/gnunet-service-lockmanager.c +++ b/src/lockmanager/gnunet-service-lockmanager.c @@ -228,7 +228,6 @@ ll_find_lock_by_owner (const struct GNUNET_SERVER_Client *client, * @param client the client which currently owns this lock * @param domain_name the name of the locking domain * @param lock_num the number of the lock - * @param tail the pointer to the tail of the global lock list */ static void ll_add_lock (struct GNUNET_SERVER_Client *client, @@ -534,6 +533,51 @@ handle_acquire (void *cls, /** + * This function gives the lock to the first client in the wait list of the + * lock. If no clients are currently waiting for this lock, the lock is + * destroyed. + * + * @param ll_entry the lock list entry corresponding to a lock + */ +static void +process_lock_release (struct LockList *ll_entry) +{ + struct WaitList *wl_entry; + + wl_entry = ll_entry->wait_list_head; + if (NULL == wl_entry) + { + ll_remove_lock (ll_entry); + return; + } + + while (NULL != wl_entry) + { + ll_wl_remove_client(ll_entry, wl_entry); + + if (GNUNET_NO == cl_find_client (wl_entry->client, NULL)) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Removing disconnected client from wait list\n"); + wl_entry = ll_entry->wait_list_head; + continue; + } + + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Giving lock to a client from wait list\n"); + ll_entry->client = wl_entry->client; + send_success_msg (wl_entry->client, + ll_entry->domain_name, + ll_entry->lock_num); + return; + } + /* We ran out of clients in the wait list -- destroy lock */ + ll_remove_lock (ll_entry); + return; +} + + +/** * Handle for GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE * * @param cls NULL @@ -556,25 +600,21 @@ handle_release (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a RELEASE message on lock with num: %d, domain: %s\n", lock_num, domain_name); + GNUNET_SERVER_receive_done (client, GNUNET_OK); if (GNUNET_YES == ll_find_lock (domain_name, lock_num, &ll_entry)) { - if (NULL == ll_entry->wait_list_head) - { - ll_remove_lock (ll_entry); - } - else + if (client != ll_entry->client) { - /* Do furthur processing on lock's wait list here */ + GNUNET_break (0); + return; } + process_lock_release (ll_entry); } else { LOG (GNUNET_ERROR_TYPE_DEBUG, "\t give lock doesn't exist\n"); } - - - GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -594,19 +634,12 @@ client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client) if (GNUNET_YES == cl_find_client (client, &cl_entry)) { - struct LockList *lock; + struct LockList *ll_entry; cl_remove_client (cl_entry); - while (GNUNET_YES == ll_find_lock_by_owner (client, &lock)) + while (GNUNET_YES == ll_find_lock_by_owner (client, &ll_entry)) { - if (NULL == lock->wait_list_head) - { - ll_remove_lock (lock); - } - else - { - /* Do furthur processing on lock's wait list here */ - } + process_lock_release (ll_entry); } } else GNUNET_break (0); |