summary refs log tree commit diff stats
path: root/rod
diff options
context:
space:
mode:
Diffstat (limited to 'rod')
0 files changed, 0 insertions, 0 deletions
ame the previous revision' href='/ahoang/Nim/blame/lib/core/locks.nim?h=devel&id=5cba831c8848658d67b7a00e24d9696326b9bcc9'>^
d05df2173 ^
d560e84fc ^
dfe51d10a ^



9dd297f61 ^

244657035 ^

9dd297f61 ^
45bbecb02 ^
841d6b6aa ^
d560e84fc ^

6ca3504df ^
28de800d6 ^
6ca3504df ^

1f13e94dd ^

6ca3504df ^
d560e84fc ^
dfe51d10a ^

d560e84fc ^
6ca3504df ^
d560e84fc ^
346443d1b ^
d560e84fc ^
6ca3504df ^
d560e84fc ^
346443d1b ^
d560e84fc ^
6ca3504df ^
d560e84fc ^
dfe51d10a ^

543ec3797 ^
6ca3504df ^
d560e84fc ^
dfe51d10a ^

d560e84fc ^

6ca3504df ^
d560e84fc ^
346443d1b ^
d560e84fc ^
6ca3504df ^
801844931 ^
346443d1b ^
d560e84fc ^
6ca3504df ^
543ec3797 ^
346443d1b ^
543ec3797 ^
6ca3504df ^
543ec3797 ^
d560e84fc ^
f0341979b ^
1cc1a7faf ^
34401a363 ^

2ecdf582a ^
b07694cd9 ^
f0341979b ^



b07694cd9 ^
1f13e94dd ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

 
                                  
                                         




                                                   
                                                                   
 



                                                                            

                                                          

                                                    
 
                                
                         

    
                                                         
                                           

                                           

                        
                                           
                                

                       
 
                                             
                                                  
                 
 
                                        
                                                                
                              
 
                               
                             

                       
 
                               
                             

                       

 
                                           
                                              
                   
 
                                             
                                                                
                     
 
                                                       
                                            
                         
 
                                         
                                                     
                     
 
                                            

                                                                 
                        
            



                 
                

       
#
#
#            Nim's Runtime Library
#        (c) Copyright 2015 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## This module contains Nim's support for locks and condition vars.

#[
for js, for now we treat locks as noop's to avoid pushing `when defined(js)`
in client code that uses locks.
]#

when not compileOption("threads") and not defined(nimdoc):
  when false: # fix #12330
    {.error: "Locks requires --threads:on option.".}

const insideRLocksModule = false
include "system/syslocks"

type
  Lock* = SysLock ## Nim lock; whether this is re-entrant
                  ## or not is unspecified!
  Cond* = SysCond ## Nim condition variable

{.push stackTrace: off.}

proc initLock*(lock: var Lock) {.inline.} =
  ## Initializes the given lock.
  when not defined(js):
    initSysLock(lock)

proc deinitLock*(lock: var Lock) {.inline.} =
  ## Frees the resources associated with the lock.
  deinitSys(lock)

proc tryAcquire*(lock: var Lock): bool =
  ## Tries to acquire the given lock. Returns `true` on success.
  result = tryAcquireSys(lock)

proc acquire*(lock: var Lock) =
  ## Acquires the given lock.
  when not defined(js):
    acquireSys(lock)

proc release*(lock: var Lock) =
  ## Releases the given lock.
  when not defined(js):
    releaseSys(lock)


proc initCond*(cond: var Cond) {.inline.} =
  ## Initializes the given condition variable.
  initSysCond(cond)

proc deinitCond*(cond: var Cond) {.inline.} =
  ## Frees the resources associated with the condition variable.
  deinitSysCond(cond)

proc wait*(cond: var Cond, lock: var Lock) {.inline.} =
  ## waits on the condition variable `cond`.
  waitSysCond(cond, lock)

proc signal*(cond: var Cond) {.inline.} =
  ## sends a signal to the condition variable `cond`.
  signalSysCond(cond)

template withLock*(a: Lock, body: untyped) =
  ## Acquires the given lock, executes the statements in body and
  ## releases the lock after the statements finish executing.
  mixin acquire, release
  acquire(a)
  {.locks: [a].}:
    try:
      body
    finally:
      release(a)

{.pop.}