blob: 59c36185ecf8ecc089f587ce53481b7756688c89 [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
Konrad Grochowski9be4e682013-06-22 22:03:31 +020020#include <thrift/thrift-config.h>
21
Roger Meier4285ba22013-06-10 21:17:23 +020022#include <thrift/concurrency/Mutex.h>
23#include <thrift/concurrency/Util.h>
Ben Craigcd54ec62013-08-29 10:45:21 -050024#include <thrift/Thrift.h>
Roger Meier3faaedf2011-10-02 10:51:45 +000025
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
Ben Craigcd54ec62013-08-29 10:45:21 -050041Mutex::Mutex(Initializer init) : impl_(new Mutex::impl())
42{ THRIFT_UNUSED_VARIABLE(init); }
Roger Meier3faaedf2011-10-02 10:51:45 +000043
44void* Mutex::getUnderlyingImpl() const { return impl_.get(); }
45
46void Mutex::lock() const { impl_->lock(); }
47
48bool Mutex::trylock() const { return impl_->try_lock(); }
49
50bool Mutex::timedlock(int64_t ms) const { return impl_->timed_lock(boost::get_system_time()+boost::posix_time::milliseconds(ms)); }
51
52void Mutex::unlock() const { impl_->unlock(); }
53
54void Mutex::DEFAULT_INITIALIZER(void* arg) {
Ben Craigcd54ec62013-08-29 10:45:21 -050055 THRIFT_UNUSED_VARIABLE(arg);
Roger Meier3faaedf2011-10-02 10:51:45 +000056}
57
58}}} // apache::thrift::concurrency