blob: f7cadabccbe4640e5dcc38dec228fa1fe1f4d205 [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
Konrad Grochowski16a23a62014-11-13 15:33:38 +010031namespace apache {
32namespace thrift {
33namespace concurrency {
Roger Meier3faaedf2011-10-02 10:51:45 +000034
35/**
36 * Implementation of Mutex class using boost interprocess mutex
37 *
38 * @version $Id:$
39 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +010040class Mutex::impl : public boost::timed_mutex {};
Roger Meier3faaedf2011-10-02 10:51:45 +000041
Konrad Grochowski16a23a62014-11-13 15:33:38 +010042Mutex::Mutex(Initializer init) : impl_(new Mutex::impl()) {
43 THRIFT_UNUSED_VARIABLE(init);
44}
Roger Meier3faaedf2011-10-02 10:51:45 +000045
Konrad Grochowski16a23a62014-11-13 15:33:38 +010046void* Mutex::getUnderlyingImpl() const {
47 return impl_.get();
48}
Roger Meier3faaedf2011-10-02 10:51:45 +000049
Konrad Grochowski16a23a62014-11-13 15:33:38 +010050void Mutex::lock() const {
51 impl_->lock();
52}
Roger Meier3faaedf2011-10-02 10:51:45 +000053
Konrad Grochowski16a23a62014-11-13 15:33:38 +010054bool Mutex::trylock() const {
55 return impl_->try_lock();
56}
Roger Meier3faaedf2011-10-02 10:51:45 +000057
Konrad Grochowski16a23a62014-11-13 15:33:38 +010058bool Mutex::timedlock(int64_t ms) const {
59 return impl_->timed_lock(boost::get_system_time() + boost::posix_time::milliseconds(ms));
60}
Roger Meier3faaedf2011-10-02 10:51:45 +000061
Konrad Grochowski16a23a62014-11-13 15:33:38 +010062void Mutex::unlock() const {
63 impl_->unlock();
64}
Roger Meier3faaedf2011-10-02 10:51:45 +000065
66void Mutex::DEFAULT_INITIALIZER(void* arg) {
Ben Craigcd54ec62013-08-29 10:45:21 -050067 THRIFT_UNUSED_VARIABLE(arg);
Roger Meier3faaedf2011-10-02 10:51:45 +000068}
Konrad Grochowski16a23a62014-11-13 15:33:38 +010069}
70}
71} // apache::thrift::concurrency