This source file includes following definitions.
- lock
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include "../core/hp_timer.hpp"
22 #include "posix_locking.hpp"
23
24 namespace jmmcg { namespace ppd { namespace pthreads {
25
26 anon_semaphore::lock_result_type
27 anon_semaphore::lock(const timeout_type period) noexcept(false) {
28 using timer_t=hp_timer<ppd::generic_traits::api_type::posix_pthreads, heavyweight_threading>;
29
30 if (period==0) {
31 return try_lock();
32 } else if (period<lock_traits::infinite_timeout()) {
33 static const timer_t time;
34 timer_t::time_utc_t now=time.current_time();
35 now.tv_nsec+=(period%1000)*1000000;
36 now.tv_sec+=period/1000+now.tv_nsec/1000000000;
37 now.tv_nsec=now.tv_nsec%1000000000;
38 assert(now.tv_nsec>=0);
39 assert(now.tv_nsec<1000000000);
40 if (sem_timedwait(&sem, &now)==-1) {
41 switch (errno) {
42 case ETIMEDOUT: return atom_unset;
43 case EINTR: return atom_interrupted;
44 case EAGAIN: return atom_max_recurse;
45 case EINVAL:
46 default: return atom_abandoned;
47 };
48 }
49 return atom_set;
50 } else {
51 return lock();
52 }
53 }
54
55 } } }