[Groonga-commit] groonga/groonga at 1bf5216 [master] plugin: don't increment reference count for temporary use

Back to archive index

Kouhei Sutou null+****@clear*****
Sun Jun 9 19:44:04 JST 2013


Kouhei Sutou	2013-06-09 19:44:04 +0900 (Sun, 09 Jun 2013)

  New Revision: 1bf521642fd775e4562b62b51f363e4097363465
  https://github.com/groonga/groonga/commit/1bf521642fd775e4562b62b51f363e4097363465

  Message:
    plugin: don't increment reference count for temporary use
    
    Plugin registration isn't multi-thread safe. Should we add locks?

  Modified files:
    lib/plugin.c

  Modified: lib/plugin.c (+15 -4)
===================================================================
--- lib/plugin.c    2013-06-05 18:40:03 +0900 (d202517)
+++ lib/plugin.c    2013-06-09 19:44:04 +0900 (1577618)
@@ -161,6 +161,13 @@ grn_plugin_initialize(grn_ctx *ctx, grn_plugin *plugin,
   return ctx->rc;
 }
 
+static grn_id
+grn_plugin_find(grn_ctx *ctx, const char *filename, grn_plugin **plugin)
+{
+  return grn_hash_get(ctx, grn_plugins, filename, PATHLEN(filename),
+                      (void **)&plugin);
+}
+
 grn_id
 grn_plugin_open(grn_ctx *ctx, const char *filename)
 {
@@ -168,8 +175,7 @@ grn_plugin_open(grn_ctx *ctx, const char *filename)
   grn_dl dl;
   grn_plugin **plugin;
 
-  if ((id = grn_hash_get(ctx, grn_plugins, filename, PATHLEN(filename),
-                         (void **)&plugin))) {
+  if ((id = grn_plugin_find(ctx, filename, plugin))) {
     if (plugin && *plugin) {
       (*plugin)->refcount++;
     }
@@ -297,12 +303,17 @@ grn_plugin_register_by_path(grn_ctx *ctx, const char *path)
   GRN_API_ENTER;
   if (GRN_DB_P(db)) {
     grn_id id;
-    id = grn_plugin_open(ctx, path);
+    grn_bool opened = GRN_FALSE;
+    id = grn_plugin_find(ctx, path, NULL);
+    if (id == GRN_ID_NIL) {
+      id = grn_plugin_open(ctx, path);
+      opened = GRN_TRUE;
+    }
     if (id) {
       ctx->impl->plugin_path = path;
       ctx->rc = grn_plugin_call_register(ctx, id);
       ctx->impl->plugin_path = NULL;
-      if (ctx->rc) {
+      if (ctx->rc && opened) {
         grn_plugin_close(ctx, id);
       }
     }
-------------- next part --------------
HTML����������������������������...
Download 



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