doc ru, printf() before assert in containers
This commit is contained in:
@@ -17,22 +17,67 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \class PIMutex
|
||||
* \brief Mutex
|
||||
* \details
|
||||
* \section PIMutex_sec0 Synopsis
|
||||
* %PIMutex provides synchronization blocks between several threads.
|
||||
* Using mutex guarantees execution of some code only one of threads.
|
||||
* Mutex contains logic state and functions to change it: \a lock(),
|
||||
* \a unlock() and \a tryLock().
|
||||
*
|
||||
* \section PIMutex_sec1 Usage
|
||||
* Block of code that should to be executed only one thread simultaniously
|
||||
* should to be started with \a lock() and ended with \a unlock().
|
||||
* \snippet pimutex.cpp main
|
||||
* "mutex" in this example is one for all threads.
|
||||
*
|
||||
* */
|
||||
//! \addtogroup Thread
|
||||
//! \{
|
||||
//! \class PIMutex pimutex.h
|
||||
//!
|
||||
//! \~\brief
|
||||
//! \~english Simple mutex
|
||||
//! \~russian Простой мьютекс
|
||||
//!
|
||||
//!
|
||||
//! \~\details
|
||||
//! \~english \section PIMutex_sec0 Synopsis
|
||||
//! \~russian \section PIMutex_sec0 Краткий обзор
|
||||
//!
|
||||
//! \~english
|
||||
//! %PIMutex provides synchronization blocks between several threads.
|
||||
//! Using mutex guarantees execution of some code only one of threads.
|
||||
//! Mutex contains logic state and functions to change it: \a lock(),
|
||||
//! \a unlock() and \a tryLock().
|
||||
//!
|
||||
//! \~russian
|
||||
//!
|
||||
//!
|
||||
//! \~english \section PIMutex_sec0 Usage
|
||||
//! \~russian \section PIMutex_sec0 Использование
|
||||
//!
|
||||
//! \~english
|
||||
//! Block of code that should to be executed only one thread simultaniously
|
||||
//! should to be started with \a lock() and finished with \a unlock().
|
||||
//!
|
||||
//! \~russian
|
||||
//!
|
||||
//! \~\code
|
||||
//! mutex.lock();
|
||||
//! // ... your code here
|
||||
//! mutex.unlock();
|
||||
//! \endcode
|
||||
//! \}
|
||||
|
||||
|
||||
//! \addtogroup Thread
|
||||
//! \{
|
||||
//! \class PIMutexLocker pimutex.h
|
||||
//!
|
||||
//! \~\brief
|
||||
//! \~english %PIMutex autolocker
|
||||
//! \~russian Автоблокировщик %PIMutex
|
||||
//!
|
||||
//!
|
||||
//! \~\details
|
||||
//!
|
||||
//! \~english
|
||||
//! When a PIMutexLocker object is created, it attempts to lock the mutex it is given, if "condition" true.
|
||||
//! When control leaves the scope in which the PIMutexLocker object was created,
|
||||
//! the PIMutexLocker is destructed and the mutex is released, if "condition" true.
|
||||
//! If "condition" false this class do nothing.
|
||||
//! The PIMutexLocker class is non-copyable.
|
||||
//!
|
||||
//! \~russian
|
||||
//!
|
||||
//! \}
|
||||
|
||||
|
||||
#include "pimutex.h"
|
||||
#include "piincludes_p.h"
|
||||
@@ -68,6 +113,11 @@ PIMutex::~PIMutex() {
|
||||
}
|
||||
|
||||
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! If mutex is unlocked it set to locked state and returns immediate.
|
||||
//! If mutex is already locked function blocks until mutex will be unlocked
|
||||
//! \~russian
|
||||
void PIMutex::lock() {
|
||||
#if defined(WINDOWS)
|
||||
EnterCriticalSection(&(PRIVATE->mutex));
|
||||
@@ -79,6 +129,10 @@ void PIMutex::lock() {
|
||||
}
|
||||
|
||||
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! In any case this function returns immediate
|
||||
//! \~russian
|
||||
void PIMutex::unlock() {
|
||||
#if defined(WINDOWS)
|
||||
LeaveCriticalSection(&(PRIVATE->mutex));
|
||||
@@ -90,12 +144,17 @@ void PIMutex::unlock() {
|
||||
}
|
||||
|
||||
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! If mutex is unlocked it set to locked state and returns "true" immediate.
|
||||
//! If mutex is already locked function returns immediate an returns "false"
|
||||
//! \~russian
|
||||
bool PIMutex::tryLock() {
|
||||
bool ret =
|
||||
#if defined(WINDOWS)
|
||||
(TryEnterCriticalSection(&(PRIVATE->mutex)) != 0);
|
||||
#elif defined(FREERTOS)
|
||||
xSemaphoreTake(PRIVATE->mutex, 0);
|
||||
xSemaphoreTake(PRIVATE->mutex, 0);
|
||||
#else
|
||||
(pthread_mutex_trylock(&(PRIVATE->mutex)) == 0);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user