Roger Meier | 3faaedf | 2011-10-02 10:51:45 +0000 | [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 | |
| 20 | #ifdef HAVE_CONFIG_H |
| 21 | #include <config.h> |
| 22 | #endif |
| 23 | #include "Mutex.h" |
| 24 | #include "Util.h" |
| 25 | |
| 26 | #include <cassert> |
| 27 | #include <boost/thread.hpp> |
| 28 | #include <boost/date_time/posix_time/posix_time.hpp> |
| 29 | #include <boost/interprocess/sync/interprocess_mutex.hpp> |
| 30 | |
| 31 | using namespace boost::interprocess; |
| 32 | |
| 33 | namespace apache { namespace thrift { namespace concurrency { |
| 34 | |
| 35 | /** |
| 36 | * Implementation of Mutex class using boost interprocess mutex |
| 37 | * |
| 38 | * @version $Id:$ |
| 39 | */ |
| 40 | class Mutex::impl : public interprocess_mutex { |
| 41 | }; |
| 42 | |
| 43 | Mutex::Mutex(Initializer init) : impl_(new Mutex::impl()) {} |
| 44 | |
| 45 | void* Mutex::getUnderlyingImpl() const { return impl_.get(); } |
| 46 | |
| 47 | void Mutex::lock() const { impl_->lock(); } |
| 48 | |
| 49 | bool Mutex::trylock() const { return impl_->try_lock(); } |
| 50 | |
| 51 | bool Mutex::timedlock(int64_t ms) const { return impl_->timed_lock(boost::get_system_time()+boost::posix_time::milliseconds(ms)); } |
| 52 | |
| 53 | void Mutex::unlock() const { impl_->unlock(); } |
| 54 | |
| 55 | void Mutex::DEFAULT_INITIALIZER(void* arg) { |
| 56 | } |
| 57 | |
| 58 | }}} // apache::thrift::concurrency |
| 59 | |