crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs | LICENSE

nodelock.cc (1091B)


      1 #include "mutextree"
      2 #include "config/config"
      3 
      4 MutexNode *MutexTree::nodelock(void *o, MutexNode *start) {
      5 
      6     // No tree start yet? Create one.
      7     if (!start) {
      8 #	ifdef DEBUG
      9 	debugmsg("Mutex nodelock: new node for " << o <<", locking now\n");
     10 #	endif	
     11         start = new MutexNode(o);
     12 	start->lock();
     13 #	ifdef DEBUG
     14 	debugmsg("Mutex nodelock: new node for " << o <<" locked\n");
     15 #	endif	
     16 	return start;
     17     }
     18 
     19     // At object? Dive into the Mutexnode.
     20     if (start->obj() == o) {
     21 #	ifdef DEBUG
     22 	debugmsg("Mutex nodelock: existing node for " << o <<
     23 		 ", locking now\n");
     24 #	endif	
     25 	start->lock();
     26 #	ifdef DEBUG
     27 	debugmsg("Mutex nodelock: existing node for " << o << " locked\n");
     28 #	endif	
     29 	return start;
     30     }
     31 
     32     // Decide whether to recurse left or right.
     33     if (start->obj() < o) {
     34 #	ifdef DEBUG
     35 	debugmsg("Mutex nodelock: going left for " << o << '\n');
     36 #	endif	
     37         start->left(nodelock(o, start->left()));
     38     } else {
     39 #	ifdef DEBUG
     40 	debugmsg("Mutex nodelock: going right for " << o << '\n');
     41 #	endif	
     42 	start->right(nodelock(o, start->right()));
     43     }	
     44     return start;
     45 }