37
37
cast ,
38
38
)
39
39
40
- from readerwriterlock .rwlock import RWLockFair
41
-
42
40
from basilisp .lang import keyword as kw
43
41
from basilisp .lang import list as llist
44
42
from basilisp .lang import map as lmap
@@ -266,7 +264,7 @@ def __init__(
266
264
self ._is_bound = False
267
265
self ._tl = None
268
266
self ._meta = meta
269
- self ._lock = RWLockFair ()
267
+ self ._lock = threading . RLock ()
270
268
self ._watches = lmap .PersistentMap .empty ()
271
269
self ._validator = None
272
270
@@ -300,7 +298,7 @@ def dynamic(self) -> bool:
300
298
return self ._dynamic
301
299
302
300
def set_dynamic (self , dynamic : bool ) -> None :
303
- with self ._lock . gen_wlock () :
301
+ with self ._lock :
304
302
if dynamic == self ._dynamic :
305
303
return
306
304
@@ -328,18 +326,18 @@ def _set_root(self, newval) -> None:
328
326
329
327
@property
330
328
def root (self ):
331
- with self ._lock . gen_rlock () :
329
+ with self ._lock :
332
330
return self ._root
333
331
334
332
def bind_root (self , val ) -> None :
335
333
"""Atomically update the root binding of this Var to val."""
336
- with self ._lock . gen_wlock () :
334
+ with self ._lock :
337
335
self ._set_root (val )
338
336
339
337
def alter_root (self , f , * args ) -> None :
340
338
"""Atomically alter the root binding of this Var to the result of calling
341
339
f with the existing root value and any additional arguments."""
342
- with self ._lock . gen_wlock () :
340
+ with self ._lock :
343
341
self ._set_root (f (self ._root , * args ))
344
342
345
343
def push_bindings (self , val ):
@@ -366,7 +364,7 @@ def value(self):
366
364
367
365
For non-dynamic Vars, this will just be the root. For dynamic Vars, this will
368
366
be any thread-local binding if one is defined. Otherwise, the root value."""
369
- with self ._lock . gen_rlock () :
367
+ with self ._lock :
370
368
if self ._dynamic :
371
369
assert self ._tl is not None
372
370
if len (self ._tl .bindings ) > 0 :
@@ -378,7 +376,7 @@ def set_value(self, v) -> None:
378
376
379
377
If the Var is not dynamic, this is equivalent to binding the root value. If the
380
378
Var is dynamic, this will set the thread-local bindings for the Var."""
381
- with self ._lock . gen_wlock () :
379
+ with self ._lock :
382
380
if self ._dynamic :
383
381
assert self ._tl is not None
384
382
self ._validate (v )
@@ -585,7 +583,7 @@ def __init__(
585
583
self ._module = Maybe (module ).or_else (lambda : _new_module (name .as_python_sym ()))
586
584
587
585
self ._meta : Optional [IPersistentMap ] = None
588
- self ._lock = RWLockFair ()
586
+ self ._lock = threading . RLock ()
589
587
590
588
self ._aliases : NamespaceMap = lmap .PersistentMap .empty ()
591
589
self ._imports : ModuleMap = lmap .map (
@@ -621,36 +619,36 @@ def module(self, m: BasilispModule):
621
619
def aliases (self ) -> NamespaceMap :
622
620
"""A mapping between a symbolic alias and another Namespace. The
623
621
fully qualified name of a namespace is also an alias for itself."""
624
- with self ._lock . gen_rlock () :
622
+ with self ._lock :
625
623
return self ._aliases
626
624
627
625
@property
628
626
def imports (self ) -> ModuleMap :
629
627
"""A mapping of names to Python modules imported into the current
630
628
namespace."""
631
- with self ._lock . gen_rlock () :
629
+ with self ._lock :
632
630
return self ._imports
633
631
634
632
@property
635
633
def import_aliases (self ) -> AliasMap :
636
634
"""A mapping of a symbolic alias and a Python module name."""
637
- with self ._lock . gen_rlock () :
635
+ with self ._lock :
638
636
return self ._import_aliases
639
637
640
638
@property
641
639
def interns (self ) -> VarMap :
642
640
"""A mapping between a symbolic name and a Var. The Var may point to
643
641
code, data, or nothing, if it is unbound. Vars in `interns` are
644
642
interned in _this_ namespace."""
645
- with self ._lock . gen_rlock () :
643
+ with self ._lock :
646
644
return self ._interns
647
645
648
646
@property
649
647
def refers (self ) -> VarMap :
650
648
"""A mapping between a symbolic name and a Var. Vars in refers are
651
649
interned in another namespace and are only referred to without an
652
650
alias in this namespace."""
653
- with self ._lock . gen_rlock () :
651
+ with self ._lock :
654
652
return self ._refers
655
653
656
654
def __repr__ (self ):
@@ -681,41 +679,41 @@ def require(self, ns_name: str, *aliases: sym.Symbol) -> BasilispModule:
681
679
682
680
def add_alias (self , namespace : "Namespace" , * aliases : sym .Symbol ) -> None :
683
681
"""Add Symbol aliases for the given Namespace."""
684
- with self ._lock . gen_wlock () :
682
+ with self ._lock :
685
683
new_m = self ._aliases
686
684
for alias in aliases :
687
685
new_m = new_m .assoc (alias , namespace )
688
686
self ._aliases = new_m
689
687
690
688
def get_alias (self , alias : sym .Symbol ) -> "Optional[Namespace]" :
691
689
"""Get the Namespace aliased by Symbol or None if it does not exist."""
692
- with self ._lock . gen_rlock () :
690
+ with self ._lock :
693
691
return self ._aliases .val_at (alias , None )
694
692
695
693
def remove_alias (self , alias : sym .Symbol ) -> None :
696
694
"""Remove the Namespace aliased by Symbol. Return None."""
697
- with self ._lock . gen_wlock () :
695
+ with self ._lock :
698
696
self ._aliases = self ._aliases .dissoc (alias )
699
697
700
698
def intern (self , sym : sym .Symbol , var : Var , force : bool = False ) -> Var :
701
699
"""Intern the Var given in this namespace mapped by the given Symbol.
702
700
If the Symbol already maps to a Var, this method _will not overwrite_
703
701
the existing Var mapping unless the force keyword argument is given
704
702
and is True."""
705
- with self ._lock . gen_wlock () :
703
+ with self ._lock :
706
704
old_var = self ._interns .val_at (sym , None )
707
705
if old_var is None or force :
708
706
self ._interns = self ._interns .assoc (sym , var )
709
707
return self ._interns .val_at (sym )
710
708
711
709
def unmap (self , sym : sym .Symbol ) -> None :
712
- with self ._lock . gen_wlock () :
710
+ with self ._lock :
713
711
self ._interns = self ._interns .dissoc (sym )
714
712
715
713
def find (self , sym : sym .Symbol ) -> Optional [Var ]:
716
714
"""Find Vars mapped by the given Symbol input or None if no Vars are
717
715
mapped by that Symbol."""
718
- with self ._lock . gen_rlock () :
716
+ with self ._lock :
719
717
v = self ._interns .val_at (sym , None )
720
718
if v is None :
721
719
return self ._refers .val_at (sym , None )
@@ -724,7 +722,7 @@ def find(self, sym: sym.Symbol) -> Optional[Var]:
724
722
def add_import (self , sym : sym .Symbol , module : Module , * aliases : sym .Symbol ) -> None :
725
723
"""Add the Symbol as an imported Symbol in this Namespace. If aliases are given,
726
724
the aliases will be applied to the"""
727
- with self ._lock . gen_wlock () :
725
+ with self ._lock :
728
726
self ._imports = self ._imports .assoc (sym , module )
729
727
if aliases :
730
728
m = self ._import_aliases
@@ -738,7 +736,7 @@ def get_import(self, sym: sym.Symbol) -> Optional[BasilispModule]:
738
736
739
737
First try to resolve a module directly with the given name. If no module
740
738
can be resolved, attempt to resolve the module using import aliases."""
741
- with self ._lock . gen_rlock () :
739
+ with self ._lock :
742
740
mod = self ._imports .val_at (sym , None )
743
741
if mod is None :
744
742
alias = self ._import_aliases .get (sym , None )
@@ -750,17 +748,17 @@ def get_import(self, sym: sym.Symbol) -> Optional[BasilispModule]:
750
748
def add_refer (self , sym : sym .Symbol , var : Var ) -> None :
751
749
"""Refer var in this namespace under the name sym."""
752
750
if not var .is_private :
753
- with self ._lock . gen_wlock () :
751
+ with self ._lock :
754
752
self ._refers = self ._refers .assoc (sym , var )
755
753
756
754
def get_refer (self , sym : sym .Symbol ) -> Optional [Var ]:
757
755
"""Get the Var referred by Symbol or None if it does not exist."""
758
- with self ._lock . gen_rlock () :
756
+ with self ._lock :
759
757
return self ._refers .val_at (sym , None )
760
758
761
759
def refer_all (self , other_ns : "Namespace" ) -> None :
762
760
"""Refer all the Vars in the other namespace."""
763
- with self ._lock . gen_wlock () :
761
+ with self ._lock :
764
762
final_refers = self ._refers
765
763
for s , var in other_ns .interns .items ():
766
764
if not var .is_private :
0 commit comments