expr_parser: fix concurrent use issues
Change-Id: Ic9ef5d42f4348ada5c418a36118660e79a1a689b
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
diff --git a/scripts/expr_parser.py b/scripts/expr_parser.py
index a9bd4d7..91aaa55 100644
--- a/scripts/expr_parser.py
+++ b/scripts/expr_parser.py
@@ -17,6 +17,7 @@
import sys
import os
import copy
+import threading
try:
import ply.lex as lex
@@ -204,14 +205,21 @@
elif ast[0] == "exists":
return True if ast_sym(ast[1], env) else False
+mutex = threading.Lock()
def parse(expr_text, env):
"""Given a text representation of an expression in our language,
use the provided environment to determine whether the expression
is true or false"""
- ast = parser.parse(expr_text)
- return ast_expr(ast, env)
+ # Like it's C counterpart, state machine is not thread-safe
+ mutex.acquire()
+ try:
+ ast = parser.parse(expr_text)
+ finally:
+ mutex.release()
+
+ return ast_expr(ast, env)
# Just some test code
if __name__ == "__main__":