diff options
author | Anand Avati <avati@redhat.com> | 2013-08-28 18:38:26 -0700 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2013-09-10 01:14:02 -0700 |
commit | a95bf63d063b3e2345936d53410b515b7198f2ac (patch) | |
tree | 213cc28a2582d2c6f0c592c9cae248011631b21c /libglusterfs | |
parent | 8eb866cc0c3ed17f7cd9ca7d6cfc3dc3de140835 (diff) |
parser: make the parser thread safe.
The volfile parser thread safe by guarding the parsing phase
in a mutex. Thread safety becomes a problem when there are multiple
glfs_t objects created by gfapi and all of them potentially parse
the respective volfiles at the same time.
Change-Id: I4376019c4956994b72397ab36e6ac3ce849797ec
BUG: 1004519
Signed-off-by: Anand Avati <avati@redhat.com>
Reviewed-on: http://review.gluster.org/5872
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/graph.y | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/libglusterfs/src/graph.y b/libglusterfs/src/graph.y index a640f2402..e0fbd169b 100644 --- a/libglusterfs/src/graph.y +++ b/libglusterfs/src/graph.y @@ -18,6 +18,7 @@ #include <sys/mman.h> #include <sys/types.h> #include <sys/wait.h> +#include <pthread.h> #define RELAX_POISONING @@ -555,6 +556,7 @@ glusterfs_graph_construct (FILE *fp) int ret = 0; glusterfs_graph_t *graph = NULL; FILE *tmp_file = NULL; + static pthread_mutex_t graph_mutex = PTHREAD_MUTEX_INITIALIZER; graph = glusterfs_graph_new (); if (!graph) @@ -580,13 +582,14 @@ glusterfs_graph_construct (FILE *fp) return NULL; } - yyin = tmp_file; - - construct = graph; - - ret = yyparse (); - - construct = NULL; + pthread_mutex_lock (&graph_mutex); + { + yyin = tmp_file; + construct = graph; + ret = yyparse (); + construct = NULL; + } + pthread_mutex_unlock (&graph_mutex); fclose (tmp_file); |