Add uri "/test_lock" and "/test_unlock" for swift so users can test zk_mutex from web browser.
Signed-off-by: Robin Dong <san...@taobao.com> --- sheep/http/swift.c | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) diff --git a/sheep/http/swift.c b/sheep/http/swift.c index 7b3354a..c82b18e 100644 --- a/sheep/http/swift.c +++ b/sheep/http/swift.c @@ -11,6 +11,10 @@ #include "http.h" #include "kv.h" +#include "lock.h" + +#define TEST_MUTEX_ID 2013 +static struct zk_mutex test_mutex; static void make_bucket_path(char *bucket, size_t size, const char *account, const char *container) @@ -166,6 +170,10 @@ static void swift_delete_object(struct http_request *req, const char *account, static int swift_init(const char *option) { + if (zk_init_mutex(&test_mutex, TEST_MUTEX_ID)) { + sd_err("Failed to init mutex %u", TEST_MUTEX_ID); + return -1; + } return 0; } @@ -192,6 +200,14 @@ static void swift_handle_request(struct http_request *req, sd_info("%s", str_http_req(req)); + if (!strcmp("/test_lock", req->uri)) { + zk_lock_mutex(&test_mutex); + sd_debug("--- lock ---"); + } else if (!strcmp("/test_unlock", req->uri)) { + zk_unlock_mutex(&test_mutex); + sd_debug("--- unlock ---"); + } + if (account == NULL) { sd_info("invalid uri: %s", req->uri); http_response_header(req, NOT_FOUND); -- 1.7.1 -- sheepdog mailing list sheepdog@lists.wpkg.org http://lists.wpkg.org/mailman/listinfo/sheepdog