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:
authorJoseph Eagar <joeedh@gmail.com>2010-04-13 16:51:03 +0400
committerJoseph Eagar <joeedh@gmail.com>2010-04-13 16:51:03 +0400
commit86aa4e5c3d7e0b95d9e55bab027f968b42a3eda6 (patch)
tree9208dfc29a7f163ea7af988ad663cfc7c78d2ae1 /source/blender/blenlib
parente50f7986476a2fe5604d78db6dea784384d3e38f (diff)
prevent images from freeing gpu buffers if not run within the main thread, instead they are queued to be freed the next time GPU_image_free() is run from the main thread.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_threads.h4
-rw-r--r--source/blender/blenlib/intern/threads.c15
2 files changed, 18 insertions, 1 deletions
diff --git a/source/blender/blenlib/BLI_threads.h b/source/blender/blenlib/BLI_threads.h
index eda0e830736..e3290873dc3 100644
--- a/source/blender/blenlib/BLI_threads.h
+++ b/source/blender/blenlib/BLI_threads.h
@@ -40,6 +40,9 @@ struct ListBase;
/* Threading API */
+/*this is run once at startup*/
+void BLI_threadapi_init(void);
+
void BLI_init_threads (struct ListBase *threadbase, void *(*do_thread)(void *), int tot);
int BLI_available_threads(struct ListBase *threadbase);
int BLI_available_thread_index(struct ListBase *threadbase);
@@ -48,6 +51,7 @@ void BLI_remove_thread (struct ListBase *threadbase, void *callerdata);
void BLI_remove_thread_index(struct ListBase *threadbase, int index);
void BLI_remove_threads(struct ListBase *threadbase);
void BLI_end_threads (struct ListBase *threadbase);
+int BLI_thread_is_main(void);
/* System Information */
diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c
index 351e0be1102..6e2eff6f97a 100644
--- a/source/blender/blenlib/intern/threads.c
+++ b/source/blender/blenlib/intern/threads.c
@@ -106,6 +106,7 @@ static pthread_mutex_t _image_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t _preview_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t _viewer_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t _custom1_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_t mainid;
static int thread_levels= 0; /* threads can be invoked inside threads */
/* just a max for security reasons */
@@ -129,6 +130,11 @@ static void BLI_unlock_malloc_thread(void)
pthread_mutex_unlock(&_malloc_lock);
}
+void BLI_threadapi_init(void)
+{
+ mainid = pthread_self();
+}
+
/* tot = 0 only initializes malloc mutex in a safe way (see sequence.c)
problem otherwise: scene render will kill of the mutex!
*/
@@ -136,7 +142,7 @@ static void BLI_unlock_malloc_thread(void)
void BLI_init_threads(ListBase *threadbase, void *(*do_thread)(void *), int tot)
{
int a;
-
+
if(threadbase != NULL && tot > 0) {
threadbase->first= threadbase->last= NULL;
@@ -204,6 +210,13 @@ static void *tslot_thread_start(void *tslot_p)
return tslot->do_thread(tslot->callerdata);
}
+int BLI_thread_is_main(void) {
+ pthread_t tid;
+ tid = pthread_self();
+
+ return !memcmp(&tid, &mainid, sizeof(pthread_t));
+}
+
void BLI_insert_thread(ListBase *threadbase, void *callerdata)
{
ThreadSlot *tslot;