| 412 | } |
| 413 | |
| 414 | void lock() |
| 415 | { |
| 416 | for(;;) |
| 417 | { |
| 418 | state_data old_state=state; |
| 419 | for(;;) |
| 420 | { |
| 421 | state_data new_state=old_state; |
| 422 | if(new_state.shared_count || new_state.exclusive) |
| 423 | { |
| 424 | ++new_state.exclusive_waiting; |
| 425 | if(!new_state.exclusive_waiting) |
| 426 | { |
| 427 | boost::throw_exception(boost::lock_error()); |
| 428 | } |
| 429 | |
| 430 | new_state.exclusive_waiting_blocked=true; |
| 431 | } |
| 432 | else |
| 433 | { |
| 434 | new_state.exclusive=true; |
| 435 | } |
| 436 | |
| 437 | state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state); |
| 438 | if(current_state==old_state) |
| 439 | { |
| 440 | break; |
| 441 | } |
| 442 | old_state=current_state; |
| 443 | } |
| 444 | |
| 445 | if(!old_state.shared_count && !old_state.exclusive) |
| 446 | { |
| 447 | return; |
| 448 | } |
| 449 | |
| 450 | #ifndef UNDER_CE |
| 451 | const bool wait_all = true; |
| 452 | #else |
| 453 | const bool wait_all = false; |
| 454 | #endif |
| 455 | BOOST_VERIFY(winapi::WaitForMultipleObjectsEx(2,semaphores,wait_all,::boost::detail::win32::infinite,0)<2); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | private: |
| 460 | template <typename Clock, typename Timepoint, typename Duration> |
nothing calls this directly
no test coverage detected