[arrayfire] 200/284: Additional sanitizing for mutex locks
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:33 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/experimental
in repository arrayfire.
commit f9a83360e2443476357a50763010f476ac11fb48
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date: Mon Jan 11 15:01:09 2016 -0500
Additional sanitizing for mutex locks
Use std::recursive_mutex instead of std::mutex for the cases
when a mutex lock is called from within another call.
Make lock_guard the first call to all the functions
---
src/backend/MemoryManager.cpp | 11 ++++++-----
src/backend/MemoryManager.hpp | 4 ++--
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/backend/MemoryManager.cpp b/src/backend/MemoryManager.cpp
index 621ce62..696c9af 100644
--- a/src/backend/MemoryManager.cpp
+++ b/src/backend/MemoryManager.cpp
@@ -25,6 +25,7 @@ MemoryManager::MemoryManager(int num_devices, unsigned MAX_BUFFERS, unsigned MAX
memory(num_devices),
debug_mode(debug)
{
+ lock_guard_t lock(this->memory_mutex);
std::string env_var = getEnvVar("AF_MEM_DEBUG");
if (!env_var.empty()) {
this->debug_mode = env_var[0] != '0';
@@ -36,6 +37,7 @@ void MemoryManager::garbageCollect()
{
if (this->debug_mode) return;
+ lock_guard_t lock(this->memory_mutex);
memory_info& current = this->getCurrentMemoryInfo();
for(buffer_iter iter = current.map.begin();
@@ -66,8 +68,8 @@ void MemoryManager::garbageCollect()
void MemoryManager::unlock(void *ptr, bool user_unlock)
{
- memory_info& current = this->getCurrentMemoryInfo();
lock_guard_t lock(this->memory_mutex);
+ memory_info& current = this->getCurrentMemoryInfo();
buffer_iter iter = current.map.find((void *)ptr);
@@ -93,14 +95,13 @@ void MemoryManager::unlock(void *ptr, bool user_unlock)
void *MemoryManager::alloc(const size_t bytes)
{
- memory_info& current = this->getCurrentMemoryInfo();
+ lock_guard_t lock(this->memory_mutex);
void *ptr = NULL;
size_t alloc_bytes = this->debug_mode ? bytes : (divup(bytes, mem_step_size) * mem_step_size);
if (bytes > 0) {
-
- lock_guard_t lock(this->memory_mutex);
+ memory_info& current = this->getCurrentMemoryInfo();
// There is no memory cache in debug mode
if (!this->debug_mode) {
@@ -240,8 +241,8 @@ void MemoryManager::printInfo(const char *msg, const int device)
void MemoryManager::bufferInfo(size_t *alloc_bytes, size_t *alloc_buffers,
size_t *lock_bytes, size_t *lock_buffers)
{
- memory_info current = this->getCurrentMemoryInfo();
lock_guard_t lock(this->memory_mutex);
+ memory_info current = this->getCurrentMemoryInfo();
if (alloc_bytes ) *alloc_bytes = current.total_bytes;
if (alloc_buffers ) *alloc_buffers = current.map.size();
if (lock_bytes ) *lock_bytes = current.lock_bytes;
diff --git a/src/backend/MemoryManager.hpp b/src/backend/MemoryManager.hpp
index 1f87ea2..cfcc60f 100644
--- a/src/backend/MemoryManager.hpp
+++ b/src/backend/MemoryManager.hpp
@@ -16,8 +16,8 @@
namespace common
{
-typedef std::mutex mutex_t;
-typedef std::lock_guard<std::mutex> lock_guard_t;
+typedef std::recursive_mutex mutex_t;
+typedef std::lock_guard<mutex_t> lock_guard_t;
class MemoryManager
{
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git
More information about the debian-science-commits
mailing list