Commit bcc430c2 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 686691ee
......@@ -23,38 +23,45 @@ from time import sleep
from wendelin.bigfile.tests.test_basic import bord_py3
from six.moves import _thread
from golang import select, default
from golang import chan, select
from golang import context, sync
# Notify channel for
# - one thread to .wait('condition'), until
# - other thread does .tell('condition')
# - one thread to .wait('condition') for
# - other thread to .tell('condition')
class NotifyChannel:
def __init__(self):
self.state = None
self._ch = chan()
def tell(self, ctx, condition):
#print >>sys.stderr, ' tell %s\tthread_id: %s\n' \
# % (condition, _thread.get_ident()),
# wait until other thread reads previous tell
while self.state is not None:
if ready(ctx.done()):
_, _rx = select(
ctx.done().recv, # 0
(self._ch.send, condition), # 1
)
if _ == 0:
raise ctx.err()
pass
self.state = condition
#print >>sys.stderr, ' told %s\tthread_id: %s\n' \
# % (condition, _thread.get_ident()),
def wait(self, ctx, condition):
#print >>sys.stderr, ' wait %s\tthread_id: %s\n' \
# % (condition, _thread.get_ident()),
while self.state != condition:
if ready(ctx.done()):
_, _rx = select(
ctx.done().recv, # 0
self._ch.recv, # 1
)
if _ == 0:
raise ctx.err()
pass
got = _rx
if got != condition:
raise RuntimeError('expected %s; got %s' % (condition, got))
#print >>sys.stderr, ' have %s\tthread_id: %s\n' \
# % (condition, _thread.get_ident()),
self.state = None
......@@ -128,10 +135,12 @@ def test_thread_lock_vs_virtmem_lock():
m[0] # calls ZLockBigFile.loadblk()
tell, wait = c12.tell, c21.wait
wait(ctx, 'T2-Z-released')
wait(ctx, 'T2-Z-released: 0')
m[0] = bord_py3(b'1') # make page dirty
fh.dirty_writeout(WRITEOUT_STORE) # calls ZLockBigFile.storeblk()
wait(ctx, 'T2-Z-released: 1')
def T2(ctx):
tell, wait = c21.tell, c12.wait
......@@ -146,7 +155,7 @@ def test_thread_lock_vs_virtmem_lock():
fh2.invalidate_page(0) # NOTE invalidating page _not_ of fh
Z.release()
tell(ctx, 'T2-Z-released')
tell(ctx, 'T2-Z-released: %d' % _)
wg = sync.WorkGroup(context.background())
wg.go(T1)
......@@ -289,16 +298,3 @@ def test_thread_load_vs_invalidate():
wg.go(T1)
wg.go(T2)
wg.wait()
# ---- misc ----
def ready(ch):
_, _rx = select(
default, # 0
ch.recv, # 1
)
if _ == 0:
return False
return True
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