From a95bf63d063b3e2345936d53410b515b7198f2ac Mon Sep 17 00:00:00 2001 From: Anand Avati Date: Wed, 28 Aug 2013 18:38:26 -0700 Subject: 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 Reviewed-on: http://review.gluster.org/5872 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- libglusterfs/src/graph.y | 17 ++++++++++------- 1 file 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 #include #include +#include #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); -- cgit