Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of el17dg by
mbed-rtos/rtos/Semaphore.cpp@40:e3bbda7444fa, 2019-05-07 (annotated)
- Committer:
- Noximilien
- Date:
- Tue May 07 15:22:35 2019 +0000
- Revision:
- 40:e3bbda7444fa
- Parent:
- 1:5aa2312d3e94
The Final, Submission Version. I have read and agreed to the academic integrity. SID:201160286
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Noximilien | 1:5aa2312d3e94 | 1 | /* mbed Microcontroller Library |
| Noximilien | 1:5aa2312d3e94 | 2 | * Copyright (c) 2006-2012 ARM Limited |
| Noximilien | 1:5aa2312d3e94 | 3 | * |
| Noximilien | 1:5aa2312d3e94 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| Noximilien | 1:5aa2312d3e94 | 5 | * of this software and associated documentation files (the "Software"), to deal |
| Noximilien | 1:5aa2312d3e94 | 6 | * in the Software without restriction, including without limitation the rights |
| Noximilien | 1:5aa2312d3e94 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| Noximilien | 1:5aa2312d3e94 | 8 | * copies of the Software, and to permit persons to whom the Software is |
| Noximilien | 1:5aa2312d3e94 | 9 | * furnished to do so, subject to the following conditions: |
| Noximilien | 1:5aa2312d3e94 | 10 | * |
| Noximilien | 1:5aa2312d3e94 | 11 | * The above copyright notice and this permission notice shall be included in |
| Noximilien | 1:5aa2312d3e94 | 12 | * all copies or substantial portions of the Software. |
| Noximilien | 1:5aa2312d3e94 | 13 | * |
| Noximilien | 1:5aa2312d3e94 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| Noximilien | 1:5aa2312d3e94 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| Noximilien | 1:5aa2312d3e94 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| Noximilien | 1:5aa2312d3e94 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| Noximilien | 1:5aa2312d3e94 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| Noximilien | 1:5aa2312d3e94 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| Noximilien | 1:5aa2312d3e94 | 20 | * SOFTWARE. |
| Noximilien | 1:5aa2312d3e94 | 21 | */ |
| Noximilien | 1:5aa2312d3e94 | 22 | #include "rtos/Semaphore.h" |
| Noximilien | 1:5aa2312d3e94 | 23 | |
| Noximilien | 1:5aa2312d3e94 | 24 | #include <string.h> |
| Noximilien | 1:5aa2312d3e94 | 25 | |
| Noximilien | 1:5aa2312d3e94 | 26 | namespace rtos { |
| Noximilien | 1:5aa2312d3e94 | 27 | |
| Noximilien | 1:5aa2312d3e94 | 28 | Semaphore::Semaphore(int32_t count) { |
| Noximilien | 1:5aa2312d3e94 | 29 | #ifdef CMSIS_OS_RTX |
| Noximilien | 1:5aa2312d3e94 | 30 | memset(_semaphore_data, 0, sizeof(_semaphore_data)); |
| Noximilien | 1:5aa2312d3e94 | 31 | _osSemaphoreDef.semaphore = _semaphore_data; |
| Noximilien | 1:5aa2312d3e94 | 32 | #endif |
| Noximilien | 1:5aa2312d3e94 | 33 | _osSemaphoreId = osSemaphoreCreate(&_osSemaphoreDef, count); |
| Noximilien | 1:5aa2312d3e94 | 34 | } |
| Noximilien | 1:5aa2312d3e94 | 35 | |
| Noximilien | 1:5aa2312d3e94 | 36 | int32_t Semaphore::wait(uint32_t millisec) { |
| Noximilien | 1:5aa2312d3e94 | 37 | return osSemaphoreWait(_osSemaphoreId, millisec); |
| Noximilien | 1:5aa2312d3e94 | 38 | } |
| Noximilien | 1:5aa2312d3e94 | 39 | |
| Noximilien | 1:5aa2312d3e94 | 40 | osStatus Semaphore::release(void) { |
| Noximilien | 1:5aa2312d3e94 | 41 | return osSemaphoreRelease(_osSemaphoreId); |
| Noximilien | 1:5aa2312d3e94 | 42 | } |
| Noximilien | 1:5aa2312d3e94 | 43 | |
| Noximilien | 1:5aa2312d3e94 | 44 | Semaphore::~Semaphore() { |
| Noximilien | 1:5aa2312d3e94 | 45 | osSemaphoreDelete(_osSemaphoreId); |
| Noximilien | 1:5aa2312d3e94 | 46 | } |
| Noximilien | 1:5aa2312d3e94 | 47 | |
| Noximilien | 1:5aa2312d3e94 | 48 | } |
