Index: libcfa/src/concurrency/locks.cfa
===================================================================
--- libcfa/src/concurrency/locks.cfa	(revision b93bf851cd2f4c65993fbbd554e9a71949aa906d)
+++ libcfa/src/concurrency/locks.cfa	(revision 38e17b075cc18efa0ede32a63ca235bf8f4b3072)
@@ -79,10 +79,10 @@
 	// lock is held by some other thread
 	if ( owner != 0p && owner != thrd ) {
-        select_node node;
+		select_node node;
 		insert_last( blocked_threads, node );
 		wait_count++;
 		unlock( lock );
 		park( );
-        return;
+		return;
 	} else if ( owner == thrd && multi_acquisition ) { // multi acquisition lock is held by current thread
 		recursion_count++;
@@ -91,5 +91,5 @@
 		recursion_count = 1;
 	}
-    unlock( lock );
+	unlock( lock );
 }
 
@@ -115,16 +115,16 @@
 
 static inline void pop_node( blocking_lock & this ) with( this ) {
-    __handle_waituntil_OR( blocked_threads );
-    select_node * node = &try_pop_front( blocked_threads );
-    if ( node ) {
-        wait_count--;
-        owner = node->blocked_thread;
-        recursion_count = 1;
-        // if ( !node->clause_status || __make_select_node_available( *node ) ) unpark( node->blocked_thread );
-        wake_one( blocked_threads, *node );
-    } else {
-        owner = 0p;
-        recursion_count = 0;
-    }
+	__handle_waituntil_OR( blocked_threads );
+	select_node * node = &remove_first( blocked_threads );
+	if ( node ) {
+		wait_count--;
+		owner = node->blocked_thread;
+		recursion_count = 1;
+		// if ( !node->clause_status || __make_select_node_available( *node ) ) unpark( node->blocked_thread );
+		wake_one( blocked_threads, *node );
+	} else {
+		owner = 0p;
+		recursion_count = 0;
+	}
 }
 
@@ -160,5 +160,5 @@
 		unpark( t );
 	}
-    unlock( lock );
+	unlock( lock );
 }
 
@@ -172,9 +172,9 @@
 	pop_node( this );
 
-    select_node node;
-    active_thread()->link_node = (void *)&node;
-	unlock( lock );
-
-    pre_park_then_park( pp_fn, pp_datum );
+	select_node node;
+	active_thread()->link_node = (void *)&node;
+	unlock( lock );
+
+	pre_park_then_park( pp_fn, pp_datum );
 
 	return ret;
@@ -187,5 +187,5 @@
 // waituntil() support
 bool register_select( blocking_lock & this, select_node & node ) with(this) {
-    lock( lock __cfaabi_dbg_ctx2 );
+	lock( lock __cfaabi_dbg_ctx2 );
 	thread$ * thrd = active_thread();
 
@@ -193,10 +193,10 @@
 	/* paranoid */ verifyf( owner != thrd || multi_acquisition, "Single acquisition lock holder (%p) attempted to reacquire the lock %p resulting in a deadlock.", owner, &this );
 
-    if ( !node.park_counter && ( (owner == thrd && multi_acquisition) || owner == 0p ) ) { // OR special case
-        if ( !__make_select_node_available( node ) ) { // we didn't win the race so give up on registering
-           unlock( lock );
-           return false;
-        }
-    }
+	if ( !node.park_counter && ( (owner == thrd && multi_acquisition) || owner == 0p ) ) { // OR special case
+		if ( !__make_select_node_available( node ) ) { // we didn't win the race so give up on registering
+			unlock( lock );
+			return false;
+		}
+	}
 
 	// lock is held by some other thread
@@ -205,5 +205,5 @@
 		wait_count++;
 		unlock( lock );
-        return false;
+		return false;
 	} else if ( owner == thrd && multi_acquisition ) { // multi acquisition lock is held by current thread
 		recursion_count++;
@@ -213,28 +213,28 @@
 	}
 
-    if ( node.park_counter ) __make_select_node_available( node );
-    unlock( lock );
-    return true;
+	if ( node.park_counter ) __make_select_node_available( node );
+	unlock( lock );
+	return true;
 }
 
 bool unregister_select( blocking_lock & this, select_node & node ) with(this) {
-    lock( lock __cfaabi_dbg_ctx2 );
-    if ( node`isListed ) {
-        remove( node );
-        wait_count--;
-        unlock( lock );
-        return false;
-    }
-    
-    if ( owner == active_thread() ) {
-        /* paranoid */ verifyf( recursion_count == 1 || multi_acquisition, "Thread %p attempted to unlock owner lock %p in waituntil unregister, which is not recursive but has a recursive count of %zu", active_thread(), &this, recursion_count );
-        // if recursion count is zero release lock and set new owner if one is waiting
-        recursion_count--;
-        if ( recursion_count == 0 ) {
-            pop_node( this );
-        }
-    }
-	unlock( lock );
-    return false;
+	lock( lock __cfaabi_dbg_ctx2 );
+	if ( isListed( node ) ) {
+		remove( node );
+		wait_count--;
+		unlock( lock );
+		return false;
+	}
+	
+	if ( owner == active_thread() ) {
+		/* paranoid */ verifyf( recursion_count == 1 || multi_acquisition, "Thread %p attempted to unlock owner lock %p in waituntil unregister, which is not recursive but has a recursive count of %zu", active_thread(), &this, recursion_count );
+		// if recursion count is zero release lock and set new owner if one is waiting
+		recursion_count--;
+		if ( recursion_count == 0 ) {
+			pop_node( this );
+		}
+	}
+	unlock( lock );
+	return false;
 }
 
@@ -265,10 +265,10 @@
 		// 	may still be called after a thread has been removed from the queue but
 		// 	before the alarm is unregistered
-		if ( (*info_thd)`isListed ) {	// is thread on queue
+		if ( isListed( *info_thd ) ) {					// is thread on queue
 			info_thd->signalled = false;
 			// remove this thread O(1)
 			remove( *info_thd );
 			cond->count--;
-			if( info_thd->lock ) {
+			if ( info_thd->lock ) {
 				// call lock's on_notify if a lock was passed
 				on_notify(*info_thd->lock, info_thd->t);
@@ -304,5 +304,5 @@
 		// 	may still be called after a thread has been removed from the queue but
 		// 	before the alarm is unregistered
-		if ( (*info_thd)`isListed ) {	// is thread on queue
+		if ( isListed( *info_thd ) ) {					// is thread on queue
 			info_thd->signalled = false;
 			// remove this thread O(1)
@@ -332,5 +332,5 @@
 
 	static void process_popped( condition_variable(L) & this, info_thread(L) & popped ) with( this ) {
-		if(&popped != 0p) {
+		if (&popped != 0p) {
 			popped.signalled = true;
 			count--;
@@ -347,6 +347,6 @@
 	bool notify_one( condition_variable(L) & this ) with( this ) {
 		lock( lock __cfaabi_dbg_ctx2 );
-		bool ret = ! blocked_threads`isEmpty;
-		process_popped(this, try_pop_front( blocked_threads ));
+		bool ret = ! isEmpty( blocked_threads );
+		process_popped(this, remove_first( blocked_threads ));
 		unlock( lock );
 		return ret;
@@ -355,7 +355,7 @@
 	bool notify_all( condition_variable(L) & this ) with(this) {
 		lock( lock __cfaabi_dbg_ctx2 );
-		bool ret = ! blocked_threads`isEmpty;
-		while( ! blocked_threads`isEmpty ) {
-			process_popped(this, try_pop_front( blocked_threads ));
+		bool ret = ! isEmpty( blocked_threads );
+		while( ! isEmpty( blocked_threads ) ) {
+			process_popped(this, remove_first( blocked_threads ));
 		}
 		unlock( lock );
@@ -364,10 +364,10 @@
 
 	uintptr_t front( condition_variable(L) & this ) with(this) {
-		return blocked_threads`isEmpty ? NULL : blocked_threads`first.info;
+		return isEmpty( blocked_threads ) ? NULL : first( blocked_threads ).info;
 	}
 
 	bool empty( condition_variable(L) & this ) with(this) {
 		lock( lock __cfaabi_dbg_ctx2 );
-		bool ret = blocked_threads`isEmpty;
+		bool ret = isEmpty( blocked_threads );
 		unlock( lock );
 		return ret;
@@ -382,22 +382,22 @@
 	}
 
-    static size_t block_and_get_recursion( info_thread(L) & i, __cfa_pre_park pp_fn, void * pp_datum ) {
-        size_t recursion_count = 0;
+	static size_t block_and_get_recursion( info_thread(L) & i, __cfa_pre_park pp_fn, void * pp_datum ) {
+		size_t recursion_count = 0;
 		if ( i.lock ) // if lock was passed get recursion count to reset to after waking thread
 			recursion_count = on_wait( *i.lock, pp_fn, pp_datum ); // this call blocks
 		else
-            pre_park_then_park( pp_fn, pp_datum );
-        return recursion_count;
-    }
-    static size_t block_and_get_recursion( info_thread(L) & i ) { return block_and_get_recursion( i, pre_park_noop, 0p ); }
+			pre_park_then_park( pp_fn, pp_datum );
+		return recursion_count;
+	}
+	static size_t block_and_get_recursion( info_thread(L) & i ) { return block_and_get_recursion( i, pre_park_noop, 0p ); }
 
 	// helper for wait()'s' with no timeout
 	static void queue_info_thread( condition_variable(L) & this, info_thread(L) & i ) with(this) {
 		lock( lock __cfaabi_dbg_ctx2 );
-        enqueue_thread( this, &i );
+		enqueue_thread( this, &i );
 		unlock( lock );
 
 		// blocks here
-        size_t recursion_count = block_and_get_recursion( i );
+		size_t recursion_count = block_and_get_recursion( i );
 
 		// resets recursion count here after waking
@@ -409,15 +409,15 @@
 		queue_info_thread( this, i );
 
-    static void cond_alarm_register( void * node_ptr ) { register_self( (alarm_node_t *)node_ptr ); }
+	static void cond_alarm_register( void * node_ptr ) { register_self( (alarm_node_t *)node_ptr ); }
 
 	// helper for wait()'s' with a timeout
 	static void queue_info_thread_timeout( condition_variable(L) & this, info_thread(L) & info, Duration t, Alarm_Callback callback ) with(this) {
 		lock( lock __cfaabi_dbg_ctx2 );
-        enqueue_thread( this, &info );
+		enqueue_thread( this, &info );
 		alarm_node_wrap(L) node_wrap = { t, 0`s, callback, &this, &info };
 		unlock( lock );
 
 		// blocks here and registers alarm node before blocking after releasing locks to avoid deadlock
-        size_t recursion_count = block_and_get_recursion( info, cond_alarm_register, (void *)(&node_wrap.alarm_node) );
+		size_t recursion_count = block_and_get_recursion( info, cond_alarm_register, (void *)(&node_wrap.alarm_node) );
 		// park();
 
@@ -434,17 +434,17 @@
 		return i.signalled;
 
-	void wait( condition_variable(L) & this                        ) with(this) { WAIT( 0, 0p    ) }
-	void wait( condition_variable(L) & this, uintptr_t info        ) with(this) { WAIT( info, 0p ) }
-	void wait( condition_variable(L) & this, L & l                 ) with(this) { WAIT( 0, &l    ) }
+	void wait( condition_variable(L) & this ) with(this) { WAIT( 0, 0p ) }
+	void wait( condition_variable(L) & this, uintptr_t info ) with(this) { WAIT( info, 0p ) }
+	void wait( condition_variable(L) & this, L & l  ) with(this) { WAIT( 0, &l ) }
 	void wait( condition_variable(L) & this, L & l, uintptr_t info ) with(this) { WAIT( info, &l ) }
 
-	bool wait( condition_variable(L) & this, Duration duration                        ) with(this) { WAIT_TIME( 0   , 0p , duration ) }
-	bool wait( condition_variable(L) & this, uintptr_t info, Duration duration        ) with(this) { WAIT_TIME( info, 0p , duration ) }
-	bool wait( condition_variable(L) & this, L & l, Duration duration                 ) with(this) { WAIT_TIME( 0   , &l , duration ) }
+	bool wait( condition_variable(L) & this, Duration duration ) with(this) { WAIT_TIME( 0 , 0p , duration ) }
+	bool wait( condition_variable(L) & this, uintptr_t info, Duration duration ) with(this) { WAIT_TIME( info, 0p , duration ) }
+	bool wait( condition_variable(L) & this, L & l, Duration duration  ) with(this) { WAIT_TIME( 0 , &l , duration ) }
 	bool wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration ) with(this) { WAIT_TIME( info, &l , duration ) }
 
 	//-----------------------------------------------------------------------------
 	// fast_cond_var
-	void  ?{}( fast_cond_var(L) & this ){
+	void ?{}( fast_cond_var(L) & this ){
 		this.blocked_threads{};
 		#ifdef __CFA_DEBUG__
@@ -455,7 +455,7 @@
 
 	bool notify_one( fast_cond_var(L) & this ) with(this) {
-		bool ret = ! blocked_threads`isEmpty;
+		bool ret = ! isEmpty( blocked_threads );
 		if ( ret ) {
-			info_thread(L) & popped = try_pop_front( blocked_threads );
+			info_thread(L) & popped = remove_first( blocked_threads );
 			on_notify(*popped.lock, popped.t);
 		}
@@ -463,7 +463,7 @@
 	}
 	bool notify_all( fast_cond_var(L) & this ) with(this) {
-		bool ret = ! blocked_threads`isEmpty;
-		while( ! blocked_threads`isEmpty ) {
-			info_thread(L) & popped = try_pop_front( blocked_threads );
+		bool ret = ! isEmpty( blocked_threads );
+		while( ! isEmpty( blocked_threads ) ) {
+			info_thread(L) & popped = remove_first( blocked_threads );
 			on_notify(*popped.lock, popped.t);
 		}
@@ -471,6 +471,6 @@
 	}
 
-	uintptr_t front( fast_cond_var(L) & this ) with(this) { return blocked_threads`isEmpty ? NULL : blocked_threads`first.info; }
-	bool empty ( fast_cond_var(L) & this ) with(this) { return blocked_threads`isEmpty; }
+	uintptr_t front( fast_cond_var(L) & this ) with(this) { return isEmpty( blocked_threads ) ? NULL : first( blocked_threads ).info; }
+	bool empty ( fast_cond_var(L) & this ) with(this) { return isEmpty( blocked_threads ); }
 
 	void wait( fast_cond_var(L) & this, L & l ) {
@@ -494,5 +494,5 @@
 	// pthread_cond_var
 
-	void  ?{}( pthread_cond_var(L) & this ) with(this) {
+	void ?{}( pthread_cond_var(L) & this ) with(this) {
 		blocked_threads{};
 		lock{};
@@ -503,7 +503,7 @@
 	bool notify_one( pthread_cond_var(L) & this ) with(this) { 
 		lock( lock __cfaabi_dbg_ctx2 );
-		bool ret = ! blocked_threads`isEmpty;
+		bool ret = ! isEmpty( blocked_threads );
 		if ( ret ) {
-			info_thread(L) & popped = try_pop_front( blocked_threads );
+			info_thread(L) & popped = remove_first( blocked_threads );
 			popped.signalled = true;
 			on_notify(*popped.lock, popped.t);
@@ -515,7 +515,7 @@
 	bool notify_all( pthread_cond_var(L) & this ) with(this) { 
 		lock( lock __cfaabi_dbg_ctx2 );
-		bool ret = ! blocked_threads`isEmpty;
-		while( ! blocked_threads`isEmpty ) {
-			info_thread(L) & popped = try_pop_front( blocked_threads );
+		bool ret = ! isEmpty( blocked_threads );
+		while( ! isEmpty( blocked_threads ) ) {
+			info_thread(L) & popped = remove_first( blocked_threads );
 			popped.signalled = true;
 			on_notify(*popped.lock, popped.t);
@@ -525,15 +525,15 @@
 	}
 
-	uintptr_t front( pthread_cond_var(L) & this ) with(this) { return blocked_threads`isEmpty ? NULL : blocked_threads`first.info; }
-	bool empty ( pthread_cond_var(L) & this ) with(this) { return blocked_threads`isEmpty; }
+	uintptr_t front( pthread_cond_var(L) & this ) with(this) { return isEmpty( blocked_threads ) ? NULL : first( blocked_threads ).info; }
+	bool empty ( pthread_cond_var(L) & this ) with(this) { return isEmpty( blocked_threads ); }
 
 	static void queue_info_thread_timeout( pthread_cond_var(L) & this, info_thread(L) & info, Duration t, Alarm_Callback callback ) with(this) {
 		lock( lock __cfaabi_dbg_ctx2 );
-        insert_last( blocked_threads, info );
+		insert_last( blocked_threads, info );
 		pthread_alarm_node_wrap(L) node_wrap = { t, 0`s, callback, &this, &info };
 		unlock( lock );
 
 		// blocks here and registers alarm node before blocking after releasing locks to avoid deadlock
-        size_t recursion_count = block_and_get_recursion( info, cond_alarm_register, (void *)(&node_wrap.alarm_node) );
+		size_t recursion_count = block_and_get_recursion( info, cond_alarm_register, (void *)(&node_wrap.alarm_node) );
 
 		// unregisters alarm so it doesn't go off if signal happens first
@@ -551,8 +551,8 @@
 		lock( lock __cfaabi_dbg_ctx2 );
 		info_thread( L ) i = { active_thread(), info, &l };
-        insert_last( blocked_threads, i );
-		unlock( lock );
-
-        // blocks here
+		insert_last( blocked_threads, i );
+		unlock( lock );
+
+		// blocks here
 		size_t recursion_count = block_and_get_recursion( i );
 
@@ -579,5 +579,5 @@
 	}
 	
-	bool wait( pthread_cond_var(L) & this, L & l, uintptr_t info, timespec t  ) {
+	bool wait( pthread_cond_var(L) & this, L & l, uintptr_t info, timespec t ) {
 		PTHREAD_WAIT_TIME( info, &l , getDuration( t ) )
 	}
@@ -585,5 +585,5 @@
 //-----------------------------------------------------------------------------
 // Semaphore
-void  ?{}( semaphore & this, int count = 1 ) {
+void ?{}( semaphore & this, int count = 1 ) {
 	(this.lock){};
 	this.count = count;
@@ -603,8 +603,7 @@
 		park();
 		return true;
-	}
-	else {
-	    unlock( lock );
-	    return false;
+	} else {
+		unlock( lock );
+		return false;
 	}
 }
@@ -622,5 +621,5 @@
 
 	// make new owner
-	if( doUnpark ) unpark( thrd );
+	if ( doUnpark ) unpark( thrd );
 
 	return thrd;
