[Groonga-commit] groonga/groonga at 4f4429f [master] Add request_timer API

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Apr 1 18:30:13 JST 2016


Kouhei Sutou	2016-04-01 18:30:13 +0900 (Fri, 01 Apr 2016)

  New Revision: 4f4429f98e23f426b1679a1b2beb7e10244b279c
  https://github.com/groonga/groonga/commit/4f4429f98e23f426b1679a1b2beb7e10244b279c

  Message:
    Add request_timer API

  Added files:
    lib/grn_request_timer.h
    lib/request_timer.c
  Modified files:
    include/groonga.h
    include/groonga/Makefile.am
    lib/sources.am

  Modified: include/groonga.h (+1 -0)
===================================================================
--- include/groonga.h    2016-04-01 18:03:42 +0900 (30e73d4)
+++ include/groonga.h    2016-04-01 18:30:13 +0900 (cc6dbd5)
@@ -34,6 +34,7 @@
 #include "groonga/output.h"
 #include "groonga/pat.h"
 #include "groonga/request_canceler.h"
+#include "groonga/request_timer.h"
 #include "groonga/thread.h"
 #include "groonga/type.h"
 #include "groonga/util.h"

  Modified: include/groonga/Makefile.am (+1 -0)
===================================================================
--- include/groonga/Makefile.am    2016-04-01 18:03:42 +0900 (230679b)
+++ include/groonga/Makefile.am    2016-04-01 18:30:13 +0900 (1f03d94)
@@ -17,6 +17,7 @@ groonga_include_HEADERS =			\
 	plugin.h				\
 	portability.h				\
 	request_canceler.h			\
+	request_timer.h				\
 	scorer.h				\
 	thread.h				\
 	token.h					\

  Added: lib/grn_request_timer.h (+28 -0) 100644
===================================================================
--- /dev/null
+++ lib/grn_request_timer.h    2016-04-01 18:30:13 +0900 (696687d)
@@ -0,0 +1,28 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2016 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#pragma once
+
+#include "grn.h"
+
+grn_bool grn_request_timer_init(void);
+void grn_request_timer_fin(void);
+
+#ifdef __cplusplus
+}
+#endif

  Added: lib/request_timer.c (+95 -0) 100644
===================================================================
--- /dev/null
+++ lib/request_timer.c    2016-04-01 18:30:13 +0900 (3e7ca5d)
@@ -0,0 +1,95 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2016 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "grn_ctx.h"
+#include "grn_request_timer.h"
+
+static grn_ctx grn_request_timer_ctx;
+static grn_mutex grn_request_timer_mutex;
+static grn_request_timer grn_current_request_timer = { 0 };
+
+grn_bool
+grn_request_timer_init(void)
+{
+  grn_ctx *ctx = &grn_request_timer_ctx;
+
+  grn_ctx_init(ctx, 0);
+
+  MUTEX_INIT(grn_request_timer_mutex);
+
+  return GRN_TRUE;
+}
+
+void *
+grn_request_timer_register(grn_ctx *ctx,
+                           const char *request_id,
+                           unsigned int request_id_size,
+                           double timeout)
+{
+  void *timer_id = NULL;
+
+  MUTEX_LOCK(grn_request_timer_mutex);
+  if (grn_current_request_timer.register_func) {
+    void *user_data = grn_current_request_timer.user_data;
+    timer_id = grn_current_request_timer.register_func(ctx,
+                                                       request_id,
+                                                       request_id_size,
+                                                       timeout,
+                                                       user_data);
+  }
+  MUTEX_UNLOCK(grn_request_timer_mutex);
+
+  return timer_id;
+}
+
+void
+grn_request_timer_unregister(grn_ctx *ctx, void *timer_id)
+{
+  MUTEX_LOCK(grn_request_timer_mutex);
+  if (grn_current_request_timer.unregister_func) {
+    void *user_data = grn_current_request_timer.user_data;
+    grn_current_request_timer.unregister_func(ctx, timer_id, user_data);
+  }
+  MUTEX_UNLOCK(grn_request_timer_mutex);
+}
+
+void
+grn_request_timer_set(grn_ctx *ctx, grn_request_timer *timer)
+{
+  MUTEX_LOCK(grn_request_timer_mutex);
+  if (grn_current_request_timer.fin_func) {
+    void *user_data = grn_current_request_timer.user_data;
+    grn_current_request_timer.fin_func(ctx, user_data);
+  }
+  if (timer) {
+    grn_current_request_timer = *timer;
+  } else {
+    memset(&grn_current_request_timer, 0, sizeof(grn_request_timer));
+  }
+  MUTEX_UNLOCK(grn_request_timer_mutex);
+}
+
+void
+grn_request_timer_fin(void)
+{
+  grn_ctx *ctx = &grn_request_timer_ctx;
+
+  grn_request_timer_set(ctx, NULL);
+  MUTEX_FIN(grn_request_timer_mutex);
+  grn_ctx_fin(ctx);
+}

  Modified: lib/sources.am (+2 -0)
===================================================================
--- lib/sources.am    2016-04-01 18:03:42 +0900 (99b91d4)
+++ lib/sources.am    2016-04-01 18:30:13 +0900 (6ed5afc)
@@ -56,6 +56,8 @@ libgroonga_la_SOURCES =				\
 	grn_report.h				\
 	request_canceler.c			\
 	grn_request_canceler.h			\
+	request_timer.c				\
+	grn_request_timer.h			\
 	rset.c					\
 	grn_rset.h				\
 	scanner.c				\
-------------- next part --------------
HTML����������������������������...
Télécharger 



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