Shinichiro Hamaji | 702befc | 2016-01-27 17:21:39 +0900 | [diff] [blame] | 1 | // 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 Hamaji | e643831 | 2016-02-16 14:04:05 +0900 | [diff] [blame] | 19 | Mutex::Mutex() { |
Shinichiro Hamaji | 702befc | 2016-01-27 17:21:39 +0900 | [diff] [blame] | 20 | if (pthread_mutex_init(&mu_, NULL) != 0) |
| 21 | PERROR("pthread_mutex_init"); |
| 22 | } |
| 23 | |
Shinichiro Hamaji | e643831 | 2016-02-16 14:04:05 +0900 | [diff] [blame] | 24 | Mutex::~Mutex() { |
Shinichiro Hamaji | 702befc | 2016-01-27 17:21:39 +0900 | [diff] [blame] | 25 | if (pthread_mutex_destroy(&mu_) != 0) |
| 26 | PERROR("pthread_mutex_destroy"); |
| 27 | } |
| 28 | |
Shinichiro Hamaji | e643831 | 2016-02-16 14:04:05 +0900 | [diff] [blame] | 29 | void Mutex::lock() { |
Shinichiro Hamaji | 702befc | 2016-01-27 17:21:39 +0900 | [diff] [blame] | 30 | if (pthread_mutex_lock(&mu_) != 0) |
| 31 | PERROR("pthread_mutex_lock"); |
| 32 | } |
| 33 | |
Shinichiro Hamaji | e643831 | 2016-02-16 14:04:05 +0900 | [diff] [blame] | 34 | void Mutex::unlock() { |
Shinichiro Hamaji | 702befc | 2016-01-27 17:21:39 +0900 | [diff] [blame] | 35 | if (pthread_mutex_unlock(&mu_) != 0) |
| 36 | PERROR("pthread_mutex_unlock"); |
| 37 | } |