Index: libcfa/src/concurrency/locks.hfa
===================================================================
--- libcfa/src/concurrency/locks.hfa	(revision 8f5576d596298c117a178d81e998ff6a1434c012)
+++ libcfa/src/concurrency/locks.hfa	(revision c7c178b577f3c639ac7fa0d4d991c368b2e91e39)
@@ -39,5 +39,4 @@
 };
 
-static inline bool P(Semaphore0nary & this, $thread * thrd) __attribute__((artificial));
 static inline bool P(Semaphore0nary & this, $thread * thrd) {
 	/* paranoid */ verify(!(thrd->seqable.next));
@@ -48,5 +47,4 @@
 }
 
-static inline bool P(Semaphore0nary & this) __attribute__((artificial));
 static inline bool P(Semaphore0nary & this) {
     $thread * thrd = active_thread();
@@ -56,5 +54,4 @@
 }
 
-static inline $thread * V(Semaphore0nary & this, const bool doUnpark = true) __attribute__((artificial));
 static inline $thread * V(Semaphore0nary & this, const bool doUnpark = true) {
 	$thread * next;
@@ -82,5 +79,8 @@
 
 	// returns true if no blocking needed
-	bool P(BinaryBenaphore & this) { return __atomic_fetch_sub(&this.counter, 1, __ATOMIC_SEQ_CST) > 0; }
+	bool P(BinaryBenaphore & this) {
+		return __atomic_fetch_sub(&this.counter, 1, __ATOMIC_SEQ_CST) > 0;
+	}
+
 	bool tryP(BinaryBenaphore & this) {
 		ssize_t c = this.counter;
@@ -115,11 +115,10 @@
 static inline void ?{}(ThreadBenaphore & this, one_t ) { (this.ben){ 1 }; }
 
-static inline bool P(ThreadBenaphore & this)              { return /* P(this.ben) ? false : */ P(this.sem); }
-static inline bool P(ThreadBenaphore & this, $thread * t) { return /* P(this.ben) ? false : */ P(this.sem, t ); }
+static inline bool P(ThreadBenaphore & this)              { return P(this.ben) ? false : P(this.sem); }
 static inline bool tryP(ThreadBenaphore & this)           { return tryP(this.ben); }
 static inline bool P(ThreadBenaphore & this, bool wait)   { return wait ? P(this) : tryP(this); }
 
 static inline $thread * V(ThreadBenaphore & this, const bool doUnpark = true) {
-	// if (V(this.ben)) return 0p;
+	if (V(this.ben)) return 0p;
 	return V(this.sem, doUnpark);
 }
@@ -138,4 +137,5 @@
 bool   V (semaphore & this);
 bool   V (semaphore & this, unsigned count);
+$thread * V (semaphore & this, bool );
 
 //----------
@@ -146,11 +146,10 @@
 static inline void  ?{}( single_acquisition_lock & this ) {((blocking_lock &)this){ false, false };}
 static inline void ^?{}( single_acquisition_lock & this ) {}
-static inline void   lock      ( single_acquisition_lock & this ) { lock    ( (blocking_lock &)this ); }
-static inline bool   try_lock  ( single_acquisition_lock & this ) { return try_lock( (blocking_lock &)this ); }
-static inline void   unlock    ( single_acquisition_lock & this ) { unlock  ( (blocking_lock &)this ); }
-static inline void   on_wait   ( single_acquisition_lock & this ) { on_wait ( (blocking_lock &)this ); }
-static inline void   on_notify ( single_acquisition_lock & this, struct $thread * t ) { on_notify( (blocking_lock &)this, t ); }
-static inline void   set_recursion_count( single_acquisition_lock & this, size_t recursion ) { set_recursion_count( (blocking_lock &)this, recursion ); }
-static inline size_t get_recursion_count( single_acquisition_lock & this ) { return get_recursion_count( (blocking_lock &)this ); }
+static inline void   lock     ( single_acquisition_lock & this ) { lock    ( (blocking_lock &)this ); }
+static inline bool   try_lock ( single_acquisition_lock & this ) { return try_lock( (blocking_lock &)this ); }
+static inline void   unlock   ( single_acquisition_lock & this ) { unlock  ( (blocking_lock &)this ); }
+static inline size_t on_wait  ( single_acquisition_lock & this ) { return on_wait ( (blocking_lock &)this ); }
+static inline void   on_wakeup( single_acquisition_lock & this, size_t v ) { on_wakeup ( (blocking_lock &)this, v ); }
+static inline void   on_notify( single_acquisition_lock & this, struct $thread * t ) { on_notify( (blocking_lock &)this, t ); }
 
 //----------
@@ -164,8 +163,7 @@
 static inline bool   try_lock ( owner_lock & this ) { return try_lock( (blocking_lock &)this ); }
 static inline void   unlock   ( owner_lock & this ) { unlock  ( (blocking_lock &)this ); }
-static inline void   on_wait  ( owner_lock & this ) { on_wait ( (blocking_lock &)this ); }
+static inline size_t on_wait  ( owner_lock & this ) { return on_wait ( (blocking_lock &)this ); }
+static inline void   on_wakeup( owner_lock & this, size_t v ) { on_wakeup ( (blocking_lock &)this, v ); }
 static inline void   on_notify( owner_lock & this, struct $thread * t ) { on_notify( (blocking_lock &)this, t ); }
-static inline void   set_recursion_count( owner_lock & this, size_t recursion ) { set_recursion_count( (blocking_lock &)this, recursion ); }
-static inline size_t get_recursion_count( owner_lock & this ) { return get_recursion_count( (blocking_lock &)this ); }
 
 struct fast_lock {
@@ -179,13 +177,5 @@
 }
 
-static inline void $lock(fast_lock & this, $thread * thrd) {
-	/* paranoid */verify(thrd != this.owner);
-
-	for (;;) {
-		if ($try_lock(this, thrd)) return;
-		P(this.sem, thrd);
-	}
-}
-
+static inline void lock( fast_lock & this ) __attribute__((artificial));
 static inline void lock( fast_lock & this ) {
 	$thread * thrd = active_thread();
@@ -198,5 +188,6 @@
 }
 
-static inline void try_lock ( fast_lock & this ) {
+static inline bool try_lock( fast_lock & this ) __attribute__((artificial));
+static inline bool try_lock ( fast_lock & this ) {
 	$thread * thrd = active_thread();
 	/* paranoid */ verify(thrd != this.owner);
@@ -204,27 +195,20 @@
 }
 
-static inline void unlock( fast_lock & this ) {
+static inline $thread * unlock( fast_lock & this ) __attribute__((artificial));
+static inline $thread * unlock( fast_lock & this ) {
 	$thread * thrd = active_thread();
 	/* paranoid */ verify(thrd == this.owner);
-	$thread * next = V(this.sem, false); // implicit fence
-	// open 'owner' only after fence
+
+	// open 'owner' before unlocking anyone
+	// so new and unlocked threads don't park incorrectly.
+	// This may require additional fencing on ARM.
 	this.owner = 0p;
 
-	// Unpark the next person (can be 0p, unpark handles it)
-	unpark(next);
-}
-
-static inline void on_wait( fast_lock & this ) {
-	unlock(this);
-	#warning this is broken
-}
-
-static inline void on_notify( fast_lock & this, struct $thread * t ) {
-	$lock(this, t);
-	#warning this is broken
-}
-
-static inline void   set_recursion_count( fast_lock & this, size_t recursion ) {}
-static inline size_t get_recursion_count( fast_lock & this ) { return 0; }
+	return V(this.sem, true);
+}
+
+static inline size_t on_wait( fast_lock & this ) { unlock(this); return 0; }
+static inline void on_wakeup( fast_lock & this, size_t ) { lock(this); }
+static inline void on_notify( fast_lock &, struct $thread * t ) { unpark(t); }
 
 struct mcs_node {
@@ -260,11 +244,8 @@
 
 	// For synchronization locks to use when releasing
-	void on_wait( L & );
-
-	// to get recursion count for cond lock to reset after waking
-	size_t get_recursion_count( L & );
+	size_t on_wait( L & );
 
 	// to set recursion count after getting signalled;
-	void set_recursion_count( L &, size_t recursion );
+	void on_wakeup( L &, size_t recursion );
 };
 
