Commit 40dfaecb authored by Jeremy Hylton's avatar Jeremy Hylton

Small but important correction to condition variable protocol!

After setting self._transaction, release the lock.  Then reacquire it
before the notify().  The wait() call is sufficient to block the other
threads; holding the lock is not necessary.

As a result, it doesn't matter if the same thread calls tpc_begin()
and tpc_abort() for a given transaction.  So remove assertion.
parent 6fac3113
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Network ZODB storage client """Network ZODB storage client
$Id: ClientStorage.py,v 1.43 2002/08/14 16:22:23 jeremy Exp $ $Id: ClientStorage.py,v 1.44 2002/08/14 19:46:28 jeremy Exp $
""" """
import cPickle import cPickle
...@@ -63,13 +63,6 @@ class DisconnectedServerStub: ...@@ -63,13 +63,6 @@ class DisconnectedServerStub:
disconnected_stub = DisconnectedServerStub() disconnected_stub = DisconnectedServerStub()
import thread
def check_thread_id(txn):
if txn._id is None: # We can't tell what thread created this
return 1
return txn._id == thread.get_ident()
class ClientStorage: class ClientStorage:
def __init__(self, addr, storage='1', cache_size=20000000, def __init__(self, addr, storage='1', cache_size=20000000,
...@@ -333,13 +326,13 @@ class ClientStorage: ...@@ -333,13 +326,13 @@ class ClientStorage:
def tpc_abort(self, transaction): def tpc_abort(self, transaction):
if transaction is not self._transaction: if transaction is not self._transaction:
return return
assert check_thread_id(transaction)
try: try:
self._server.tpc_abort(self._serial) self._server.tpc_abort(self._serial)
self._tbuf.clear() self._tbuf.clear()
self._seriald.clear() self._seriald.clear()
del self._serials[:] del self._serials[:]
finally: finally:
self.tpc_cond.acquire()
self._transaction = None self._transaction = None
self.tpc_cond.notify() self.tpc_cond.notify()
self.tpc_cond.release() self.tpc_cond.release()
...@@ -358,6 +351,7 @@ class ClientStorage: ...@@ -358,6 +351,7 @@ class ClientStorage:
self.tpc_cond.release() self.tpc_cond.release()
return return
self.tpc_cond.wait() self.tpc_cond.wait()
self.tpc_cond.release()
if self._server is None: if self._server is None:
self.tpc_cond.release() self.tpc_cond.release()
...@@ -393,7 +387,6 @@ class ClientStorage: ...@@ -393,7 +387,6 @@ class ClientStorage:
def tpc_finish(self, transaction, f=None): def tpc_finish(self, transaction, f=None):
if transaction is not self._transaction: if transaction is not self._transaction:
return return
assert check_thread_id(transaction)
try: try:
if f is not None: if f is not None:
f() f()
...@@ -405,6 +398,7 @@ class ClientStorage: ...@@ -405,6 +398,7 @@ class ClientStorage:
self._update_cache() self._update_cache()
finally: finally:
self.tpc_cond.acquire()
self._transaction = None self._transaction = None
self.tpc_cond.notify() self.tpc_cond.notify()
self.tpc_cond.release() self.tpc_cond.release()
......
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