File: semaphore.pxd

package info (click to toggle)
cython 3.1.6%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,932 kB
  • sloc: python: 92,172; ansic: 19,275; cpp: 1,407; xml: 1,031; javascript: 511; makefile: 373; sh: 223; sed: 11
file content (44 lines) | stat: -rw-r--r-- 1,578 bytes parent folder | download
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
from libcpp cimport bool

cdef extern from "<semaphore>" namespace "std" nogil:
    # Notes on templating:
    # Cython doesn't currently support non-class template types so it's
    # declared here as a class template.
    # counting_semaphore has a default max value anyway, so you typically
    # don't need to use the templates. If you do though, then there's a
    # few tricks - e.g. you can define a class with a cname of "3" for
    # example.

    # Note on thread-safety:
    # You should use these classes without the GIL. It's very easy
    # to deadlock with the GIL, and we're assuming that anyone going
    # low enough level to be using semaphores doesn't want the overhead
    # of Cython handling GIL safety.

    cdef cppclass counting_semaphore[LeastMaxValue=*]:
        counting_semaphore(ptrdiff_t desired)

        void release() except+
        void release(ptrdiff_t update) except+
        void acquire() except+
        bool try_acquire()

        # unfortunately, we don't currently define chrono types
        bool try_acquire_for[T](T duration) except+
        bool try_acquire_until[T](T timepoint) except+

        ptrdiff_t max()

    cdef cppclass binary_semaphore:
        binary_semaphore(ptrdiff_t desired)

        void release() except+
        void release(ptrdiff_t update) except+
        void acquire() except+
        bool try_acquire()

        # unfortunately, we don't currently define chrono types
        bool try_acquire_for[T](T timepoint) except+
        bool try_acquire_until[T](T duration) except+

        ptrdiff_t max()