UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / src / lib / amutex.cpp
bloba97cbb342f1e3c8afca240cc619cbaa07c3e4ba7
1 /*
2 * amutex.cpp
4 * Simple mutex wrapper class.
5 */
7 /*
8 * Copyright (C) 2007 Adam Kropelin
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General
12 * Public License as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * MA 02111-1307, USA.
25 #include "amutex.h"
26 #include "autil.h"
28 const char *amutex::DEFAULT_NAME = "unnamed_mutex";
30 amutex::amutex(const char *name, bool recursive)
31 : _name(name)
33 pthread_mutexattr_t attr;
34 pthread_mutexattr_init(&attr);
35 pthread_mutexattr_settype(&attr,
36 recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL);
37 pthread_mutex_init(&_mutex, &attr);
38 pthread_mutexattr_destroy(&attr);
41 amutex::~amutex()
43 pthread_mutex_destroy(&_mutex);