Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mstd_mutex.cpp Source File

mstd_mutex.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2019 ARM Limited
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #include <mstd_mutex>
00019 
00020 #if MBED_CONF_RTOS_PRESENT
00021 
00022 /* SharedPointer<Mutex> lazy-init kerfuffle will generate code - don't inline it */
00023 namespace mstd {
00024 
00025 // Lock and try lock use SingletonPtr::get() to lazy-init
00026 void _Mutex_base::lock()
00027 {
00028     _pm.get()->lock();
00029 }
00030 
00031 bool _Mutex_base::try_lock()
00032 {
00033     return _pm.get()->trylock();
00034 }
00035 
00036 // Unlock knows it must have been initted, so optimise with get_no_init()
00037 void _Mutex_base::unlock()
00038 {
00039     _pm.get_no_init()->unlock();
00040 }
00041 
00042 // And don't forget to destroy - SingletonPtr doesn't do it automatically
00043 _Mutex_base::~_Mutex_base()
00044 {
00045     _pm.destroy();
00046 }
00047 
00048 } // namespace mstd
00049 
00050 #endif