blob: 986366b20ab4b29c6ec253d60323c39fb6b2a0a2 [file] [log] [blame]
Shinichiro Hamaji702befc2016-01-27 17:21:39 +09001// Copyright 2016 Google Inc. All rights reserved
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "mutex.h"
16
17#include "log.h"
18
Shinichiro Hamajie6438312016-02-16 14:04:05 +090019Mutex::Mutex() {
Shinichiro Hamaji702befc2016-01-27 17:21:39 +090020 if (pthread_mutex_init(&mu_, NULL) != 0)
21 PERROR("pthread_mutex_init");
22}
23
Shinichiro Hamajie6438312016-02-16 14:04:05 +090024Mutex::~Mutex() {
Shinichiro Hamaji702befc2016-01-27 17:21:39 +090025 if (pthread_mutex_destroy(&mu_) != 0)
26 PERROR("pthread_mutex_destroy");
27}
28
Shinichiro Hamajie6438312016-02-16 14:04:05 +090029void Mutex::lock() {
Shinichiro Hamaji702befc2016-01-27 17:21:39 +090030 if (pthread_mutex_lock(&mu_) != 0)
31 PERROR("pthread_mutex_lock");
32}
33
Shinichiro Hamajie6438312016-02-16 14:04:05 +090034void Mutex::unlock() {
Shinichiro Hamaji702befc2016-01-27 17:21:39 +090035 if (pthread_mutex_unlock(&mu_) != 0)
36 PERROR("pthread_mutex_unlock");
37}