blob: a7b5c377fb141fe52a880e70492b806065b83b04 [file] [log] [blame]
Roger Meier3faaedf2011-10-02 10:51:45 +00001/*
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>
Roger Meier38315782011-11-06 11:29:41 +000028#include <boost/thread/mutex.hpp>
Roger Meier3faaedf2011-10-02 10:51:45 +000029#include <boost/date_time/posix_time/posix_time.hpp>
Roger Meier3faaedf2011-10-02 10:51:45 +000030
31namespace apache { namespace thrift { namespace concurrency {
32
33/**
34 * Implementation of Mutex class using boost interprocess mutex
35 *
36 * @version $Id:$
37 */
Roger Meier38315782011-11-06 11:29:41 +000038class Mutex::impl : public boost::timed_mutex {
Roger Meier3faaedf2011-10-02 10:51:45 +000039};
40
41Mutex::Mutex(Initializer init) : impl_(new Mutex::impl()) {}
42
43void* Mutex::getUnderlyingImpl() const { return impl_.get(); }
44
45void Mutex::lock() const { impl_->lock(); }
46
47bool Mutex::trylock() const { return impl_->try_lock(); }
48
49bool Mutex::timedlock(int64_t ms) const { return impl_->timed_lock(boost::get_system_time()+boost::posix_time::milliseconds(ms)); }
50
51void Mutex::unlock() const { impl_->unlock(); }
52
53void Mutex::DEFAULT_INITIALIZER(void* arg) {
54}
55
56}}} // apache::thrift::concurrency
57