[Groonga-commit] groonga/groonga at 73e759e [master] Add lock_acquire and lock_release

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jan 25 14:58:34 JST 2016


Kouhei Sutou	2016-01-25 14:58:34 +0900 (Mon, 25 Jan 2016)

  New Revision: 73e759e0983e6890ecad8b14d992a355644fd754
  https://github.com/groonga/groonga/commit/73e759e0983e6890ecad8b14d992a355644fd754

  Message:
    Add lock_acquire and lock_release

  Modified files:
    lib/grn_proc.h
    lib/proc.c
    lib/proc/proc_lock.c

  Modified: lib/grn_proc.h (+2 -0)
===================================================================
--- lib/grn_proc.h    2016-01-25 14:44:42 +0900 (fd42ea6)
+++ lib/grn_proc.h    2016-01-25 14:58:34 +0900 (7a79380)
@@ -33,7 +33,9 @@ void grn_proc_init_clearlock(grn_ctx *ctx);
 void grn_proc_init_config_get(grn_ctx *ctx);
 void grn_proc_init_config_set(grn_ctx *ctx);
 void grn_proc_init_config_delete(grn_ctx *ctx);
+void grn_proc_init_lock_acquire(grn_ctx *ctx);
 void grn_proc_init_lock_clear(grn_ctx *ctx);
+void grn_proc_init_lock_release(grn_ctx *ctx);
 void grn_proc_init_schema(grn_ctx *ctx);
 void grn_proc_init_table_create(grn_ctx *ctx);
 void grn_proc_init_table_list(grn_ctx *ctx);

  Modified: lib/proc.c (+3 -0)
===================================================================
--- lib/proc.c    2016-01-25 14:44:42 +0900 (c05e44f)
+++ lib/proc.c    2016-01-25 14:58:34 +0900 (cbd5b5b)
@@ -7103,4 +7103,7 @@ grn_db_init_builtin_query(grn_ctx *ctx)
   grn_proc_init_config_get(ctx);
   grn_proc_init_config_set(ctx);
   grn_proc_init_config_delete(ctx);
+
+  grn_proc_init_lock_acquire(ctx);
+  grn_proc_init_lock_release(ctx);
 }

  Modified: lib/proc/proc_lock.c (+93 -1)
===================================================================
--- lib/proc/proc_lock.c    2016-01-25 14:44:42 +0900 (e9cb363)
+++ lib/proc/proc_lock.c    2016-01-25 14:58:34 +0900 (75cefbd)
@@ -18,6 +18,8 @@
 
 #include "grn_proc.h"
 
+#include "grn_ctx.h"
+
 #include <groonga/plugin.h>
 
 static grn_obj *
@@ -43,7 +45,7 @@ command_lock_clear(grn_ctx *ctx,
     grn_obj_clear_lock(ctx, obj);
   } else {
     GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT,
-                     "[lock_clear] target object not found: <%.*s>",
+                     "[lock][clear] target object not found: <%.*s>",
                      target_name_len, GRN_TEXT_VALUE(target_name));
   }
 
@@ -78,3 +80,93 @@ grn_proc_init_lock_clear(grn_ctx *ctx)
                             1,
                             vars);
 }
+
+static grn_obj *
+command_lock_acquire(grn_ctx *ctx,
+                     int nargs,
+                     grn_obj **args,
+                     grn_user_data *user_data)
+{
+  int target_name_len;
+  grn_obj *target_name;
+  grn_obj *obj;
+
+  target_name = grn_plugin_proc_get_var(ctx, user_data, "target_name", -1);
+  target_name_len = GRN_TEXT_LEN(target_name);
+
+  if (target_name_len) {
+    obj = grn_ctx_get(ctx, GRN_TEXT_VALUE(target_name), target_name_len);
+  } else {
+    obj = grn_ctx_db(ctx);
+  }
+
+  if (obj) {
+    grn_obj_lock(ctx, obj, GRN_ID_NIL, grn_lock_timeout);
+  } else {
+    GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT,
+                     "[lock][acquire] target object not found: <%.*s>",
+                     target_name_len, GRN_TEXT_VALUE(target_name));
+  }
+
+  grn_ctx_output_bool(ctx, ctx->rc == GRN_SUCCESS);
+
+  return NULL;
+}
+
+void
+grn_proc_init_lock_acquire(grn_ctx *ctx)
+{
+  grn_expr_var vars[1];
+
+  grn_plugin_expr_var_init(ctx, &(vars[0]), "target_name", -1);
+  grn_plugin_command_create(ctx,
+                            "lock_acquire", -1,
+                            command_lock_acquire,
+                            1,
+                            vars);
+}
+
+static grn_obj *
+command_lock_release(grn_ctx *ctx,
+                     int nargs,
+                     grn_obj **args,
+                     grn_user_data *user_data)
+{
+  int target_name_len;
+  grn_obj *target_name;
+  grn_obj *obj;
+
+  target_name = grn_plugin_proc_get_var(ctx, user_data, "target_name", -1);
+  target_name_len = GRN_TEXT_LEN(target_name);
+
+  if (target_name_len) {
+    obj = grn_ctx_get(ctx, GRN_TEXT_VALUE(target_name), target_name_len);
+  } else {
+    obj = grn_ctx_db(ctx);
+  }
+
+  if (obj) {
+    grn_obj_unlock(ctx, obj, GRN_ID_NIL);
+  } else {
+    GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT,
+                     "[lock][release] target object not found: <%.*s>",
+                     target_name_len, GRN_TEXT_VALUE(target_name));
+  }
+
+  grn_ctx_output_bool(ctx, ctx->rc == GRN_SUCCESS);
+
+  return NULL;
+}
+
+void
+grn_proc_init_lock_release(grn_ctx *ctx)
+{
+  grn_expr_var vars[1];
+
+  grn_plugin_expr_var_init(ctx, &(vars[0]), "target_name", -1);
+  grn_plugin_command_create(ctx,
+                            "lock_release", -1,
+                            command_lock_release,
+                            1,
+                            vars);
+}
-------------- next part --------------
HTML����������������������������...
Download 



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