aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-01-19 00:59:25 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-01-19 00:59:25 +0000
commit6326ddf024db95b616f34b198a4991ad30de316b (patch)
tree0f471fcdb9243311f539365724d9932f20d98a36
parentc36bffdd89a43a08f7b44a6527462b4a9de2d1b1 (diff)
downloadpaludis-6326ddf024db95b616f34b198a4991ad30de316b.tar.gz
paludis-6326ddf024db95b616f34b198a4991ad30de316b.tar.xz
Don't use dynamic allocation for mutexes
-rw-r--r--paludis/util/mutex.cc30
-rw-r--r--paludis/util/mutex.hh5
2 files changed, 19 insertions, 16 deletions
diff --git a/paludis/util/mutex.cc b/paludis/util/mutex.cc
index 4fa1566..9080c03 100644
--- a/paludis/util/mutex.cc
+++ b/paludis/util/mutex.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2008 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 2009 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -24,30 +24,34 @@
using namespace paludis;
-Mutex::Mutex() :
- _attr(new pthread_mutexattr_t),
- _mutex(new pthread_mutex_t)
+namespace
{
- pthread_mutexattr_init(_attr);
- pthread_mutexattr_settype(_attr, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init(_mutex, _attr);
+ pthread_mutexattr_t make_recursive_attr()
+ {
+ pthread_mutexattr_t result;
+ pthread_mutexattr_init(&result);
+ pthread_mutexattr_settype(&result, PTHREAD_MUTEX_RECURSIVE);
+ return result;
+ }
+}
+
+Mutex::Mutex()
+{
+ static const pthread_mutexattr_t attr = make_recursive_attr();
+ pthread_mutex_init(&_mutex, &attr);
}
Mutex::~Mutex()
{
int r(0);
- if (0 != ((r = pthread_mutex_destroy(_mutex))))
+ if (0 != ((r = pthread_mutex_destroy(&_mutex))))
throw InternalError(PALUDIS_HERE, "mutex destory failed: " + stringify(strerror(r)));
- pthread_mutexattr_destroy(_attr);
-
- delete _mutex;
- delete _attr;
}
pthread_mutex_t *
Mutex::posix_mutex()
{
- return _mutex;
+ return &_mutex;
}
Lock::Lock(Mutex & m) :
diff --git a/paludis/util/mutex.hh b/paludis/util/mutex.hh
index 669f9bc..5c73385 100644
--- a/paludis/util/mutex.hh
+++ b/paludis/util/mutex.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2008 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 2009 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -48,8 +48,7 @@ namespace paludis
Mutex(const Mutex &);
Mutex & operator= (const Mutex &);
- pthread_mutexattr_t * const _attr;
- pthread_mutex_t * const _mutex;
+ pthread_mutex_t _mutex;
public:
///\name Basic operations