Commit af33e8450f92ece65591ab04c028a9a495d098d4

Authored by Georg Hopp
1 parent 2f3a24d9

Revert "try to make code more thread save"

This reverts commit 2f3a24d9.
... ... @@ -37,16 +37,16 @@ TR_CLASS(TR_Hash) {
37 37 TR_INSTANCE_INIT(TR_Hash);
38 38 TR_CLASSVARS_DECL(TR_Hash) {};
39 39
40   -//#define TR_hashEmpty(hash) (NULL == (hash)->tree->root)
41   -
42   -void * TR_hashAdd(TR_Hash, void *);
43   -void * TR_hashDelete(TR_Hash, const char *, size_t);
44   -void * TR_hashGet(TR_Hash, const char *, size_t);
45   -void * TR_hashGetFirst(TR_Hash);
46   -void * TR_hashDeleteByVal(TR_Hash, unsigned long);
47   -void * TR_hashGetByVal(TR_Hash, unsigned long);
48   -unsigned long TR_hashEach(TR_Hash, const void *, void (*)(const void *, const void *));
49   -void TR_hashCleanup(TR_Hash);
  40 +#define TR_hashEmpty(hash) (NULL == (hash)->tree->root)
  41 +
  42 +void * TR_hashAdd(TR_Hash, void *);
  43 +void * TR_hashDelete(TR_Hash, const char *, size_t);
  44 +void * TR_hashGet(TR_Hash, const char *, size_t);
  45 +void * TR_hashGetFirst(TR_Hash);
  46 +void * TR_hashDeleteByVal(TR_Hash, unsigned long);
  47 +void * TR_hashGetByVal(TR_Hash, unsigned long);
  48 +void TR_hashEach(TR_Hash, const void *, void (*)(const void *, const void *));
  49 +void TR_hashCleanup(TR_Hash);
50 50
51 51 #endif // __TR_HASH_H__
52 52
... ...
... ... @@ -50,11 +50,11 @@ TR_CLASSVARS_DECL(TR_Tree) {};
50 50 typedef int (*TR_TreeComp)(const void *, const void *);
51 51 typedef void (*TR_TreeAction)(const void *, const void *, const int);
52 52
53   -void * TR_treeFind(TR_Tree, const void *, TR_TreeComp);
54   -void * TR_treeInsert(TR_Tree, const void *, TR_TreeComp);
55   -void * TR_treeDelete(TR_Tree, const void *, TR_TreeComp);
56   -unsigned long TR_treeWalk(TR_Tree, const void *, TR_TreeAction);
57   -void TR_treeDestroy(TR_Tree, TR_TreeAction);
  53 +void * TR_treeFind(TR_Tree, const void *, TR_TreeComp);
  54 +void * TR_treeInsert(TR_Tree, const void *, TR_TreeComp);
  55 +void * TR_treeDelete(TR_Tree, const void *, TR_TreeComp);
  56 +void TR_treeWalk(TR_Tree, const void *, TR_TreeAction);
  57 +void TR_treeDestroy(TR_Tree, TR_TreeAction);
58 58
59 59 #endif // __TR_TREE_H__
60 60
... ...
... ... @@ -34,7 +34,7 @@ walk(const void * node, const void * data, const int depth)
34 34 cb(node, data);
35 35 }
36 36
37   -unsigned long
  37 +void
38 38 TR_hashEach(
39 39 TR_Hash this,
40 40 const void * data,
... ... @@ -42,7 +42,7 @@ TR_hashEach(
42 42 {
43 43 cb = callback;
44 44
45   - return TR_treeWalk(this->tree, data, walk);
  45 + TR_treeWalk(this->tree, data, walk);
46 46 }
47 47
48 48 // vim: set ts=4 sw=4:
... ...
... ... @@ -29,12 +29,10 @@
29 29 void
30 30 TR_queueDestroy(TR_Queue this)
31 31 {
32   - TR_Queue node;
  32 + TR_Queue node = this->first;
33 33
34 34 pthread_mutex_lock(&(this->lock));
35 35
36   - node = this->first;
37   -
38 36 while (NULL != node) {
39 37 TR_Queue next = node->next;
40 38 if (this->free_msgs) {
... ...
... ... @@ -20,8 +20,6 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#include <pthread.h>
24   -
25 23 #include "trbase.h"
26 24 #include "tr/queue.h"
27 25
... ... @@ -30,9 +28,7 @@ TR_queueFind(TR_Queue this, void * msg)
30 28 {
31 29 TR_Queue node;
32 30
33   - pthread_mutex_lock(&(this->lock));
34 31 for (node = this->first; node && node->msg != msg; node = node->next);
35   - pthread_mutex_unlock(&(this->lock));
36 32
37 33 return node;
38 34 }
... ...
... ... @@ -20,8 +20,6 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#include <pthread.h>
24   -
25 23 #include "trbase.h"
26 24 #include "tr/queue.h"
27 25
... ... @@ -30,9 +28,7 @@ TR_queueFindParent(TR_Queue this, void * msg)
30 28 {
31 29 TR_Queue node;
32 30
33   - pthread_mutex_lock(&(this->lock));
34 31 for (node = this; node->next && node->next->msg != msg; node = node->next);
35   - pthread_mutex_unlock(&(this->lock));
36 32
37 33 return node->next ? node : NULL;
38 34 }
... ...
... ... @@ -28,12 +28,10 @@
28 28 void
29 29 TR_queuePut(TR_Queue this, void * msg)
30 30 {
31   - TR_Queue node;
  31 + TR_Queue node = (this->last)? this->last : this;
32 32
33 33 pthread_mutex_lock(&(this->lock));
34 34
35   - node = (this->last)? this->last : this;
36   -
37 35 node->next = TR_new(TR_Queue);
38 36 this->last = node->next;
39 37
... ...
... ... @@ -28,12 +28,10 @@
28 28 void
29 29 TR_queuePutFirst(TR_Queue this, void * msg)
30 30 {
31   - TR_Queue current_first;
  31 + TR_Queue current_first = this->first;
32 32
33 33 pthread_mutex_lock(&(this->lock));
34 34
35   - current_first = this->first;
36   -
37 35 this->first = this->next = TR_new(TR_Queue);
38 36 this->first->next = current_first;
39 37 this->first->msg = msg;
... ...
... ... @@ -28,7 +28,7 @@
28 28 void *
29 29 TR_treeDelete(TR_Tree this, const void * search, TR_TreeComp comp)
30 30 {
31   - TR_TreeNode node;
  31 + TR_TreeNode node = this->root;
32 32 TR_TreeNode del_node;
33 33 TR_TreeNode sibling;
34 34 int found;
... ... @@ -36,8 +36,6 @@ TR_treeDelete(TR_Tree this, const void * search, TR_TreeComp comp)
36 36
37 37 pthread_mutex_lock(&(this->lock));
38 38
39   - node = this->root;
40   -
41 39 TR_TREE_FIND(node, search, found, comp);
42 40
43 41 /*
... ...
... ... @@ -26,15 +26,10 @@
26 26 void
27 27 TR_treeDestroy(TR_Tree this, TR_TreeAction action)
28 28 {
29   - TR_TreeNode previous;
30   - TR_TreeNode node;
31   - int depth = 1;
  29 + TR_TreeNode previous = this->root;
  30 + TR_TreeNode node = this->root;
  31 + int depth = 1;
32 32
33   - pthread_mutex_lock(&(this->lock));
34   -
35   - previous = this->root;
36   - node = this->root;
37   -
38 33 /*
39 34 * I think this has something like O(n+log(n)) on a ballanced
40 35 * tree because I have to traverse back the rightmost leaf to
... ... @@ -88,8 +83,6 @@ TR_treeDestroy(TR_Tree this, TR_TreeAction action)
88 83 }
89 84
90 85 this->root = NULL;
91   -
92   - pthread_mutex_unlock(&(this->lock));
93 86 }
94 87
95 88 // vim: set ts=4 sw=4:
... ...
... ... @@ -25,19 +25,16 @@
25 25 void *
26 26 TR_treeFind(TR_Tree this, const void * search, TR_TreeComp comp)
27 27 {
28   - int found;
29   - TR_TreeNode node;
30   - void * retval;
  28 + int found;
  29 + TR_TreeNode node = this->root;
31 30
32 31 pthread_mutex_lock(&(this->lock));
33 32
34   - node = this->root;
35 33 TR_TREE_FIND(node, search, found, comp);
36   - retval = found == 0 ? node->data : NULL;
37 34
38 35 pthread_mutex_unlock(&(this->lock));
39 36
40   - return retval;
  37 + return found == 0 ? node->data : NULL;
41 38 }
42 39
43 40 // vim: set ts=4 sw=4:
... ...
... ... @@ -28,15 +28,12 @@
28 28 void *
29 29 TR_treeInsert(TR_Tree this, const void * search, TR_TreeComp comp)
30 30 {
31   - TR_TreeNode new_node = NULL;
32   - TR_TreeNode node;
33   - int found;
34   - void * retval;
  31 + TR_TreeNode node = this->root;
  32 + TR_TreeNode new_node = NULL;
  33 + int found;
35 34
36 35 pthread_mutex_lock(&(this->lock));
37 36
38   - node = this->root;
39   -
40 37 /*
41 38 * insert the node or return the one in tree if comparison
42 39 * succeeds.
... ... @@ -80,11 +77,10 @@ TR_treeInsert(TR_Tree this, const void * search, TR_TreeComp comp)
80 77 * new node at this point...now rabalance the tree
81 78 */
82 79 TR_TREE_BALANCE_INSERT(&(this->root), node);
83   - retval = new_node->data;
84 80
85 81 pthread_mutex_unlock(&(this->lock));
86 82
87   - return retval;
  83 + return new_node->data;
88 84 }
89 85
90 86 // vim: set ts=4 sw=4:
... ...
... ... @@ -20,22 +20,14 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#include <pthread.h>
24   -
25 23 #include "tr/tree.h"
26 24
27   -unsigned long
  25 +void
28 26 TR_treeWalk(TR_Tree this, const void * data, TR_TreeAction action)
29 27 {
30   - TR_TreeNode previous;
31   - TR_TreeNode node;
32   - int depth = 1;
33   - unsigned long processed = 0;
34   -
35   - pthread_mutex_lock(&(this->lock));
36   -
37   - previous = this->root;
38   - node = this->root;
  28 + TR_TreeNode previous = this->root;
  29 + TR_TreeNode node = this->root;
  30 + int depth = 1;
39 31
40 32 while (NULL != node) {
41 33 if (previous == TR_TREE_RIGHT(node)) {
... ... @@ -48,7 +40,6 @@ TR_treeWalk(TR_Tree this, const void * data, TR_TreeAction action)
48 40 if (NULL == TR_TREE_LEFT(node) || previous == TR_TREE_LEFT(node)) {
49 41 if (action) {
50 42 action(node->data, data, depth);
51   - processed++;
52 43 }
53 44 previous = node;
54 45
... ... @@ -65,10 +56,6 @@ TR_treeWalk(TR_Tree this, const void * data, TR_TreeAction action)
65 56 depth++;
66 57 }
67 58 }
68   -
69   - pthread_mutex_unlock(&(this->lock));
70   -
71   - return processed;
72 59 }
73 60
74 61 // vim: set ts=4 sw=4:
... ...
Please register or login to post a comment