Commit f19d0b27 authored by gsamain's avatar gsamain

Make with lock statement use the recursive & upgrade capabilities of CyObject lock

parent 56673057
...@@ -8257,25 +8257,19 @@ class LockCypclassNode(StatNode): ...@@ -8257,25 +8257,19 @@ class LockCypclassNode(StatNode):
def generate_execution_code(self, code): def generate_execution_code(self, code):
self.obj.generate_evaluation_code(code) self.obj.generate_evaluation_code(code)
# We must unlock if it's a 'with unlocked' statement,
# or if we're changing lock type.
if self.was_rlocked or self.was_wlocked:
code.putln("Cy_UNLOCK(%s);" % self.obj.result())
# Then, lock accordingly # As we're relying on a recursive and upgradable lock,
if self.state == "rlocked": # we don't need to care about things like unlocking a read lock
code.putln("Cy_RLOCK(%s);" % self.obj.result()) # before taking a write lock, so the code is quite brutal here.
elif self.state == "wlocked": lock_code = "Cy_%s(%s);" % (self.state[:-2].upper(), self.obj.result())
code.putln("Cy_WLOCK(%s);" % self.obj.result()) code.putln(lock_code)
self.body.generate_execution_code(code) self.body.generate_execution_code(code)
# We must unlock if we held a lock previously # We must unlock if we held a lock previously, and relock if we unlocked.
if self.state != "unlocked": if self.state != "unlocked":
code.putln("Cy_UNLOCK(%s);" % self.obj.result()) code.putln("Cy_UNLOCK(%s);" % self.obj.result())
elif self.was_rlocked:
# Then, relock if needed
if self.was_rlocked:
code.putln("Cy_RLOCK(%s);" % self.obj.result()) code.putln("Cy_RLOCK(%s);" % self.obj.result())
elif self.was_wlocked: elif self.was_wlocked:
code.putln("Cy_WLOCK(%s);" % self.obj.result()) code.putln("Cy_WLOCK(%s);" % self.obj.result())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment