expr_parser: fix concurrent use issues
Change-Id: Ic9ef5d42f4348ada5c418a36118660e79a1a689b Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
5aaf5f1c6f
commit
99c0f64b34
1 changed files with 10 additions and 2 deletions
|
@ -17,6 +17,7 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import copy
|
import copy
|
||||||
|
import threading
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import ply.lex as lex
|
import ply.lex as lex
|
||||||
|
@ -204,14 +205,21 @@ def ast_expr(ast, env):
|
||||||
elif ast[0] == "exists":
|
elif ast[0] == "exists":
|
||||||
return True if ast_sym(ast[1], env) else False
|
return True if ast_sym(ast[1], env) else False
|
||||||
|
|
||||||
|
mutex = threading.Lock()
|
||||||
|
|
||||||
def parse(expr_text, env):
|
def parse(expr_text, env):
|
||||||
"""Given a text representation of an expression in our language,
|
"""Given a text representation of an expression in our language,
|
||||||
use the provided environment to determine whether the expression
|
use the provided environment to determine whether the expression
|
||||||
is true or false"""
|
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
|
# Just some test code
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue