6 | module System.Concurrency
13 | %foreign "scheme:blodwen-set-thread-data"
14 | prim__setThreadData : {a : Type} -> a -> PrimIO ()
15 | %foreign "scheme:blodwen-get-thread-data"
16 | prim__getThreadData : (a : Type) -> PrimIO a
17 | %foreign "scheme,chez:get-thread-id"
18 | prim__getThreadId : PrimIO Int
23 | setThreadData : HasIO io => {a : Type} -> a -> io ()
24 | setThreadData val = primIO (prim__setThreadData val)
29 | getThreadData : HasIO io => (a : Type) -> io a
30 | getThreadData a = primIO (prim__getThreadData a)
34 | getThreadId : HasIO io => io Int
35 | getThreadId = primIO prim__getThreadId
41 | data Mutex : Type where [external]
43 | %foreign "scheme:blodwen-make-mutex"
44 | prim__makeMutex : PrimIO Mutex
45 | %foreign "scheme:blodwen-mutex-acquire"
46 | prim__mutexAcquire : Mutex -> PrimIO ()
47 | %foreign "scheme:blodwen-mutex-release"
48 | prim__mutexRelease : Mutex -> PrimIO ()
52 | makeMutex : HasIO io => io Mutex
53 | makeMutex = primIO prim__makeMutex
63 | mutexAcquire : HasIO io => Mutex -> io ()
64 | mutexAcquire m = primIO (prim__mutexAcquire m)
69 | mutexRelease : HasIO io => Mutex -> io ()
70 | mutexRelease m = primIO (prim__mutexRelease m)
76 | data Condition : Type where [external]
78 | %foreign "scheme,racket:blodwen-make-cv"
79 | "scheme,chez:blodwen-make-condition"
80 | prim__makeCondition : PrimIO Condition
81 | %foreign "scheme,racket:blodwen-cv-wait"
82 | "scheme,chez:blodwen-condition-wait"
83 | prim__conditionWait : Condition -> Mutex -> PrimIO ()
84 | %foreign "scheme,chez:blodwen-condition-wait-timeout"
86 | prim__conditionWaitTimeout : Condition -> Mutex -> Int -> PrimIO ()
87 | %foreign "scheme,racket:blodwen-cv-signal"
88 | "scheme,chez:blodwen-condition-signal"
89 | prim__conditionSignal : Condition -> PrimIO ()
90 | %foreign "scheme,racket:blodwen-cv-broadcast"
91 | "scheme,chez:blodwen-condition-broadcast"
92 | prim__conditionBroadcast : Condition -> PrimIO ()
97 | makeCondition : HasIO io => io Condition
98 | makeCondition = primIO prim__makeCondition
107 | conditionWait : HasIO io => Condition -> Mutex -> io ()
108 | conditionWait cond mutex = primIO (prim__conditionWait cond mutex)
114 | conditionWaitTimeout : HasIO io => Condition -> Mutex -> Int -> io ()
115 | conditionWaitTimeout cond mutex timeout = primIO (prim__conditionWaitTimeout cond mutex timeout)
119 | conditionSignal : HasIO io => Condition -> io ()
120 | conditionSignal c = primIO (prim__conditionSignal c)
124 | conditionBroadcast : HasIO io => Condition -> io ()
125 | conditionBroadcast c = primIO (prim__conditionBroadcast c)
131 | data Semaphore : Type where [external]
133 | %foreign "scheme:blodwen-make-semaphore"
134 | prim__makeSemaphore : Int -> PrimIO Semaphore
135 | %foreign "scheme:blodwen-semaphore-post"
136 | prim__semaphorePost : Semaphore -> PrimIO ()
137 | %foreign "scheme:blodwen-semaphore-wait"
138 | prim__semaphoreWait : Semaphore -> PrimIO ()
143 | makeSemaphore : HasIO io => Int -> io Semaphore
144 | makeSemaphore init = primIO (prim__makeSemaphore init)
148 | semaphorePost : HasIO io => Semaphore -> io ()
149 | semaphorePost sema = primIO (prim__semaphorePost sema)
154 | semaphoreWait : HasIO io => Semaphore -> io ()
155 | semaphoreWait sema = primIO (prim__semaphoreWait sema)
163 | data Barrier : Type where [external]
165 | %foreign "scheme:blodwen-make-barrier"
166 | prim__makeBarrier : Int -> PrimIO Barrier
167 | %foreign "scheme:blodwen-barrier-wait"
168 | prim__barrierWait : Barrier -> PrimIO ()
174 | makeBarrier : HasIO io => (numThreads : Int) -> io Barrier
175 | makeBarrier numThreads = primIO (prim__makeBarrier numThreads)
179 | barrierWait : HasIO io => Barrier -> io ()
180 | barrierWait barrier = primIO (prim__barrierWait barrier)
186 | data Channel : Type -> Type where [external]
188 | %foreign "scheme:blodwen-make-channel"
189 | prim__makeChannel : PrimIO (Channel a)
190 | %foreign "scheme:blodwen-channel-get"
191 | prim__channelGet : Channel a -> PrimIO a
192 | %foreign "scheme,chez:blodwen-channel-get-non-blocking"
193 | prim__channelGetNonBlocking : Channel a -> PrimIO (Maybe a)
194 | %foreign "scheme,chez:blodwen-channel-get-with-timeout"
195 | prim__channelGetWithTimeout : Channel a -> Int -> PrimIO (Maybe a)
196 | %foreign "scheme:blodwen-channel-put"
197 | prim__channelPut : Channel a -> a -> PrimIO ()
206 | makeChannel : HasIO io => io (Channel a)
207 | makeChannel = primIO prim__makeChannel
214 | channelGet : HasIO io => (chan : Channel a) -> io a
215 | channelGet chan = primIO (prim__channelGet chan)
222 | channelGetNonBlocking : HasIO io => (chan : Channel a) -> io (Maybe a)
223 | channelGetNonBlocking chan = primIO (prim__channelGetNonBlocking chan)
231 | channelGetWithTimeout : HasIO io => (chan : Channel a) -> (milliseconds : Nat) -> io (Maybe a)
232 | channelGetWithTimeout chan milliseconds = primIO (prim__channelGetWithTimeout chan (cast milliseconds))
239 | channelPut : HasIO io => (chan : Channel a) -> (val : a) -> io ()
240 | channelPut chan val = primIO (prim__channelPut chan val)