| | |
| | | } |
| | | st_.nlock_ += n; |
| | | } |
| | | void unlock() { mutex_.unlock(); } |
| | | void unlock() |
| | | { |
| | | auto old_time = last_lock_time_.load(); |
| | | if (Now() - old_time > limit_) { |
| | | } else { |
| | | if (last_lock_time_.compare_exchange_strong(old_time, Now())) { |
| | | mutex_.unlock(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | namespace |
| | |
| | | |
| | | const std::string mtx_name("test_mutex"); |
| | | const std::string int_name("test_int"); |
| | | auto mtx = shm.find_or_construct<Mutex>(mtx_name.c_str())(); |
| | | auto pi = shm.find_or_construct<int>(int_name.c_str())(100); |
| | | auto mtx = shm.FindOrCreate<Mutex>(mtx_name); |
| | | auto pi = shm.FindOrCreate<int>(int_name, 100); |
| | | |
| | | printf("mutetx "); |
| | | PrintPtr(mtx); |
| | |
| | | TLMutex mutex; |
| | | // CasMutex mutex; |
| | | auto Lock = [&]() { |
| | | for (int i = 0; i < 1000 * 100; ++i) { |
| | | for (int i = 0; i < 10; ++i) { |
| | | mutex.lock(); |
| | | mutex.unlock(); |
| | | } |