[Groonga-commit] groonga/groonga at ba3aee6 [master] Add grn_cache_default_reopen()

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Apr 26 11:00:31 JST 2017


Kouhei Sutou	2017-04-26 11:00:31 +0900 (Wed, 26 Apr 2017)

  New Revision: ba3aee6c4c933d6b1826f1195beaed973d5d48da
  https://github.com/groonga/groonga/commit/ba3aee6c4c933d6b1826f1195beaed973d5d48da

  Message:
    Add grn_cache_default_reopen()

  Modified files:
    include/groonga/cache.h
    lib/cache.c

  Modified: include/groonga/cache.h (+2 -0)
===================================================================
--- include/groonga/cache.h    2017-04-25 14:59:11 +0900 (a923404)
+++ include/groonga/cache.h    2017-04-26 11:00:31 +0900 (bba7224)
@@ -36,6 +36,8 @@ GRN_API grn_rc grn_cache_close(grn_ctx *ctx, grn_cache *cache);
 GRN_API grn_rc grn_cache_current_set(grn_ctx *ctx, grn_cache *cache);
 GRN_API grn_cache *grn_cache_current_get(grn_ctx *ctx);
 
+GRN_API grn_rc grn_cache_default_reopen(void);
+
 GRN_API grn_rc grn_cache_set_max_n_entries(grn_ctx *ctx,
                                            grn_cache *cache,
                                            unsigned int n);

  Modified: lib/cache.c (+27 -0)
===================================================================
--- lib/cache.c    2017-04-25 14:59:11 +0900 (2f38995)
+++ lib/cache.c    2017-04-26 11:00:31 +0900 (38238f6)
@@ -425,6 +425,33 @@ grn_cache_init(void)
   grn_cache_current_set(ctx, grn_cache_default);
 }
 
+grn_rc
+grn_cache_default_reopen(void)
+{
+  grn_ctx *ctx = &grn_cache_ctx;
+  grn_cache *new_default;
+  grn_bool default_is_current;
+
+  GRN_API_ENTER;
+
+  new_default = grn_cache_open(ctx);
+  if (!new_default) {
+    GRN_API_RETURN(ctx->rc);
+  }
+
+  default_is_current = (grn_cache_default == grn_cache_current_get(ctx));
+  if (default_is_current) {
+    grn_cache_current_set(ctx, new_default);
+  }
+
+  if (grn_cache_default) {
+    grn_cache_close(ctx, grn_cache_default);
+  }
+  grn_cache_default = new_default;
+
+  GRN_API_RETURN(ctx->rc);
+}
+
 static void
 grn_cache_expire_entry_memory(grn_cache *cache, grn_cache_entry_memory *ce)
 {
-------------- next part --------------
HTML����������������������������...
下載 



More information about the Groonga-commit mailing list
Back to archive index