Add a counter to avoid multiple initialization of Groonga mecab tokenizer
This commit is contained in:
parent
6e6a4227c0
commit
38ea795bb6
@ -30,6 +30,7 @@ grn_rc grn_tokenizers_init(void);
|
|||||||
grn_rc grn_tokenizers_fin(void);
|
grn_rc grn_tokenizers_fin(void);
|
||||||
|
|
||||||
grn_rc grn_db_init_mecab_tokenizer(grn_ctx *ctx);
|
grn_rc grn_db_init_mecab_tokenizer(grn_ctx *ctx);
|
||||||
|
void grn_db_fin_mecab_tokenizer(grn_ctx *ctx);
|
||||||
grn_rc grn_db_init_builtin_tokenizers(grn_ctx *ctx);
|
grn_rc grn_db_init_builtin_tokenizers(grn_ctx *ctx);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
static unsigned int sole_mecab_init_counter = 0;
|
||||||
static mecab_t *sole_mecab = NULL;
|
static mecab_t *sole_mecab = NULL;
|
||||||
static grn_plugin_mutex *sole_mecab_mutex = NULL;
|
static grn_plugin_mutex *sole_mecab_mutex = NULL;
|
||||||
static grn_encoding sole_mecab_encoding = GRN_ENC_NONE;
|
static grn_encoding sole_mecab_encoding = GRN_ENC_NONE;
|
||||||
@ -563,6 +564,11 @@ check_mecab_dictionary_encoding(grn_ctx *ctx)
|
|||||||
grn_rc
|
grn_rc
|
||||||
GRN_PLUGIN_INIT(grn_ctx *ctx)
|
GRN_PLUGIN_INIT(grn_ctx *ctx)
|
||||||
{
|
{
|
||||||
|
++sole_mecab_init_counter;
|
||||||
|
if (sole_mecab_init_counter > 1)
|
||||||
|
{
|
||||||
|
return GRN_SUCCESS;
|
||||||
|
}
|
||||||
{
|
{
|
||||||
char env[GRN_ENV_BUFFER_SIZE];
|
char env[GRN_ENV_BUFFER_SIZE];
|
||||||
|
|
||||||
@ -636,6 +642,11 @@ GRN_PLUGIN_REGISTER(grn_ctx *ctx)
|
|||||||
grn_rc
|
grn_rc
|
||||||
GRN_PLUGIN_FIN(grn_ctx *ctx)
|
GRN_PLUGIN_FIN(grn_ctx *ctx)
|
||||||
{
|
{
|
||||||
|
--sole_mecab_init_counter;
|
||||||
|
if (sole_mecab_init_counter > 0)
|
||||||
|
{
|
||||||
|
return GRN_SUCCESS;
|
||||||
|
}
|
||||||
if (sole_mecab) {
|
if (sole_mecab) {
|
||||||
mecab_destroy(sole_mecab);
|
mecab_destroy(sole_mecab);
|
||||||
sole_mecab = NULL;
|
sole_mecab = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user