Index: libcfa/src/concurrency/kernel_private.hfa
===================================================================
--- libcfa/src/concurrency/kernel_private.hfa	(revision cfff6398bb3300e69fce3706c15f15750c4641db)
+++ libcfa/src/concurrency/kernel_private.hfa	(revision c993b1521e96d36bed6b395f8eec5284bc85f5f5)
@@ -25,5 +25,4 @@
 // Scheduler
 
-struct __attribute__((aligned(128))) __scheduler_lock_id_t;
 
 extern "C" {
@@ -80,8 +79,8 @@
 // Lock-Free registering/unregistering of threads
 // Register a processor to a given cluster and get its unique id in return
-void register_proc_id( struct __processor_id_t * );
+unsigned register_proc_id( void );
 
 // Unregister a processor from a given cluster using its id, getting back the original pointer
-void unregister_proc_id( struct __processor_id_t * proc );
+void unregister_proc_id( unsigned );
 
 //=======================================================================
@@ -112,21 +111,7 @@
 }
 
-// Cells use by the reader writer lock
-// while not generic it only relies on a opaque pointer
-struct __attribute__((aligned(128))) __scheduler_lock_id_t {
-	// Spin lock used as the underlying lock
-	volatile bool lock;
-
-	// Handle pointing to the proc owning this cell
-	// Used for allocating cells and debugging
-	__processor_id_t * volatile handle;
-
-	#ifdef __CFA_WITH_VERIFY__
-		// Debug, check if this is owned for reading
-		bool owned;
-	#endif
-};
-
-static_assert( sizeof(struct __scheduler_lock_id_t) <= __alignof(struct __scheduler_lock_id_t));
+
+
+
 
 //-----------------------------------------------------------------------
@@ -147,8 +132,8 @@
 
 	// writer lock
-	volatile bool lock;
+	volatile bool write_lock;
 
 	// data pointer
-	__scheduler_lock_id_t * data;
+	volatile bool * volatile * data;
 };
 
@@ -163,12 +148,10 @@
 static inline void ready_schedule_lock(void) with(*__scheduler_lock) {
 	/* paranoid */ verify( ! __preemption_enabled() );
-	/* paranoid */ verify( kernelTLS().this_proc_id );
-
-	unsigned iproc = kernelTLS().this_proc_id->id;
-	/*paranoid*/ verify(data[iproc].handle == kernelTLS().this_proc_id);
-	/*paranoid*/ verify(iproc < ready);
+	/* paranoid */ verify( ! kernelTLS().in_sched_lock );
+	/* paranoid */ verify( data[kernelTLS().sched_id] == &kernelTLS().sched_lock );
+	/* paranoid */ verify( !kernelTLS().this_processor || kernelTLS().this_processor->unique_id == kernelTLS().sched_id );
 
 	// Step 1 : make sure no writer are in the middle of the critical section
-	while(__atomic_load_n(&lock, (int)__ATOMIC_RELAXED))
+	while(__atomic_load_n(&write_lock, (int)__ATOMIC_RELAXED))
 		Pause();
 
@@ -179,10 +162,10 @@
 
 	// Step 2 : acquire our local lock
-	__atomic_acquire( &data[iproc].lock );
-	/*paranoid*/ verify(data[iproc].lock);
+	__atomic_acquire( &kernelTLS().sched_lock );
+	/*paranoid*/ verify(kernelTLS().sched_lock);
 
 	#ifdef __CFA_WITH_VERIFY__
 		// Debug, check if this is owned for reading
-		data[iproc].owned = true;
+		kernelTLS().in_sched_lock = true;
 	#endif
 }
@@ -190,16 +173,13 @@
 static inline void ready_schedule_unlock(void) with(*__scheduler_lock) {
 	/* paranoid */ verify( ! __preemption_enabled() );
-	/* paranoid */ verify( kernelTLS().this_proc_id );
-
-	unsigned iproc = kernelTLS().this_proc_id->id;
-	/*paranoid*/ verify(data[iproc].handle == kernelTLS().this_proc_id);
-	/*paranoid*/ verify(iproc < ready);
-	/*paranoid*/ verify(data[iproc].lock);
-	/*paranoid*/ verify(data[iproc].owned);
+	/* paranoid */ verify( data[kernelTLS().sched_id] == &kernelTLS().sched_lock );
+	/* paranoid */ verify( !kernelTLS().this_processor || kernelTLS().this_processor->unique_id == kernelTLS().sched_id );
+	/* paranoid */ verify( kernelTLS().sched_lock );
+	/* paranoid */ verify( kernelTLS().in_sched_lock );
 	#ifdef __CFA_WITH_VERIFY__
 		// Debug, check if this is owned for reading
-		data[iproc].owned = false;
+		kernelTLS().in_sched_lock = false;
 	#endif
-	__atomic_unlock(&data[iproc].lock);
+	__atomic_unlock(&kernelTLS().sched_lock);
 }
 
@@ -207,11 +187,10 @@
 	static inline bool ready_schedule_islocked(void) {
 		/* paranoid */ verify( ! __preemption_enabled() );
-		/*paranoid*/ verify( kernelTLS().this_proc_id );
-		__processor_id_t * proc = kernelTLS().this_proc_id;
-		return __scheduler_lock->data[proc->id].owned;
+		/* paranoid */ verify( (!kernelTLS().in_sched_lock) || kernelTLS().sched_lock );
+		return kernelTLS().sched_lock;
 	}
 
 	static inline bool ready_mutate_islocked() {
-		return __scheduler_lock->lock;
+		return __scheduler_lock->write_lock;
 	}
 #endif
@@ -228,14 +207,15 @@
 // Register a processor to a given cluster and get its unique id in return
 // For convenience, also acquires the lock
-static inline uint_fast32_t ready_mutate_register( struct __processor_id_t * proc ) {
-	register_proc_id( proc );
-	return ready_mutate_lock();
+static inline [unsigned, uint_fast32_t] ready_mutate_register() {
+	unsigned id = register_proc_id();
+	uint_fast32_t last = ready_mutate_lock();
+	return [id, last];
 }
 
 // Unregister a processor from a given cluster using its id, getting back the original pointer
 // assumes the lock is acquired
-static inline void ready_mutate_unregister( struct __processor_id_t * proc, uint_fast32_t last_s ) {
+static inline void ready_mutate_unregister( unsigned id, uint_fast32_t last_s ) {
 	ready_mutate_unlock( last_s );
-	unregister_proc_id( proc );
+	unregister_proc_id( id );
 }
 
