File: sharedlock.yo

package info (click to toggle)
c%2B%2B-annotations 10.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,536 kB
  • ctags: 3,247
  • sloc: cpp: 19,157; makefile: 1,521; ansic: 165; sh: 128; perl: 90
file content (132 lines) | stat: -rw-r--r-- 6,513 bytes parent folder | download | duplicates (5)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
em(Shared locks) are available through the type
    hi(shared_lock)tt(std::shared_lock), after including the
    tthi(shared_mutex) header file.

An object of the type tt(std::shared_lock) controls the shared ownership of a
lockable object within a scope. Shared ownership of the lockable object may be
acquired at construction time or thereafter, and once acquired, it may be
transferred to another tt(shared_lock) object. Objects of type tt(shared_lock)
cannot be copied, but move construction and assignment is supported. 

The behavior of a program is undefined if the contained pointer to a mutex
(tt(pm)) has a non-zero value and the lockable object pointed to by tt(pm) does
not exist for the entire remaining lifetime of the tt(shared_lock)
object. The supplied mutex type must be a tt(shared_mutex) or a type having
the same characteristics.

The type tt(shared_lock) offers the following constructors, destructor and
operators:
    itemization(
    ittq(shared_lock() noexcept)
        (The default constructor creates a tt(shared_lock) which is not owned
by a thread and for which tt(pm == 0);)

    ittq(explicit shared_lock(mutex_type &mut))
        (This constructor locks the mutex, calling tt(mut.lock_shared()). The
calling thread may not already own the lock. Following the construction tt(pm
== &mut), and the lock is owned by the current thread;)

    ittq(shared_lock(mutex_type &mut, defer_lock_t) noexcept)
        (This constructor assigns tt(pm) to tt(&mut), but the calling thread 
does not own the lock;)

    ittq(shared_lock(mutex_type &mut, try_to_lock_t))
        (This constructor tries to locks the mutex, calling
tt(mut.try_lock_shared()). The calling thread may not already own the
lock. Following the construction tt(pm == &mut), and the lock may or may not
be owned by current thread, depending on the return value of
tt(try_lock_shared;))

    ittq(shared_lock(mutex_type &mut, adopt_lock_t))
        (This constructor can be called if the calling thread has shared
ownership of the mutex. Following the construction tt(pm == &mut), and the
lock is owned by the current thread;)

    ittq(shared_lock(mutex_type &mut,
                chrono::time_point<Clock, Duration> const &abs_time))
        (This constructor is a member template, where tt(Clock) and
tt(Duration) are types specifying a clock and absolute time (cf. section
ref(TIMESPEC)). It can be called if the calling thread does not already own
the mutex. It calls tt(mut.try_lock_shared_until(abs_time)). Following the
construction tt(pm == &mut), and the lock may or may not be owned by current
thread, depending on the return value of tt(try_lock_shared_until;))

    ittq(shared_lock(mutex_type &mut, 
                chrono::duration<Rep, Period> const &rel_time))
        (This constructor is a member template, where tt(Clock) and
tt(Period) are types specifying a clock and relative time (cf. section
ref(TIMESPEC)). It can be called if the calling thread does not already own
the mutex. It calls tt(mut.try_lock_shared_for(abs_time)). Following the
construction tt(pm == &mut), and the lock may or may not be owned by current
thread, depending on the return value of tt(try_lock_shared_for;))

    ittq(shared_lock(shared_lock &&tmp) noexcept)
        (The move constructor transfers the information in tt(tmp) to the
newly constructed tt(shared_lock). Following the construction tt(tmp.pm == 0)
and tt(tmp) no longer owns the lock;)

    ittq(~shared_lock())
        (If the lock is owned by the current thread, 
tt(pm->unlock_shared()) is called;)
        
    itt(shared_lock &operator=(shared_lock &&tmp) noexcept)
        (The move assignment operator calls tt(pm->unlock_shared) and then
transfers the information in tt(tmp) to the
current tt(shared_lock) object. Following this tt(tmp.pm == 0)
and tt(tmp) no longer owns the lock;)

    ithtq(operator bool)(explicit operator bool () const noexcept)
    (Returns whether or not the tt(shared_lock) object owns the lock.)
    )

The following members are provided:

    itemization(
    ithtq(lock)(void lock())
    (Calls tt(pm->lock_shared()), after which the current tread owns the
shared lock. Exceptions may be thrown from tt(lock_shared), and otherwise if
tt(pm == 0) or if the current thread already owns the lock;)

    ithtq(mutex)(mutex_type *mutex() const noexcept)
    (Returns tt(pm);)

    ithtq(release)(mutex_type *release() noexcept)
    (Returns the previous value of tt(pm), which is equal to zero after
calling this member. Also, the current object no longer owns the lock;)

    ithtq(swap)(void swap(shared_lock &other) noexcept)
    (Swaps the data members of the current and the tt(other) tt(shared_lock)
objects. There is also a free member tt(swap), a function template, swapping
two tt(shared_lock<Mutex>) objects, where tt(Mutex) represents the mutex type
for which the shared lock objects were instantiated: tt(void
swap(shared_lock<Mutex> &one, shared_lock<Mutex> &two) noexcept);)

    ithtq(try_lock)(bool try_lock())
        (Calls tt(pm->try_lock_shared()), returning this call's return value.
Exceptions may be thrown from tt(try_lock_shared), and
otherwise if tt(pm == 0) or if the current thread already owns the lock;)

    ithtq(try_lock_for)(bool try_lock_for(const chrono::duration<Rep, Period>&
rel_time))
    (A member template, where tt(Clock) and tt(Period) are types specifying a
clock and relative time (cf. section ref(TIMESPEC)). It calls
tt(mut.try_lock_shared_for(abs_time)). Following the call the lock may or may
not be owned by current thread, depending on the return value of
tt(try_lock_shared_until).  Exceptions may be thrown from
tt(try_lock_shared_for), and otherwise if tt(pm == 0) or if the current thread
already owns the lock;)

    ithtq(try_lock_until)(bool try_lock_until(const chrono::time_point<Clock,
Duration>& abs_time))
    (A member template, where tt(Clock) and tt(Duration) are types specifying
a clock and absolute time (cf. section ref(TIMESPEC)). It calls
tt(mut.try_lock_shared_until(abs_time)), returning its return value. Following
the call the lock may or may not be owned by current thread, depending on the
return value of tt(try_lock_shared_until).  Exceptions may be thrown from
tt(try_lock_shared_until), and otherwise if tt(pm == 0) or if the current
thread already owns the lock;)

    ithtq(unlock)(void unlock())
    (Unlocks the shared mutex lock, releasing its ownership. Throws an
exception if the shared mutex was not owned by the current thread.)
    )