| 179 | } |
| 180 | |
| 181 | bool locker::unlock(void) |
| 182 | { |
| 183 | bool ret; |
| 184 | |
| 185 | #ifdef HAS_SPINLOCK |
| 186 | if (spinlock_) { |
| 187 | if (pthread_spin_unlock(spinlock_) == 0) { |
| 188 | ret = true; |
| 189 | } else { |
| 190 | ret = false; |
| 191 | } |
| 192 | } else |
| 193 | #endif |
| 194 | if (mutex_) { |
| 195 | if (acl_pthread_mutex_unlock(mutex_) == 0) { |
| 196 | ret = true; |
| 197 | } else { |
| 198 | ret = false; |
| 199 | } |
| 200 | } else { |
| 201 | ret = true; |
| 202 | } |
| 203 | |
| 204 | if (fHandle_ == ACL_FILE_INVALID) { |
| 205 | return ret; |
| 206 | } |
| 207 | |
| 208 | #ifdef ACL_HAS_FLOCK_LOCK |
| 209 | if (acl_myflock(fHandle_, ACL_FLOCK_STYLE_FLOCK, ACL_FLOCK_OP_NONE) == -1) { |
| 210 | #else |
| 211 | if (acl_myflock(fHandle_, ACL_FLOCK_STYLE_FCNTL, ACL_FLOCK_OP_NONE) == -1) { |
| 212 | #endif |
| 213 | return false; |
| 214 | } |
| 215 | return ret; |
| 216 | } |
| 217 | |
| 218 | ///////////////////////////////////////////////////////////////////////////// |
| 219 | |
| 220 | lock_guard::lock_guard(locker& lk) |
| 221 | : lk_(lk) |
| 222 | { |
| 223 | if (!lk_.lock()) { |
| 224 | abort(); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | lock_guard::~lock_guard(void) |
| 229 | { |
| 230 | if (!lk_.unlock()) { |
| 231 | abort(); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | } // namespace acl |