0 | module System.Posix.Pthreads.Struct
 1 |
 2 | import public Data.C.Ptr
 3 | import public System.Posix.Errno
 4 | import public System.Posix.Pthreads.Types
 5 |
 6 | %default total
 7 |
 8 | --------------------------------------------------------------------------------
 9 | -- PthreadT
10 | --------------------------------------------------------------------------------
11 |
12 | %foreign "C:pthread_equal, posix-idris"
13 | prim__pthread_equal : AnyPtr -> AnyPtr -> Bits8
14 |
15 | ||| Wrapper around an identifier for a POSIX thread.
16 | public export
17 | record PthreadT where
18 |   constructor P
19 |   ptr : AnyPtr
20 |
21 | export %inline
22 | Eq PthreadT where
23 |   x == y = toBool (prim__pthread_equal x.ptr y.ptr)
24 |
25 | ||| Warning: This `Show` implementation for thread IDs is for debugging only!
26 | ||| According to SUSv3, a thread ID need not be a scalar, so it should be
27 | ||| treated as an opaque type.
28 | |||
29 | ||| On many implementations (including on Linux), they are just integers, so
30 | ||| this can be useful for debugging.
31 | export %inline
32 | Show PthreadT where
33 |   show (P p) = show (believe_me {b = Bits64} p)
34 |
35 | ||| Wrapper around a `pthread_mutex_t` pointer.
36 | |||
37 | ||| Noted: While this provides additional flexibility over the type of mutex
38 | ||| we use (see `mkmutex`) and how we acquire a lock on a mutex, it is less
39 | ||| convenient to use than the garbage-collected version from
40 | ||| `System.Concurrency`.
41 | public export
42 | record SMutexT (s : Type) where
43 |   constructor M
44 |   ptr : AnyPtr
45 |
46 | public export
47 | 0 MutexT : Type
48 | MutexT = SMutexT World
49 |
50 | ||| Wrapper around a `pthread_cond_t` pointer.
51 | |||
52 | ||| Noted: While this provides additional flexibility over the type of condition
53 | ||| we use (see `mkcond`) convenient to use than the garbage-collected version from
54 | ||| `System.Concurrency`.
55 | public export
56 | record SCondT (s : Type) where
57 |   constructor C
58 |   ptr : AnyPtr
59 |
60 | public export
61 | 0 CondT : Type
62 | CondT = SCondT World
63 |