Carl Yeksigian | 7cb7fc8 | 2013-06-07 07:33:01 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
Konrad Grochowski | 9be4e68 | 2013-06-22 22:03:31 +0200 | [diff] [blame] | 20 | #include <thrift/thrift-config.h> |
| 21 | |
Roger Meier | 4285ba2 | 2013-06-10 21:17:23 +0200 | [diff] [blame] | 22 | #include <thrift/concurrency/Mutex.h> |
| 23 | #include <thrift/concurrency/Util.h> |
Carl Yeksigian | 7cb7fc8 | 2013-06-07 07:33:01 -0400 | [diff] [blame] | 24 | |
| 25 | #include <cassert> |
| 26 | #include <chrono> |
| 27 | #include <mutex> |
| 28 | |
| 29 | namespace apache { namespace thrift { namespace concurrency { |
| 30 | |
| 31 | /** |
| 32 | * Implementation of Mutex class using C++11 std::timed_mutex |
| 33 | * |
| 34 | * @version $Id:$ |
| 35 | */ |
| 36 | class Mutex::impl : public std::timed_mutex { |
| 37 | }; |
| 38 | |
| 39 | Mutex::Mutex(Initializer init) : impl_(new Mutex::impl()) {} |
| 40 | |
| 41 | void* Mutex::getUnderlyingImpl() const { return impl_.get(); } |
| 42 | |
| 43 | void Mutex::lock() const { impl_->lock(); } |
| 44 | |
| 45 | bool Mutex::trylock() const { return impl_->try_lock(); } |
| 46 | |
| 47 | bool Mutex::timedlock(int64_t ms) const { return impl_->try_lock_for(std::chrono::milliseconds(ms)); } |
| 48 | |
| 49 | void Mutex::unlock() const { impl_->unlock(); } |
| 50 | |
| 51 | void Mutex::DEFAULT_INITIALIZER(void* arg) { |
| 52 | } |
| 53 | |
| 54 | }}} // apache::thrift::concurrency |
| 55 | |