Kouhei Sutou
null+****@clear*****
Wed Mar 9 17:13:58 JST 2016
Kouhei Sutou 2016-03-09 17:13:58 +0900 (Wed, 09 Mar 2016) New Revision: 69a000639f182deef1c8fb4567d76f5e02271410 https://github.com/groonga/groonga/commit/69a000639f182deef1c8fb4567d76f5e02271410 Message: Add grn_request_canceler_cancel_all() It's useful to cancel all running requests. Modified files: include/groonga/request_canceler.h lib/request_canceler.c Modified: include/groonga/request_canceler.h (+1 -0) =================================================================== --- include/groonga/request_canceler.h 2016-03-09 17:12:52 +0900 (b1fb5c9) +++ include/groonga/request_canceler.h 2016-03-09 17:13:58 +0900 (a837b60) @@ -30,6 +30,7 @@ GRN_API void grn_request_canceler_unregister(grn_ctx *ctx, unsigned int size); GRN_API grn_bool grn_request_canceler_cancel(const char *request_id, unsigned int size); +GRN_API grn_bool grn_request_canceler_cancel_all(void); #ifdef __cplusplus } Modified: lib/request_canceler.c (+32 -1) =================================================================== --- lib/request_canceler.c 2016-03-09 17:12:52 +0900 (866292f) +++ lib/request_canceler.c 2016-03-09 17:13:58 +0900 (9b9dfde) @@ -1,6 +1,6 @@ /* -*- c-basic-offset: 2 -*- */ /* - Copyright(C) 2014 Brazil + Copyright(C) 2014-2016 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -111,6 +111,37 @@ grn_request_canceler_cancel(const char *request_id, unsigned int size) return canceled; } +grn_bool +grn_request_canceler_cancel_all(void) +{ + grn_bool canceled = GRN_FALSE; + MUTEX_LOCK(grn_the_request_canceler->mutex); + { + grn_ctx *ctx = &grn_gctx; + grn_hash *entries = grn_the_request_canceler->entries; + grn_hash_cursor *cursor; + + cursor = grn_hash_cursor_open(ctx, entries, + NULL, 0, NULL, 0, + 0, -1, 0); + if (cursor) { + while (grn_hash_cursor_next(ctx, cursor) != GRN_ID_NIL) { + void *value; + if (grn_hash_cursor_get_value(ctx, cursor, &value) > 0) { + grn_request_canceler_entry *entry = value; + if (entry->ctx->rc == GRN_SUCCESS) { + entry->ctx->rc = GRN_INTERRUPTED_FUNCTION_CALL; + canceled = GRN_TRUE; + } + } + } + grn_hash_cursor_close(ctx, cursor); + } + } + MUTEX_UNLOCK(grn_the_request_canceler->mutex); + return canceled; +} + void grn_request_canceler_fin(void) { -------------- next part -------------- HTML����������������������������...Télécharger