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 Rejestrator
mbed-rtos/rtos/Semaphore.cpp@0:fa31f8461c63, 2015-04-18 (annotated)
- Committer:
- Waldek
- Date:
- Sat Apr 18 17:01:57 2015 +0000
- Revision:
- 0:fa31f8461c63
working version, stop
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Waldek | 0:fa31f8461c63 | 1 | /* mbed Microcontroller Library |
| Waldek | 0:fa31f8461c63 | 2 | * Copyright (c) 2006-2012 ARM Limited |
| Waldek | 0:fa31f8461c63 | 3 | * |
| Waldek | 0:fa31f8461c63 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| Waldek | 0:fa31f8461c63 | 5 | * of this software and associated documentation files (the "Software"), to deal |
| Waldek | 0:fa31f8461c63 | 6 | * in the Software without restriction, including without limitation the rights |
| Waldek | 0:fa31f8461c63 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| Waldek | 0:fa31f8461c63 | 8 | * copies of the Software, and to permit persons to whom the Software is |
| Waldek | 0:fa31f8461c63 | 9 | * furnished to do so, subject to the following conditions: |
| Waldek | 0:fa31f8461c63 | 10 | * |
| Waldek | 0:fa31f8461c63 | 11 | * The above copyright notice and this permission notice shall be included in |
| Waldek | 0:fa31f8461c63 | 12 | * all copies or substantial portions of the Software. |
| Waldek | 0:fa31f8461c63 | 13 | * |
| Waldek | 0:fa31f8461c63 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| Waldek | 0:fa31f8461c63 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| Waldek | 0:fa31f8461c63 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| Waldek | 0:fa31f8461c63 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| Waldek | 0:fa31f8461c63 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| Waldek | 0:fa31f8461c63 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| Waldek | 0:fa31f8461c63 | 20 | * SOFTWARE. |
| Waldek | 0:fa31f8461c63 | 21 | */ |
| Waldek | 0:fa31f8461c63 | 22 | #include "Semaphore.h" |
| Waldek | 0:fa31f8461c63 | 23 | |
| Waldek | 0:fa31f8461c63 | 24 | #include <string.h> |
| Waldek | 0:fa31f8461c63 | 25 | |
| Waldek | 0:fa31f8461c63 | 26 | namespace rtos { |
| Waldek | 0:fa31f8461c63 | 27 | |
| Waldek | 0:fa31f8461c63 | 28 | Semaphore::Semaphore(int32_t count) { |
| Waldek | 0:fa31f8461c63 | 29 | #ifdef CMSIS_OS_RTX |
| Waldek | 0:fa31f8461c63 | 30 | memset(_semaphore_data, 0, sizeof(_semaphore_data)); |
| Waldek | 0:fa31f8461c63 | 31 | _osSemaphoreDef.semaphore = _semaphore_data; |
| Waldek | 0:fa31f8461c63 | 32 | #endif |
| Waldek | 0:fa31f8461c63 | 33 | _osSemaphoreId = osSemaphoreCreate(&_osSemaphoreDef, count); |
| Waldek | 0:fa31f8461c63 | 34 | } |
| Waldek | 0:fa31f8461c63 | 35 | |
| Waldek | 0:fa31f8461c63 | 36 | int32_t Semaphore::wait(uint32_t millisec) { |
| Waldek | 0:fa31f8461c63 | 37 | return osSemaphoreWait(_osSemaphoreId, millisec); |
| Waldek | 0:fa31f8461c63 | 38 | } |
| Waldek | 0:fa31f8461c63 | 39 | |
| Waldek | 0:fa31f8461c63 | 40 | osStatus Semaphore::release(void) { |
| Waldek | 0:fa31f8461c63 | 41 | return osSemaphoreRelease(_osSemaphoreId); |
| Waldek | 0:fa31f8461c63 | 42 | } |
| Waldek | 0:fa31f8461c63 | 43 | |
| Waldek | 0:fa31f8461c63 | 44 | Semaphore::~Semaphore() { |
| Waldek | 0:fa31f8461c63 | 45 | osSemaphoreDelete(_osSemaphoreId); |
| Waldek | 0:fa31f8461c63 | 46 | } |
| Waldek | 0:fa31f8461c63 | 47 | |
| Waldek | 0:fa31f8461c63 | 48 | } |