diff --git a/libraries/AP_Common/AP_Common.h b/libraries/AP_Common/AP_Common.h index 48b2ae4293..f93fdc0706 100644 --- a/libraries/AP_Common/AP_Common.h +++ b/libraries/AP_Common/AP_Common.h @@ -159,24 +159,3 @@ bool is_bounded_int32(int32_t value, int32_t lower_bound, int32_t upper_bound); #else #define SITL_printf(fmt, args ...) #endif - -/* - a method to make semaphores less error prone - */ -class WithSemaphore { -public: - WithSemaphore(HAL_Semaphore &mtx) : - _mtx(mtx) - { - _mtx.take_blocking(); - } - - ~WithSemaphore() { - _mtx.give(); - } -private: - HAL_Semaphore &_mtx; -}; - -#define WITH_SEMAPHORE(sem) WithSemaphore _getsem(sem) - diff --git a/libraries/AP_Common/Semaphore.h b/libraries/AP_Common/Semaphore.h new file mode 100644 index 0000000000..1e00dbf87a --- /dev/null +++ b/libraries/AP_Common/Semaphore.h @@ -0,0 +1,37 @@ +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +/* + a method to make semaphores less error prone. The WITH_SEMAPHORE() + macro will block forever for a semaphore, and will automatically + release the semaphore when it goes out of scope + */ +class WithSemaphore { +public: + WithSemaphore(HAL_Semaphore &mtx) : + _mtx(mtx) + { + _mtx.take_blocking(); + } + + ~WithSemaphore() { + _mtx.give(); + } +private: + HAL_Semaphore &_mtx; +}; + +#define WITH_SEMAPHORE(sem) WithSemaphore _getsem(sem) +