@@ -37,15 +37,15 @@ class mutex {
3737 }
3838
3939 bool valid () const noexcept {
40- static const tmp[sizeof pthread_mutex_t ] {};
40+ static const tmp[sizeof ( pthread_mutex_t ) ] {};
4141 return shm_.valid ()
4242 && (mutex_ != nullptr )
43- && (std::memcmp (tmp, mutex_, sizeof pthread_mutex_t ) != 0 );
43+ && (std::memcmp (tmp, mutex_, sizeof ( pthread_mutex_t ) ) != 0 );
4444 }
4545
4646 bool open (char const *name) noexcept {
4747 close ();
48- if (!shm_.acquire (name, sizeof pthread_mutex_t )) {
48+ if (!shm_.acquire (name, sizeof ( pthread_mutex_t ) )) {
4949 ipc::error (" fail shm.acquire: %s\n " , name);
5050 return false ;
5151 }
@@ -93,27 +93,29 @@ class mutex {
9393
9494 bool lock (std::uint64_t tm) noexcept {
9595 for (;;) {
96+ auto ts = detail::make_timespec (tm);
9697 int eno = (tm == invalid_value)
9798 ? ::pthread_mutex_lock (mutex_)
98- : ::pthread_mutex_timedlock (mutex_, detail::make_timespec (tm) );
99+ : ::pthread_mutex_timedlock (mutex_, &ts );
99100 switch (eno) {
100101 case 0 :
101102 return true ;
102103 case ETIMEDOUT:
103104 return false ;
104- case EOWNERDEAD:
105- if (shm_.ref () > 1 ) {
106- shm_.sub_ref ();
107- }
108- int eno2 = ::pthread_mutex_consistent (mutex_);
109- if (eno2 != 0 ) {
110- ipc::error (" fail pthread_mutex_lock[%d], pthread_mutex_consistent[%d]\n " , eno, eno2);
111- return false ;
112- }
113- int eno3 = ::pthread_mutex_unlock (mutex_);
114- if (eno3 != 0 ) {
115- ipc::error (" fail pthread_mutex_lock[%d], pthread_mutex_unlock[%d]\n " , eno, eno3);
116- return false ;
105+ case EOWNERDEAD: {
106+ if (shm_.ref () > 1 ) {
107+ shm_.sub_ref ();
108+ }
109+ int eno2 = ::pthread_mutex_consistent (mutex_);
110+ if (eno2 != 0 ) {
111+ ipc::error (" fail pthread_mutex_lock[%d], pthread_mutex_consistent[%d]\n " , eno, eno2);
112+ return false ;
113+ }
114+ int eno3 = ::pthread_mutex_unlock (mutex_);
115+ if (eno3 != 0 ) {
116+ ipc::error (" fail pthread_mutex_lock[%d], pthread_mutex_unlock[%d]\n " , eno, eno3);
117+ return false ;
118+ }
117119 }
118120 break ; // loop again
119121 default :
@@ -124,25 +126,27 @@ class mutex {
124126 }
125127
126128 bool try_lock () noexcept (false ) {
127- int eno = ::pthread_mutex_timedlock (mutex_, detail::make_timespec (0 ));
129+ auto ts = detail::make_timespec (0 );
130+ int eno = ::pthread_mutex_timedlock (mutex_, &ts);
128131 switch (eno) {
129132 case 0 :
130133 return true ;
131134 case ETIMEDOUT:
132135 return false ;
133- case EOWNERDEAD:
134- if (shm_.ref () > 1 ) {
135- shm_.sub_ref ();
136- }
137- int eno2 = ::pthread_mutex_consistent (mutex_);
138- if (eno2 != 0 ) {
139- ipc::error (" fail pthread_mutex_timedlock[%d], pthread_mutex_consistent[%d]\n " , eno, eno2);
140- break ;
141- }
142- int eno3 = ::pthread_mutex_unlock (mutex_);
143- if (eno3 != 0 ) {
144- ipc::error (" fail pthread_mutex_timedlock[%d], pthread_mutex_unlock[%d]\n " , eno, eno3);
145- break ;
136+ case EOWNERDEAD: {
137+ if (shm_.ref () > 1 ) {
138+ shm_.sub_ref ();
139+ }
140+ int eno2 = ::pthread_mutex_consistent (mutex_);
141+ if (eno2 != 0 ) {
142+ ipc::error (" fail pthread_mutex_timedlock[%d], pthread_mutex_consistent[%d]\n " , eno, eno2);
143+ break ;
144+ }
145+ int eno3 = ::pthread_mutex_unlock (mutex_);
146+ if (eno3 != 0 ) {
147+ ipc::error (" fail pthread_mutex_timedlock[%d], pthread_mutex_unlock[%d]\n " , eno, eno3);
148+ break ;
149+ }
146150 }
147151 break ;
148152 default :
0 commit comments