1 /* 2 * Copyright 2013, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold <ingo_weinhold@gmx.de> 7 */ 8 #ifndef _PTHREAD_MUTEX_LOCKER_H 9 #define _PTHREAD_MUTEX_LOCKER_H 10 11 12 #include <pthread.h> 13 14 #include <AutoLocker.h> 15 16 17 namespace BPrivate { 18 19 20 class AutoLockerMutexLocking { 21 public: 22 inline bool Lock(pthread_mutex_t* lockable) 23 { 24 return pthread_mutex_lock(lockable) == 0; 25 } 26 27 inline void Unlock(pthread_mutex_t* lockable) 28 { 29 pthread_mutex_unlock(lockable); 30 } 31 }; 32 33 34 typedef AutoLocker<pthread_mutex_t, AutoLockerMutexLocking> PthreadMutexLocker; 35 36 37 } // namespace BPrivate 38 39 using BPrivate::PthreadMutexLocker; 40 41 42 #endif // _PTHREAD_MUTEX_LOCKER_H 43