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:
authorMiika Hamalainen <blender@miikah.org>2011-10-22 20:16:14 +0400
committerMiika Hamalainen <blender@miikah.org>2011-10-22 20:16:14 +0400
commit30cba27987362054d16b10e73ddf2601af93be68 (patch)
treed971f10db56b5d024cf5f7d6f3d48d1e3c20d698 /source/blender/blenlib
parent8be3249537e7930e0fa5adb59bc343455da309e9 (diff)
Dynamic Paint:
* Some changes and cleanup pointed on the codereview.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_kdtree.h1
-rw-r--r--source/blender/blenlib/BLI_threads.h4
-rw-r--r--source/blender/blenlib/intern/BLI_kdtree.c87
-rw-r--r--source/blender/blenlib/intern/threads.c14
4 files changed, 18 insertions, 88 deletions
diff --git a/source/blender/blenlib/BLI_kdtree.h b/source/blender/blenlib/BLI_kdtree.h
index 532295449e5..c607dae386f 100644
--- a/source/blender/blenlib/BLI_kdtree.h
+++ b/source/blender/blenlib/BLI_kdtree.h
@@ -65,6 +65,5 @@ int BLI_kdtree_find_n_nearest(KDTree *tree, int n, float *co, float *nor, KDTree
/* Normal is optional, but if given will limit results to points in normal direction from co. */
/* Remember to free nearest after use! */
int BLI_kdtree_range_search(KDTree *tree, float range, float *co, float *nor, KDTreeNearest **nearest);
-int BLI_kdtree_range_search_thread_safe(KDTree *tree, float range, float *co, float *nor, KDTreeNearest *nearest, int limit);
#endif
diff --git a/source/blender/blenlib/BLI_threads.h b/source/blender/blenlib/BLI_threads.h
index 5bf5423d312..94ed7af6a2c 100644
--- a/source/blender/blenlib/BLI_threads.h
+++ b/source/blender/blenlib/BLI_threads.h
@@ -57,6 +57,10 @@ void BLI_remove_threads(struct ListBase *threadbase);
void BLI_end_threads (struct ListBase *threadbase);
int BLI_thread_is_main(void);
+
+void BLI_begin_threaded_malloc(void);
+void BLI_end_threaded_malloc(void);
+
/* System Information */
int BLI_system_thread_count(void); /* gets the number of threads the system can make use of */
diff --git a/source/blender/blenlib/intern/BLI_kdtree.c b/source/blender/blenlib/intern/BLI_kdtree.c
index 79afd9c7a60..9e61778a59b 100644
--- a/source/blender/blenlib/intern/BLI_kdtree.c
+++ b/source/blender/blenlib/intern/BLI_kdtree.c
@@ -449,91 +449,4 @@ int BLI_kdtree_range_search(KDTree *tree, float range, float *co, float *nor, KD
*nearest = foundstack;
return found;
-}
-
-
-static int add_in_range_thread_safe(KDTreeNearest *ptn, int found, int *totfoundstack, int index, float dist, float *co)
-{
- KDTreeNearest *to;
-
- if(found+1 > *totfoundstack)
- return 0;
-
- to = ptn + found;
-
- to->index = index;
- to->dist = sqrt(dist);
- copy_v3_v3(to->co, co);
- return 1;
-}
-int BLI_kdtree_range_search_thread_safe(KDTree *tree, float range, float *co, float *nor, KDTreeNearest *nearest, int limit)
-{
- KDTreeNode *root, *node= NULL;
- KDTreeNode **stack, *defaultstack[500];
- KDTreeNearest *foundstack=nearest;
- float range2 = range*range, dist2;
- int totstack, cur=0, found=0;
-
- if(!tree || !tree->root)
- return 0;
-
- stack= defaultstack;
- totstack= 500;
-
- root= tree->root;
-
- if(co[root->d] + range < root->co[root->d]) {
- if(root->left)
- stack[cur++]=root->left;
- }
- else if(co[root->d] - range > root->co[root->d]) {
- if(root->right)
- stack[cur++]=root->right;
- }
- else {
- dist2 = squared_distance(root->co, co, root->nor, nor);
- if(dist2 <= range2)
- add_in_range_thread_safe(foundstack, found++, &limit, root->index, dist2, root->co);
-
- if(root->left)
- stack[cur++]=root->left;
- if(root->right)
- stack[cur++]=root->right;
- }
-
- while(cur--) {
- node=stack[cur];
-
- if(co[node->d] + range < node->co[node->d]) {
- if(node->left)
- stack[cur++]=node->left;
- }
- else if(co[node->d] - range > node->co[node->d]) {
- if(node->right)
- stack[cur++]=node->right;
- }
- else {
- dist2 = squared_distance(node->co, co, node->nor, nor);
- if(dist2 <= range2)
- if (!add_in_range_thread_safe(foundstack, found++, &limit, node->index, dist2, node->co))
- break;
-
- if(node->left)
- stack[cur++]=node->left;
- if(node->right)
- stack[cur++]=node->right;
- }
-
- /* abort if running out of stack */
- if(cur+3 > totstack)
- break;
- }
-
- if(stack != defaultstack)
- MEM_freeN(stack);
-
- if(found)
- qsort(foundstack, found, sizeof(KDTreeNearest), range_compare);
-
- return found;
} \ No newline at end of file
diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c
index 097ad2bcd74..b4923169179 100644
--- a/source/blender/blenlib/intern/threads.c
+++ b/source/blender/blenlib/intern/threads.c
@@ -660,3 +660,17 @@ void BLI_thread_queue_nowait(ThreadQueue *queue)
pthread_mutex_unlock(&queue->mutex);
}
+void BLI_begin_threaded_malloc(void)
+{
+ if(thread_levels == 0) {
+ MEM_set_lock_callback(BLI_lock_malloc_thread, BLI_unlock_malloc_thread);
+ }
+ thread_levels++;
+}
+
+void BLI_end_threaded_malloc(void)
+{
+ thread_levels--;
+ if(thread_levels==0)
+ MEM_set_lock_callback(NULL, NULL);
+} \ No newline at end of file