5 * ***** BEGIN GPL LICENSE BLOCK *****
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * The Original Code is Copyright (C) 2006 Blender Foundation.
22 * All rights reserved.
24 * The Original Code is: all of this file.
26 * Contributor(s): none yet.
28 * ***** END GPL LICENSE BLOCK *****
34 /* one custom lock available now. can be extended */
36 #define LOCK_CUSTOM1 1
38 /* for tables, button in UI, etc */
39 #define BLENDER_MAX_THREADS 8
42 void BLI_init_threads (struct ListBase *threadbase, void *(*do_thread)(void *), int tot);
43 int BLI_available_threads(struct ListBase *threadbase);
44 int BLI_available_thread_index(struct ListBase *threadbase);
45 void BLI_insert_thread (struct ListBase *threadbase, void *callerdata);
46 void BLI_remove_thread (struct ListBase *threadbase, void *callerdata);
47 void BLI_remove_thread_index(struct ListBase *threadbase, int index);
48 void BLI_remove_threads(struct ListBase *threadbase);
49 void BLI_end_threads (struct ListBase *threadbase);
51 void BLI_lock_thread (int type);
52 void BLI_unlock_thread (int type);
54 int BLI_system_thread_count( void ); /* gets the number of threads the system can make use of */
56 /* exported by preview render, it has to ensure render buffers are not freed while draw */
57 void BLI_lock_malloc_thread(void);
58 void BLI_unlock_malloc_thread(void);
60 /* ThreadedWorker is a simple tool for dispatching work to a limited number of threads in a transparent
61 * fashion from the caller's perspective
64 struct ThreadedWorker;
66 /* Create a new worker supporting tot parallel threads.
67 * When new work in inserted and all threads are busy, sleep(sleep_time) before checking again
69 struct ThreadedWorker *BLI_create_worker(void *(*do_thread)(void *), int tot, int sleep_time);
71 /* join all working threads */
72 void BLI_end_worker(struct ThreadedWorker *worker);
74 /* also ends all working threads */
75 void BLI_destroy_worker(struct ThreadedWorker *worker);
77 /* Spawns a new work thread if possible, sleeps until one is available otherwise
78 * NOTE: inserting work is NOT thread safe, so make sure it is only done from one thread */
79 void BLI_insert_work(struct ThreadedWorker *worker, void *param);