leo hendrickson / Mbed OS example-Ethernet-mbed-Cloud-connect
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers critical-pal.c Source File

critical-pal.c

00001 // ----------------------------------------------------------------------------
00002 // Copyright 2015-2017 ARM Ltd.
00003 //
00004 // SPDX-License-Identifier: Apache-2.0
00005 //
00006 // Licensed under the Apache License, Version 2.0 (the "License");
00007 // you may not use this file except in compliance with the License.
00008 // You may obtain a copy of the License at
00009 //
00010 //     http://www.apache.org/licenses/LICENSE-2.0
00011 //
00012 // Unless required by applicable law or agreed to in writing, software
00013 // distributed under the License is distributed on an "AS IS" BASIS,
00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 // See the License for the specific language governing permissions and
00016 // limitations under the License.
00017 // ----------------------------------------------------------------------------
00018 
00019 #if defined(ATOMIC_QUEUE_USE_PAL) && !defined(TARGET_LIKE_MBED)
00020 
00021 #include <stdint.h>
00022 #include <assert.h>
00023 
00024 #include "pal.h"
00025 // Module include
00026 #include "aq_critical.h"
00027 
00028 static palMutexID_t mutex = NULLPTR;
00029 
00030 void aq_critical_section_enter(void)
00031 {
00032     if (mutex == NULLPTR) {
00033         palStatus_t rc = pal_osMutexCreate(&mutex);
00034         assert(rc == PAL_SUCCESS);
00035     }
00036 
00037     palStatus_t rc = pal_osMutexWait(mutex, PAL_RTOS_WAIT_FOREVER);
00038     assert(rc == PAL_SUCCESS);
00039 }
00040 
00041 void aq_critical_section_exit(void)
00042 {
00043     palStatus_t rc = pal_osMutexRelease(mutex);
00044     assert(rc == PAL_SUCCESS);
00045 }
00046 
00047 #endif // defined(ATOMIC_QUEUE_USE_PAL)