Commit bcc430c2 authored by Kirill Smelkov's avatar Kirill Smelkov

.

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