Add shared PthreadMutexLocker, an AutoLocker for pthread_mutex_t
This commit is contained in:
parent
6978941aac
commit
7136419383
42
headers/private/shared/PthreadMutexLocker.h
Normal file
42
headers/private/shared/PthreadMutexLocker.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2013, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Ingo Weinhold <ingo_weinhold@gmx.de>
|
||||
*/
|
||||
#ifndef _PTHREAD_MUTEX_LOCKER_H
|
||||
#define _PTHREAD_MUTEX_LOCKER_H
|
||||
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <AutoLocker.h>
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class AutoLockerMutexLocking {
|
||||
public:
|
||||
inline bool Lock(pthread_mutex_t* lockable)
|
||||
{
|
||||
return pthread_mutex_lock(lockable) == 0;
|
||||
}
|
||||
|
||||
inline void Unlock(pthread_mutex_t* lockable)
|
||||
{
|
||||
pthread_mutex_unlock(lockable);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
typedef AutoLocker<pthread_mutex_t, AutoLockerMutexLocking> PthreadMutexLocker;
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
using BPrivate::PthreadMutexLocker;
|
||||
|
||||
|
||||
#endif // _PTHREAD_MUTEX_LOCKER_H
|
Loading…
x
Reference in New Issue
Block a user