Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid accessing a trie node outside of the critical region. #50

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/grib_itrie.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,9 @@ int grib_itrie_get_id(grib_itrie* t, const char* key)
t = t->next[mapping[(int)*k++]];

if (t != NULL && t->id != -1) {
int id = t->id;
GRIB_MUTEX_UNLOCK(&mutex);
return t->id;
return id;
}
else {
int ret = grib_itrie_insert(last, key);
Expand Down Expand Up @@ -401,11 +402,12 @@ int grib_itrie_insert(grib_itrie* t, const char* key)
Assert(*(t->count) < MAX_NUM_CONCEPTS);
}

int id = t->id;
GRIB_MUTEX_UNLOCK(&mutex);

/*printf("grib_itrie_get_id: %s -> %d\n",key,t->id);*/

return t->id;
return id;
}

int grib_itrie_get_size(grib_itrie* t)
Expand Down
6 changes: 4 additions & 2 deletions src/grib_itrie_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,12 @@ static int grib_hash_keys_insert(grib_itrie* t, const char* key)
Assert(*(t->count) + TOTAL_KEYWORDS < ACCESSORS_ARRAY_SIZE);
}

int id = t->id;
GRIB_MUTEX_UNLOCK(&mutex);

/*printf("grib_hash_keys_get_id: %s -> %d\n",key,t->id);*/

return t->id;
return id;
}

int grib_hash_keys_get_id(grib_itrie* t, const char* key)
Expand All @@ -403,8 +404,9 @@ int grib_hash_keys_get_id(grib_itrie* t, const char* key)
t = t->next[mapping[(int)*k++]];

if (t != NULL && t->id != -1) {
int id = t->id;
GRIB_MUTEX_UNLOCK(&mutex);
return t->id + TOTAL_KEYWORDS + 1;
return id + TOTAL_KEYWORDS + 1;
}
else {
int ret = grib_hash_keys_insert(last, key);
Expand Down
6 changes: 4 additions & 2 deletions src/grib_trie.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,11 @@ void* grib_trie_get(grib_trie* t, const char* key)
t = t->next[mapping[(int)*k++]];
}

if (*k == 0 && t != NULL && t->data != NULL) {
if( t ) {
/* t!=NULL implies *k==0 */
void * saved = t->data;
GRIB_MUTEX_UNLOCK(&mutex);
return t->data;
return saved;
}
GRIB_MUTEX_UNLOCK(&mutex);
return NULL;
Expand Down
3 changes: 2 additions & 1 deletion src/grib_trie_with_rank.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,9 @@ int grib_trie_with_rank_insert(grib_trie_with_rank* t, const char* key, void* da
t->objs = grib_oarray_new(t->context, 100, 1000);
grib_oarray_push(t->context, t->objs, data);
/* grib_trie_with_rank_insert_in_list(t,data); */
size_t n = t->objs->n;
GRIB_MUTEX_UNLOCK(&mutex);
return t->objs->n; /* grib_oarray_used_size(t->objs) */
return n; /* grib_oarray_used_size(t->objs) */
}

/*
Expand Down