Navigation Menu

Skip to content

Commit

Permalink
Add lock for mrn_long_term_share related operations
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 11, 2013
1 parent 5530c74 commit 5236779
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ha_mroonga.cpp
Expand Up @@ -147,6 +147,7 @@ handlerton *mrn_hton_ptr;
HASH mrn_open_tables;
pthread_mutex_t mrn_open_tables_mutex;
HASH mrn_long_term_share;
pthread_mutex_t mrn_long_term_share_mutex;

/* internal variables */
static grn_ctx mrn_ctx;
Expand Down Expand Up @@ -1779,6 +1780,9 @@ static int mrn_init(void *p)
mrn_open_tables_get_key, 0, 0)) {
goto error_allocated_open_tables_hash_init;
}
if ((pthread_mutex_init(&mrn_long_term_share_mutex, NULL) != 0)) {
goto error_allocated_long_term_share_mutex_init;
}
if (my_hash_init(&mrn_long_term_share, system_charset_info, 32, 0, 0,
mrn_long_term_share_get_key, 0, 0)) {
goto error_allocated_long_term_share_hash_init;
Expand All @@ -1787,6 +1791,8 @@ static int mrn_init(void *p)
return 0;

error_allocated_long_term_share_hash_init:
pthread_mutex_destroy(&mrn_long_term_share_mutex);
error_allocated_long_term_share_mutex_init:
my_hash_free(&mrn_open_tables);
error_allocated_open_tables_hash_init:
pthread_mutex_destroy(&mrn_open_tables_mutex);
Expand Down Expand Up @@ -1846,6 +1852,7 @@ static int mrn_deinit(void *p)
}

my_hash_free(&mrn_long_term_share);
pthread_mutex_destroy(&mrn_long_term_share_mutex);
my_hash_free(&mrn_open_tables);
pthread_mutex_destroy(&mrn_open_tables_mutex);
my_hash_free(&mrn_allocated_thds);
Expand Down
5 changes: 5 additions & 0 deletions mrn_table.cpp
Expand Up @@ -53,6 +53,7 @@ extern "C" {
extern HASH mrn_open_tables;
extern pthread_mutex_t mrn_open_tables_mutex;
extern HASH mrn_long_term_share;
extern pthread_mutex_t mrn_long_term_share_mutex;
extern char *mrn_default_parser;
extern char *mrn_default_wrapper_engine;
extern handlerton *mrn_hton_ptr;
Expand Down Expand Up @@ -709,7 +710,10 @@ int mrn_free_share_alloc(
void mrn_free_long_term_share(MRN_LONG_TERM_SHARE *long_term_share)
{
MRN_DBUG_ENTER_FUNCTION();
{
mrn::Lock lock(&mrn_long_term_share_mutex);
my_hash_delete(&mrn_long_term_share, (uchar*) long_term_share);
}
pthread_mutex_destroy(&long_term_share->auto_inc_mutex);
my_free(long_term_share, MYF(0));
DBUG_VOID_RETURN;
Expand All @@ -723,6 +727,7 @@ MRN_LONG_TERM_SHARE *mrn_get_long_term_share(const char *table_name,
char *tmp_name;
MRN_DBUG_ENTER_FUNCTION();
DBUG_PRINT("info", ("mroonga: table_name=%s", table_name));
mrn::Lock lock(&mrn_long_term_share_mutex);
if (!(long_term_share = (MRN_LONG_TERM_SHARE*)
my_hash_search(&mrn_long_term_share, (uchar*) table_name,
table_name_length)))
Expand Down

0 comments on commit 5236779

Please sign in to comment.