diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-05-09 09:59:06 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-05-09 09:59:06 +0000 |
commit | 695901a05a1ffc75be39e367fafa66fb7be1c7a3 (patch) | |
tree | f1057bd048f1e07752dbb3f1ce4e5c65870fe95f /src/lockmanager | |
parent | a9e83be91832bfa07b33c8d865cab9f00df05b78 (diff) | |
download | gnunet-695901a05a1ffc75be39e367fafa66fb7be1c7a3.tar.gz gnunet-695901a05a1ffc75be39e367fafa66fb7be1c7a3.zip |
processing upon lock release
Diffstat (limited to 'src/lockmanager')
-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 f959a3c5e..f7c01b1af 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, | |||
228 | * @param client the client which currently owns this lock | 228 | * @param client the client which currently owns this lock |
229 | * @param domain_name the name of the locking domain | 229 | * @param domain_name the name of the locking domain |
230 | * @param lock_num the number of the lock | 230 | * @param lock_num the number of the lock |
231 | * @param tail the pointer to the tail of the global lock list | ||
232 | */ | 231 | */ |
233 | static void | 232 | static void |
234 | ll_add_lock (struct GNUNET_SERVER_Client *client, | 233 | ll_add_lock (struct GNUNET_SERVER_Client *client, |
@@ -534,6 +533,51 @@ handle_acquire (void *cls, | |||
534 | 533 | ||
535 | 534 | ||
536 | /** | 535 | /** |
536 | * This function gives the lock to the first client in the wait list of the | ||
537 | * lock. If no clients are currently waiting for this lock, the lock is | ||
538 | * destroyed. | ||
539 | * | ||
540 | * @param ll_entry the lock list entry corresponding to a lock | ||
541 | */ | ||
542 | static void | ||
543 | process_lock_release (struct LockList *ll_entry) | ||
544 | { | ||
545 | struct WaitList *wl_entry; | ||
546 | |||
547 | wl_entry = ll_entry->wait_list_head; | ||
548 | if (NULL == wl_entry) | ||
549 | { | ||
550 | ll_remove_lock (ll_entry); | ||
551 | return; | ||
552 | } | ||
553 | |||
554 | while (NULL != wl_entry) | ||
555 | { | ||
556 | ll_wl_remove_client(ll_entry, wl_entry); | ||
557 | |||
558 | if (GNUNET_NO == cl_find_client (wl_entry->client, NULL)) | ||
559 | { | ||
560 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
561 | "Removing disconnected client from wait list\n"); | ||
562 | wl_entry = ll_entry->wait_list_head; | ||
563 | continue; | ||
564 | } | ||
565 | |||
566 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
567 | "Giving lock to a client from wait list\n"); | ||
568 | ll_entry->client = wl_entry->client; | ||
569 | send_success_msg (wl_entry->client, | ||
570 | ll_entry->domain_name, | ||
571 | ll_entry->lock_num); | ||
572 | return; | ||
573 | } | ||
574 | /* We ran out of clients in the wait list -- destroy lock */ | ||
575 | ll_remove_lock (ll_entry); | ||
576 | return; | ||
577 | } | ||
578 | |||
579 | |||
580 | /** | ||
537 | * Handle for GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE | 581 | * Handle for GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE |
538 | * | 582 | * |
539 | * @param cls NULL | 583 | * @param cls NULL |
@@ -556,25 +600,21 @@ handle_release (void *cls, | |||
556 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 600 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
557 | "Received a RELEASE message on lock with num: %d, domain: %s\n", | 601 | "Received a RELEASE message on lock with num: %d, domain: %s\n", |
558 | lock_num, domain_name); | 602 | lock_num, domain_name); |
603 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
559 | if (GNUNET_YES == ll_find_lock (domain_name, lock_num, &ll_entry)) | 604 | if (GNUNET_YES == ll_find_lock (domain_name, lock_num, &ll_entry)) |
560 | { | 605 | { |
561 | if (NULL == ll_entry->wait_list_head) | 606 | if (client != ll_entry->client) |
562 | { | ||
563 | ll_remove_lock (ll_entry); | ||
564 | } | ||
565 | else | ||
566 | { | 607 | { |
567 | /* Do furthur processing on lock's wait list here */ | 608 | GNUNET_break (0); |
609 | return; | ||
568 | } | 610 | } |
611 | process_lock_release (ll_entry); | ||
569 | } | 612 | } |
570 | else | 613 | else |
571 | { | 614 | { |
572 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 615 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
573 | "\t give lock doesn't exist\n"); | 616 | "\t give lock doesn't exist\n"); |
574 | } | 617 | } |
575 | |||
576 | |||
577 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
578 | } | 618 | } |
579 | 619 | ||
580 | 620 | ||
@@ -594,19 +634,12 @@ client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client) | |||
594 | 634 | ||
595 | if (GNUNET_YES == cl_find_client (client, &cl_entry)) | 635 | if (GNUNET_YES == cl_find_client (client, &cl_entry)) |
596 | { | 636 | { |
597 | struct LockList *lock; | 637 | struct LockList *ll_entry; |
598 | 638 | ||
599 | cl_remove_client (cl_entry); | 639 | cl_remove_client (cl_entry); |
600 | while (GNUNET_YES == ll_find_lock_by_owner (client, &lock)) | 640 | while (GNUNET_YES == ll_find_lock_by_owner (client, &ll_entry)) |
601 | { | 641 | { |
602 | if (NULL == lock->wait_list_head) | 642 | process_lock_release (ll_entry); |
603 | { | ||
604 | ll_remove_lock (lock); | ||
605 | } | ||
606 | else | ||
607 | { | ||
608 | /* Do furthur processing on lock's wait list here */ | ||
609 | } | ||
610 | } | 643 | } |
611 | } | 644 | } |
612 | else GNUNET_break (0); | 645 | else GNUNET_break (0); |