Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2006-09-06 23:13:23 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2006-09-06 23:13:23 +0400
commite7d6537f1c5227005ccddc52987ea720ba66bc80 (patch)
tree5ac48fd44121194b879fc002d369281494a7598d /source/blender/blenlib
parentd444f25b2864b7d4a9ae39211c695e36ffd813a8 (diff)
Added support for threadsafe MEM_mallocN/MEM_freeN in the guardedalloc
module itself, replacing the special MEM_mallocT/MEM_freeT functions. Mutex locking is only enabled when threads are running. There was no good reason to have these separate, it just led to ugly hacks when calling functions with non-threadsafe malloc from threads.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_threads.h10
-rw-r--r--source/blender/blenlib/intern/threads.c56
2 files changed, 16 insertions, 50 deletions
diff --git a/source/blender/blenlib/BLI_threads.h b/source/blender/blenlib/BLI_threads.h
index 43792ccb1bc..af2565e3ae5 100644
--- a/source/blender/blenlib/BLI_threads.h
+++ b/source/blender/blenlib/BLI_threads.h
@@ -31,11 +31,9 @@
#ifndef BLI_THREADS_H
#define BLI_THREADS_H
-/* default lock is to protect MEM_ module calls, one custom lock available now. van be extended */
-#define LOCK_MALLOC 0
+/* one custom lock available now. can be extended */
#define LOCK_CUSTOM1 1
-
void BLI_init_threads (ListBase *threadbase, void *(*do_thread)(void *), int tot);
int BLI_available_threads(ListBase *threadbase);
int BLI_available_thread_index(ListBase *threadbase);
@@ -46,11 +44,5 @@ void BLI_end_threads (ListBase *threadbase);
void BLI_lock_thread (int type);
void BLI_unlock_thread (int type);
- /* threadsafe version of MEM_malloc and friends */
-void *MEM_mallocT(int len, char *name);
-void *MEM_callocT(int len, char *name);
-void *MEM_mapallocT(int len, char *name);
-void MEM_freeT(void *poin);
-
#endif
diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c
index f94d959d46a..d9cf2ec0e57 100644
--- a/source/blender/blenlib/intern/threads.c
+++ b/source/blender/blenlib/intern/threads.c
@@ -97,6 +97,16 @@ typedef struct ThreadSlot {
int avail;
} ThreadSlot;
+static void BLI_lock_malloc_thread()
+{
+ pthread_mutex_lock(&_malloc_lock);
+}
+
+static void BLI_unlock_malloc_thread()
+{
+ pthread_mutex_unlock(&_malloc_lock);
+}
+
void BLI_init_threads(ListBase *threadbase, void *(*do_thread)(void *), int tot)
{
int a;
@@ -114,6 +124,8 @@ void BLI_init_threads(ListBase *threadbase, void *(*do_thread)(void *), int tot)
tslot->do_thread= do_thread;
tslot->avail= 1;
}
+
+ MEM_set_lock_callback(BLI_lock_malloc_thread, BLI_unlock_malloc_thread);
}
/* amount of available threads */
@@ -182,57 +194,19 @@ void BLI_end_threads(ListBase *threadbase)
}
BLI_freelistN(threadbase);
+ MEM_set_lock_callback(NULL, NULL);
}
void BLI_lock_thread(int type)
{
- if(type==LOCK_MALLOC)
- pthread_mutex_lock(&_malloc_lock);
- else
+ if (type==LOCK_CUSTOM1)
pthread_mutex_lock(&_custom1_lock);
}
void BLI_unlock_thread(int type)
{
- if(type==LOCK_MALLOC)
- pthread_mutex_unlock(&_malloc_lock);
- else
+ if(type==LOCK_CUSTOM1)
pthread_mutex_unlock(&_custom1_lock);
}
-
-/* ***************** Thread safe MEM_malloc/calloc/free ************************** */
-
-void *MEM_mallocT(int len, char *name)
-{
- void *mem;
- pthread_mutex_lock(&_malloc_lock);
- mem= MEM_mallocN(len, name);
- pthread_mutex_unlock(&_malloc_lock);
- return mem;
-}
-void *MEM_callocT(int len, char *name)
-{
- void *mem;
- pthread_mutex_lock(&_malloc_lock);
- mem= MEM_callocN(len, name);
- pthread_mutex_unlock(&_malloc_lock);
- return mem;
-}
-void *MEM_mapallocT(int len, char *name)
-{
- void *mem;
- pthread_mutex_lock(&_malloc_lock);
- mem= MEM_mapallocN(len, name);
- pthread_mutex_unlock(&_malloc_lock);
- return mem;
-}
-void MEM_freeT(void *poin)
-{
- pthread_mutex_lock(&_malloc_lock);
- MEM_freeN(poin);
- pthread_mutex_unlock(&_malloc_lock);
-}
-
-
/* eof */