Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
/**
|
|
|
|
*
|
2008-03-19 22:58:16 +00:00
|
|
|
* $Id$
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2006 Blender Foundation
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2006-02-25 11:56:08 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_threads.h"
|
|
|
|
|
2008-08-16 22:47:33 +00:00
|
|
|
#include "PIL_time.h"
|
|
|
|
|
2008-02-21 08:43:13 +00:00
|
|
|
/* for checking system threads - BLI_system_thread_count */
|
2008-02-20 01:12:21 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#include "Windows.h"
|
2008-02-21 08:43:13 +00:00
|
|
|
#elif defined(__APPLE__)
|
2008-02-20 16:07:42 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysctl.h>
|
2008-02-21 08:43:13 +00:00
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
2008-02-20 16:07:42 +00:00
|
|
|
#endif
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
|
|
|
|
/* ********** basic thread control API ************
|
|
|
|
|
|
|
|
Many thread cases have an X amount of jobs, and only an Y amount of
|
|
|
|
threads are useful (typically amount of cpus)
|
|
|
|
|
|
|
|
This code can be used to start a maximum amount of 'thread slots', which
|
|
|
|
then can be filled in a loop with an idle timer.
|
|
|
|
|
|
|
|
A sample loop can look like this (pseudo c);
|
|
|
|
|
|
|
|
ListBase lb;
|
|
|
|
int maxthreads= 2;
|
|
|
|
int cont= 1;
|
|
|
|
|
|
|
|
BLI_init_threads(&lb, do_something_func, maxthreads);
|
|
|
|
|
|
|
|
while(cont) {
|
|
|
|
if(BLI_available_threads(&lb) && !(escape loop event)) {
|
|
|
|
// get new job (data pointer)
|
|
|
|
// tag job 'processed
|
|
|
|
BLI_insert_thread(&lb, job);
|
|
|
|
}
|
|
|
|
else PIL_sleep_ms(50);
|
|
|
|
|
|
|
|
// find if a job is ready, this the do_something_func() should write in job somewhere
|
|
|
|
cont= 0;
|
|
|
|
for(go over all jobs)
|
|
|
|
if(job is ready) {
|
|
|
|
if(job was not removed) {
|
|
|
|
BLI_remove_thread(&lb, job);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else cont= 1;
|
|
|
|
}
|
|
|
|
// conditions to exit loop
|
|
|
|
if(if escape loop event) {
|
|
|
|
if(BLI_available_threadslots(&lb)==maxthreads)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_end_threads(&lb);
|
|
|
|
|
|
|
|
************************************************ */
|
2006-02-25 11:56:08 +00:00
|
|
|
static pthread_mutex_t _malloc_lock = PTHREAD_MUTEX_INITIALIZER;
|
2006-12-21 15:44:46 +00:00
|
|
|
static pthread_mutex_t _image_lock = PTHREAD_MUTEX_INITIALIZER;
|
2006-03-13 11:01:17 +00:00
|
|
|
static pthread_mutex_t _custom1_lock = PTHREAD_MUTEX_INITIALIZER;
|
2006-11-28 10:16:24 +00:00
|
|
|
static int thread_levels= 0; /* threads can be invoked inside threads */
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
|
|
|
|
/* just a max for security reasons */
|
|
|
|
#define RE_MAX_THREAD 8
|
|
|
|
|
|
|
|
typedef struct ThreadSlot {
|
|
|
|
struct ThreadSlot *next, *prev;
|
2006-02-25 11:56:08 +00:00
|
|
|
void *(*do_thread)(void *);
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
void *callerdata;
|
2006-02-25 11:56:08 +00:00
|
|
|
pthread_t pthread;
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
int avail;
|
|
|
|
} ThreadSlot;
|
|
|
|
|
2007-03-19 15:48:24 +00:00
|
|
|
static void BLI_lock_malloc_thread(void)
|
2006-09-06 19:13:23 +00:00
|
|
|
{
|
|
|
|
pthread_mutex_lock(&_malloc_lock);
|
|
|
|
}
|
|
|
|
|
2007-03-19 15:48:24 +00:00
|
|
|
static void BLI_unlock_malloc_thread(void)
|
2006-09-06 19:13:23 +00:00
|
|
|
{
|
|
|
|
pthread_mutex_unlock(&_malloc_lock);
|
|
|
|
}
|
|
|
|
|
2007-11-25 16:35:33 +00:00
|
|
|
/* tot = 0 only initializes malloc mutex in a safe way (see sequence.c)
|
|
|
|
problem otherwise: scene render will kill of the mutex!
|
|
|
|
*/
|
|
|
|
|
2006-02-25 11:56:08 +00:00
|
|
|
void BLI_init_threads(ListBase *threadbase, void *(*do_thread)(void *), int tot)
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
{
|
|
|
|
int a;
|
|
|
|
|
2007-11-25 16:35:33 +00:00
|
|
|
if(threadbase != NULL && tot > 0) {
|
|
|
|
threadbase->first= threadbase->last= NULL;
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
|
2007-11-25 16:35:33 +00:00
|
|
|
if(tot>RE_MAX_THREAD) tot= RE_MAX_THREAD;
|
|
|
|
else if(tot<1) tot= 1;
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
|
2007-11-25 16:35:33 +00:00
|
|
|
for(a=0; a<tot; a++) {
|
|
|
|
ThreadSlot *tslot= MEM_callocN(sizeof(ThreadSlot), "threadslot");
|
|
|
|
BLI_addtail(threadbase, tslot);
|
|
|
|
tslot->do_thread= do_thread;
|
|
|
|
tslot->avail= 1;
|
|
|
|
}
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
}
|
2006-09-06 19:13:23 +00:00
|
|
|
|
|
|
|
MEM_set_lock_callback(BLI_lock_malloc_thread, BLI_unlock_malloc_thread);
|
2006-11-28 10:16:24 +00:00
|
|
|
thread_levels++;
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* amount of available threads */
|
|
|
|
int BLI_available_threads(ListBase *threadbase)
|
|
|
|
{
|
|
|
|
ThreadSlot *tslot;
|
|
|
|
int counter=0;
|
|
|
|
|
|
|
|
for(tslot= threadbase->first; tslot; tslot= tslot->next) {
|
2006-02-25 11:56:08 +00:00
|
|
|
if(tslot->avail)
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
return counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns thread number, for sample patterns or threadsafe tables */
|
|
|
|
int BLI_available_thread_index(ListBase *threadbase)
|
|
|
|
{
|
|
|
|
ThreadSlot *tslot;
|
|
|
|
int counter=0;
|
|
|
|
|
|
|
|
for(tslot= threadbase->first; tslot; tslot= tslot->next, counter++) {
|
2006-02-25 11:56:08 +00:00
|
|
|
if(tslot->avail)
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
return counter;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BLI_insert_thread(ListBase *threadbase, void *callerdata)
|
|
|
|
{
|
|
|
|
ThreadSlot *tslot;
|
|
|
|
|
|
|
|
for(tslot= threadbase->first; tslot; tslot= tslot->next) {
|
2006-02-25 11:56:08 +00:00
|
|
|
if(tslot->avail) {
|
|
|
|
tslot->avail= 0;
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
tslot->callerdata= callerdata;
|
2006-02-25 11:56:08 +00:00
|
|
|
pthread_create(&tslot->pthread, NULL, tslot->do_thread, tslot->callerdata);
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("ERROR: could not insert thread slot\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void BLI_remove_thread(ListBase *threadbase, void *callerdata)
|
|
|
|
{
|
|
|
|
ThreadSlot *tslot;
|
|
|
|
|
|
|
|
for(tslot= threadbase->first; tslot; tslot= tslot->next) {
|
|
|
|
if(tslot->callerdata==callerdata) {
|
|
|
|
tslot->callerdata= NULL;
|
2006-02-25 11:56:08 +00:00
|
|
|
pthread_join(tslot->pthread, NULL);
|
|
|
|
tslot->avail= 1;
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-14 23:48:52 +00:00
|
|
|
void BLI_remove_thread_index(ListBase *threadbase, int index)
|
|
|
|
{
|
|
|
|
ThreadSlot *tslot;
|
|
|
|
int counter=0;
|
|
|
|
|
|
|
|
for(tslot = threadbase->first; tslot; tslot = tslot->next, counter++) {
|
|
|
|
if (counter == index && tslot->avail == 0) {
|
|
|
|
tslot->callerdata = NULL;
|
|
|
|
pthread_join(tslot->pthread, NULL);
|
|
|
|
tslot->avail = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
void BLI_end_threads(ListBase *threadbase)
|
|
|
|
{
|
|
|
|
ThreadSlot *tslot;
|
|
|
|
|
2007-11-25 16:35:33 +00:00
|
|
|
if (threadbase) {
|
|
|
|
for(tslot= threadbase->first; tslot; tslot= tslot->next) {
|
|
|
|
if(tslot->avail==0) {
|
|
|
|
pthread_join(tslot->pthread, NULL);
|
|
|
|
}
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
}
|
2007-11-25 16:35:33 +00:00
|
|
|
BLI_freelistN(threadbase);
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
}
|
2006-01-30 11:09:50 +00:00
|
|
|
|
2006-11-28 10:16:24 +00:00
|
|
|
thread_levels--;
|
|
|
|
if(thread_levels==0)
|
|
|
|
MEM_set_lock_callback(NULL, NULL);
|
2006-01-30 11:09:50 +00:00
|
|
|
}
|
|
|
|
|
2006-03-13 11:01:17 +00:00
|
|
|
void BLI_lock_thread(int type)
|
2006-02-11 15:55:00 +00:00
|
|
|
{
|
2006-12-21 15:44:46 +00:00
|
|
|
if (type==LOCK_IMAGE)
|
|
|
|
pthread_mutex_lock(&_image_lock);
|
|
|
|
else if (type==LOCK_CUSTOM1)
|
2006-03-13 11:01:17 +00:00
|
|
|
pthread_mutex_lock(&_custom1_lock);
|
2006-02-11 15:55:00 +00:00
|
|
|
}
|
|
|
|
|
2006-03-13 11:01:17 +00:00
|
|
|
void BLI_unlock_thread(int type)
|
2006-02-11 15:55:00 +00:00
|
|
|
{
|
2006-12-21 15:44:46 +00:00
|
|
|
if (type==LOCK_IMAGE)
|
|
|
|
pthread_mutex_unlock(&_image_lock);
|
|
|
|
else if(type==LOCK_CUSTOM1)
|
2006-03-13 11:01:17 +00:00
|
|
|
pthread_mutex_unlock(&_custom1_lock);
|
2006-02-11 15:55:00 +00:00
|
|
|
}
|
|
|
|
|
2008-02-19 22:23:21 +00:00
|
|
|
/* how many threads are native on this system? */
|
|
|
|
int BLI_system_thread_count( void )
|
|
|
|
{
|
2008-02-19 22:59:52 +00:00
|
|
|
int t;
|
|
|
|
#ifdef WIN32
|
|
|
|
SYSTEM_INFO info;
|
|
|
|
GetSystemInfo(&info);
|
|
|
|
t = (int) info.dwNumberOfProcessors;
|
2008-02-20 16:07:42 +00:00
|
|
|
#else
|
|
|
|
# ifdef __APPLE__
|
|
|
|
int mib[2];
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
mib[0] = CTL_HW;
|
|
|
|
mib[1] = HW_NCPU;
|
|
|
|
len = sizeof(t);
|
|
|
|
sysctl(mib, 2, &t, &len, NULL, 0);
|
2008-03-19 22:58:16 +00:00
|
|
|
# elif defined(__sgi)
|
|
|
|
t = sysconf(_SC_NPROC_ONLN);
|
2008-02-20 16:07:42 +00:00
|
|
|
# else
|
2008-02-19 22:59:52 +00:00
|
|
|
t = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
2008-02-20 16:07:42 +00:00
|
|
|
# endif
|
2008-02-19 22:59:52 +00:00
|
|
|
#endif
|
|
|
|
|
2008-02-19 22:23:21 +00:00
|
|
|
if (t>RE_MAX_THREAD)
|
|
|
|
return RE_MAX_THREAD;
|
|
|
|
if (t<1)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2008-08-16 22:47:33 +00:00
|
|
|
/* ************************************************ */
|
|
|
|
|
|
|
|
typedef struct ThreadedWorker {
|
|
|
|
ListBase threadbase;
|
|
|
|
void *(*work_fnct)(void *);
|
|
|
|
char busy[RE_MAX_THREAD];
|
|
|
|
int total;
|
|
|
|
int sleep_time;
|
|
|
|
} ThreadedWorker;
|
|
|
|
|
|
|
|
typedef struct WorkParam {
|
|
|
|
ThreadedWorker *worker;
|
|
|
|
void *param;
|
|
|
|
int index;
|
|
|
|
} WorkParam;
|
|
|
|
|
|
|
|
void *exec_work_fnct(void *v_param)
|
|
|
|
{
|
|
|
|
WorkParam *p = (WorkParam*)v_param;
|
|
|
|
void *value;
|
|
|
|
|
|
|
|
value = p->worker->work_fnct(p->param);
|
|
|
|
|
|
|
|
p->worker->busy[p->index] = 0;
|
|
|
|
MEM_freeN(p);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadedWorker *BLI_create_worker(void *(*do_thread)(void *), int tot, int sleep_time)
|
|
|
|
{
|
|
|
|
ThreadedWorker *worker;
|
|
|
|
|
|
|
|
worker = MEM_callocN(sizeof(ThreadedWorker), "threadedworker");
|
|
|
|
|
|
|
|
if (tot > RE_MAX_THREAD)
|
|
|
|
{
|
|
|
|
tot = RE_MAX_THREAD;
|
|
|
|
}
|
|
|
|
else if (tot < 1)
|
|
|
|
{
|
|
|
|
tot= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
worker->total = tot;
|
|
|
|
worker->work_fnct = do_thread;
|
|
|
|
|
|
|
|
BLI_init_threads(&worker->threadbase, exec_work_fnct, tot);
|
|
|
|
|
|
|
|
return worker;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BLI_end_worker(ThreadedWorker *worker)
|
|
|
|
{
|
|
|
|
BLI_end_threads(&worker->threadbase);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BLI_destroy_worker(ThreadedWorker *worker)
|
|
|
|
{
|
|
|
|
BLI_end_worker(worker);
|
|
|
|
BLI_freelistN(&worker->threadbase);
|
|
|
|
MEM_freeN(worker);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BLI_insert_work(ThreadedWorker *worker, void *param)
|
|
|
|
{
|
|
|
|
WorkParam *p = MEM_callocN(sizeof(WorkParam), "workparam");
|
|
|
|
int index;
|
|
|
|
|
|
|
|
if (BLI_available_threads(&worker->threadbase) == 0)
|
|
|
|
{
|
|
|
|
index = worker->total;
|
|
|
|
while(index == worker->total)
|
|
|
|
{
|
|
|
|
PIL_sleep_ms(worker->sleep_time);
|
|
|
|
|
|
|
|
for (index = 0; index < worker->total; index++)
|
|
|
|
{
|
|
|
|
if (worker->busy[index] == 0)
|
|
|
|
{
|
|
|
|
BLI_remove_thread_index(&worker->threadbase, index);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
index = BLI_available_thread_index(&worker->threadbase);
|
|
|
|
}
|
|
|
|
|
|
|
|
worker->busy[index] = 1;
|
|
|
|
|
|
|
|
p->param = param;
|
|
|
|
p->index = index;
|
|
|
|
p->worker = worker;
|
|
|
|
|
|
|
|
BLI_insert_thread(&worker->threadbase, p);
|
|
|
|
}
|
|
|
|
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
/* eof */
|