171364193SIngo Weinhold/*
271364193SIngo Weinhold * Copyright 2013, Haiku, Inc. All Rights Reserved.
371364193SIngo Weinhold * Distributed under the terms of the MIT License.
471364193SIngo Weinhold *
571364193SIngo Weinhold * Authors:
671364193SIngo Weinhold *		Ingo Weinhold <ingo_weinhold@gmx.de>
771364193SIngo Weinhold */
871364193SIngo Weinhold#ifndef _PTHREAD_MUTEX_LOCKER_H
971364193SIngo Weinhold#define _PTHREAD_MUTEX_LOCKER_H
1071364193SIngo Weinhold
1171364193SIngo Weinhold
1271364193SIngo Weinhold#include <pthread.h>
1371364193SIngo Weinhold
1471364193SIngo Weinhold#include <AutoLocker.h>
1571364193SIngo Weinhold
1671364193SIngo Weinhold
1771364193SIngo Weinholdnamespace BPrivate {
1871364193SIngo Weinhold
1971364193SIngo Weinhold
2071364193SIngo Weinholdclass AutoLockerMutexLocking {
2171364193SIngo Weinholdpublic:
2271364193SIngo Weinhold	inline bool Lock(pthread_mutex_t* lockable)
2371364193SIngo Weinhold	{
2471364193SIngo Weinhold		return pthread_mutex_lock(lockable) == 0;
2571364193SIngo Weinhold	}
2671364193SIngo Weinhold
2771364193SIngo Weinhold	inline void Unlock(pthread_mutex_t* lockable)
2871364193SIngo Weinhold	{
2971364193SIngo Weinhold		pthread_mutex_unlock(lockable);
3071364193SIngo Weinhold	}
3171364193SIngo Weinhold};
3271364193SIngo Weinhold
3371364193SIngo Weinhold
3471364193SIngo Weinholdtypedef AutoLocker<pthread_mutex_t, AutoLockerMutexLocking> PthreadMutexLocker;
3571364193SIngo Weinhold
3671364193SIngo Weinhold
3771364193SIngo Weinhold}	// namespace BPrivate
3871364193SIngo Weinhold
3971364193SIngo Weinholdusing BPrivate::PthreadMutexLocker;
4071364193SIngo Weinhold
4171364193SIngo Weinhold
4271364193SIngo Weinhold#endif	// _PTHREAD_MUTEX_LOCKER_H
43