Index: libcfa/src/concurrency/alarm.cfa
===================================================================
--- libcfa/src/concurrency/alarm.cfa	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ libcfa/src/concurrency/alarm.cfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -22,7 +22,7 @@
 }
 
-#include "alarm.h"
-#include "kernel_private.h"
-#include "preemption.h"
+#include "alarm.hfa"
+#include "kernel_private.hfa"
+#include "preemption.hfa"
 
 //=============================================================================================
Index: libcfa/src/concurrency/alarm.h
===================================================================
--- libcfa/src/concurrency/alarm.h	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ 	(revision )
@@ -1,78 +1,0 @@
-//
-// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
-//
-// The contents of this file are covered under the licence agreement in the
-// file "LICENCE" distributed with Cforall.
-//
-// alarm.h --
-//
-// Author           : Thierry Delisle
-// Created On       : Fri Jun 2 11:31:25 2017
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Mon Mar 26 16:25:41 2018
-// Update Count     : 11
-//
-
-#pragma once
-
-#include <stdbool.h>
-#include <stdint.h>
-
-#include <assert.h>
-
-#include "time"
-
-struct thread_desc;
-struct processor;
-
-//=============================================================================================
-// Clock logic
-//=============================================================================================
-
-Time __kernel_get_time();
-void __kernel_set_timer( Duration alarm );
-
-//=============================================================================================
-// Alarm logic
-//=============================================================================================
-
-struct alarm_node_t {
-	Time alarm;				// time when alarm goes off
-	Duration period;			// if > 0 => period of alarm
-	alarm_node_t * next;		// intrusive link list field
-
-	union {
-		thread_desc * thrd;	// thrd who created event
-		processor * proc;		// proc who created event
-	};
-
-	bool set		:1;		// whether or not the alarm has be registered
-	bool kernel_alarm	:1;		// true if this is not a user defined alarm
-};
-
-typedef alarm_node_t ** __alarm_it_t;
-
-void ?{}( alarm_node_t & this, thread_desc * thrd, Time alarm, Duration period );
-void ?{}( alarm_node_t & this, processor   * proc, Time alarm, Duration period );
-void ^?{}( alarm_node_t & this );
-
-struct alarm_list_t {
-	alarm_node_t * head;
-	__alarm_it_t tail;
-};
-
-static inline void ?{}( alarm_list_t & this ) with( this ) {
-	head = 0;
-	tail = &head;
-}
-
-void insert( alarm_list_t * this, alarm_node_t * n );
-alarm_node_t * pop( alarm_list_t * this );
-
-void register_self  ( alarm_node_t * this );
-void unregister_self( alarm_node_t * this );
-
-// Local Variables: //
-// mode: c //
-// tab-width: 6 //
-// End: //
Index: libcfa/src/concurrency/alarm.hfa
===================================================================
--- libcfa/src/concurrency/alarm.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
+++ libcfa/src/concurrency/alarm.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -0,0 +1,78 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// alarm.hfa --
+//
+// Author           : Thierry Delisle
+// Created On       : Fri Jun 2 11:31:25 2017
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Mon Mar 26 16:25:41 2018
+// Update Count     : 11
+//
+
+#pragma once
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <assert.h>
+
+#include "time"
+
+struct thread_desc;
+struct processor;
+
+//=============================================================================================
+// Clock logic
+//=============================================================================================
+
+Time __kernel_get_time();
+void __kernel_set_timer( Duration alarm );
+
+//=============================================================================================
+// Alarm logic
+//=============================================================================================
+
+struct alarm_node_t {
+	Time alarm;				// time when alarm goes off
+	Duration period;			// if > 0 => period of alarm
+	alarm_node_t * next;		// intrusive link list field
+
+	union {
+		thread_desc * thrd;	// thrd who created event
+		processor * proc;		// proc who created event
+	};
+
+	bool set		:1;		// whether or not the alarm has be registered
+	bool kernel_alarm	:1;		// true if this is not a user defined alarm
+};
+
+typedef alarm_node_t ** __alarm_it_t;
+
+void ?{}( alarm_node_t & this, thread_desc * thrd, Time alarm, Duration period );
+void ?{}( alarm_node_t & this, processor   * proc, Time alarm, Duration period );
+void ^?{}( alarm_node_t & this );
+
+struct alarm_list_t {
+	alarm_node_t * head;
+	__alarm_it_t tail;
+};
+
+static inline void ?{}( alarm_list_t & this ) with( this ) {
+	head = 0;
+	tail = &head;
+}
+
+void insert( alarm_list_t * this, alarm_node_t * n );
+alarm_node_t * pop( alarm_list_t * this );
+
+void register_self  ( alarm_node_t * this );
+void unregister_self( alarm_node_t * this );
+
+// Local Variables: //
+// mode: c //
+// tab-width: 6 //
+// End: //
Index: libcfa/src/concurrency/coroutine
===================================================================
--- libcfa/src/concurrency/coroutine	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ 	(revision )
@@ -1,151 +1,0 @@
-//
-// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
-//
-// The contents of this file are covered under the licence agreement in the
-// file "LICENCE" distributed with Cforall.
-//
-// coroutine --
-//
-// Author           : Thierry Delisle
-// Created On       : Mon Nov 28 12:27:26 2016
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Fri Mar 30 18:23:45 2018
-// Update Count     : 8
-//
-
-#pragma once
-
-#include <assert.h>
-#include "invoke.h"
-
-//-----------------------------------------------------------------------------
-// Coroutine trait
-// Anything that implements this trait can be resumed.
-// Anything that is resumed is a coroutine.
-trait is_coroutine(dtype T) {
-      void main(T & this);
-      coroutine_desc * get_coroutine(T & this);
-};
-
-#define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X& this) { return &this.__cor; } void main(X& this)
-
-//-----------------------------------------------------------------------------
-// Ctors and dtors
-// void ?{}( coStack_t & this );
-// void ^?{}( coStack_t & this );
-
-void ?{}( coroutine_desc & this, const char * name, void * storage, size_t storageSize );
-void ^?{}( coroutine_desc & this );
-
-static inline void ?{}( coroutine_desc & this)                                       { this{ "Anonymous Coroutine", NULL, 0 }; }
-static inline void ?{}( coroutine_desc & this, size_t stackSize)                     { this{ "Anonymous Coroutine", NULL, stackSize }; }
-static inline void ?{}( coroutine_desc & this, void * storage, size_t storageSize )  { this{ "Anonymous Coroutine", storage, storageSize }; }
-static inline void ?{}( coroutine_desc & this, const char * name)                    { this{ name, NULL, 0 }; }
-static inline void ?{}( coroutine_desc & this, const char * name, size_t stackSize ) { this{ name, NULL, stackSize }; }
-
-//-----------------------------------------------------------------------------
-// Public coroutine API
-static inline void suspend();
-
-forall(dtype T | is_coroutine(T))
-static inline void resume(T & cor);
-
-forall(dtype T | is_coroutine(T))
-void prime(T & cor);
-
-//-----------------------------------------------------------------------------
-// PRIVATE exposed because of inline
-
-// Start coroutine routines
-extern "C" {
-      forall(dtype T | is_coroutine(T))
-      void CtxInvokeCoroutine(T * this);
-
-      forall(dtype T | is_coroutine(T))
-      void CtxStart(T * this, void ( *invoke)(T *));
-}
-
-// Private wrappers for context switch and stack creation
-extern void CoroutineCtxSwitch(coroutine_desc * src, coroutine_desc * dst);
-extern void create_stack( coStack_t * this, unsigned int storageSize );
-
-// Suspend implementation inlined for performance
-static inline void suspend() {
-	// optimization : read TLS once and reuse it
-	// Safety note: this is preemption safe since if
-	// preemption occurs after this line, the pointer
-	// will also migrate which means this value will
-	// stay in syn with the TLS
-	coroutine_desc * src = TL_GET( this_coroutine );
-
-	assertf( src->last != 0,
-		"Attempt to suspend coroutine \"%.256s\" (%p) that has never been resumed.\n"
-		"Possible cause is a suspend executed in a member called by a coroutine user rather than by the coroutine main.",
-		src->name, src );
-	assertf( src->last->state != Halted,
-		"Attempt by coroutine \"%.256s\" (%p) to suspend back to terminated coroutine \"%.256s\" (%p).\n"
-		"Possible cause is terminated coroutine's main routine has already returned.",
-		src->name, src, src->last->name, src->last );
-
-	CoroutineCtxSwitch( src, src->last );
-}
-
-// Resume implementation inlined for performance
-forall(dtype T | is_coroutine(T))
-static inline void resume(T & cor) {
-	// optimization : read TLS once and reuse it
-	// Safety note: this is preemption safe since if
-	// preemption occurs after this line, the pointer
-	// will also migrate which means this value will
-	// stay in syn with the TLS
-	coroutine_desc * src = TL_GET( this_coroutine );
-	coroutine_desc * dst = get_coroutine(cor);
-
-	if( unlikely(!dst->stack.base) ) {
-		create_stack(&dst->stack, dst->stack.size);
-		CtxStart(&cor, CtxInvokeCoroutine);
-	}
-
-	// not resuming self ?
-	if ( src != dst ) {
-		assertf( dst->state != Halted ,
-			"Attempt by coroutine %.256s (%p) to resume terminated coroutine %.256s (%p).\n"
-			"Possible cause is terminated coroutine's main routine has already returned.",
-			src->name, src, dst->name, dst );
-
-		// set last resumer
-		dst->last = src;
-		dst->starter = dst->starter ? dst->starter : src;
-	}
-
-	// always done for performance testing
-	CoroutineCtxSwitch( src, dst );
-}
-
-static inline void resume(coroutine_desc * dst) {
-	// optimization : read TLS once and reuse it
-	// Safety note: this is preemption safe since if
-	// preemption occurs after this line, the pointer
-	// will also migrate which means this value will
-	// stay in syn with the TLS
-	coroutine_desc * src = TL_GET( this_coroutine );
-
-	// not resuming self ?
-	if ( src != dst ) {
-		assertf( dst->state != Halted ,
-			"Attempt by coroutine %.256s (%p) to resume terminated coroutine %.256s (%p).\n"
-			"Possible cause is terminated coroutine's main routine has already returned.",
-			src->name, src, dst->name, dst );
-
-		// set last resumer
-		dst->last = src;
-	}
-
-	// always done for performance testing
-	CoroutineCtxSwitch( src, dst );
-}
-
-// Local Variables: //
-// mode: c //
-// tab-width: 4 //
-// End: //
Index: libcfa/src/concurrency/coroutine.cfa
===================================================================
--- libcfa/src/concurrency/coroutine.cfa	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ libcfa/src/concurrency/coroutine.cfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -25,5 +25,5 @@
 }
 
-#include "kernel_private.h"
+#include "kernel_private.hfa"
 
 #define __CFA_INVOKE_PRIVATE__
Index: libcfa/src/concurrency/coroutine.hfa
===================================================================
--- libcfa/src/concurrency/coroutine.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
+++ libcfa/src/concurrency/coroutine.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -0,0 +1,151 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// coroutine --
+//
+// Author           : Thierry Delisle
+// Created On       : Mon Nov 28 12:27:26 2016
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Fri Mar 30 18:23:45 2018
+// Update Count     : 8
+//
+
+#pragma once
+
+#include <assert.h>
+#include "invoke.h"
+
+//-----------------------------------------------------------------------------
+// Coroutine trait
+// Anything that implements this trait can be resumed.
+// Anything that is resumed is a coroutine.
+trait is_coroutine(dtype T) {
+      void main(T & this);
+      coroutine_desc * get_coroutine(T & this);
+};
+
+#define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X& this) { return &this.__cor; } void main(X& this)
+
+//-----------------------------------------------------------------------------
+// Ctors and dtors
+// void ?{}( coStack_t & this );
+// void ^?{}( coStack_t & this );
+
+void ?{}( coroutine_desc & this, const char * name, void * storage, size_t storageSize );
+void ^?{}( coroutine_desc & this );
+
+static inline void ?{}( coroutine_desc & this)                                       { this{ "Anonymous Coroutine", NULL, 0 }; }
+static inline void ?{}( coroutine_desc & this, size_t stackSize)                     { this{ "Anonymous Coroutine", NULL, stackSize }; }
+static inline void ?{}( coroutine_desc & this, void * storage, size_t storageSize )  { this{ "Anonymous Coroutine", storage, storageSize }; }
+static inline void ?{}( coroutine_desc & this, const char * name)                    { this{ name, NULL, 0 }; }
+static inline void ?{}( coroutine_desc & this, const char * name, size_t stackSize ) { this{ name, NULL, stackSize }; }
+
+//-----------------------------------------------------------------------------
+// Public coroutine API
+static inline void suspend();
+
+forall(dtype T | is_coroutine(T))
+static inline void resume(T & cor);
+
+forall(dtype T | is_coroutine(T))
+void prime(T & cor);
+
+//-----------------------------------------------------------------------------
+// PRIVATE exposed because of inline
+
+// Start coroutine routines
+extern "C" {
+      forall(dtype T | is_coroutine(T))
+      void CtxInvokeCoroutine(T * this);
+
+      forall(dtype T | is_coroutine(T))
+      void CtxStart(T * this, void ( *invoke)(T *));
+}
+
+// Private wrappers for context switch and stack creation
+extern void CoroutineCtxSwitch(coroutine_desc * src, coroutine_desc * dst);
+extern void create_stack( coStack_t * this, unsigned int storageSize );
+
+// Suspend implementation inlined for performance
+static inline void suspend() {
+	// optimization : read TLS once and reuse it
+	// Safety note: this is preemption safe since if
+	// preemption occurs after this line, the pointer
+	// will also migrate which means this value will
+	// stay in syn with the TLS
+	coroutine_desc * src = TL_GET( this_coroutine );
+
+	assertf( src->last != 0,
+		"Attempt to suspend coroutine \"%.256s\" (%p) that has never been resumed.\n"
+		"Possible cause is a suspend executed in a member called by a coroutine user rather than by the coroutine main.",
+		src->name, src );
+	assertf( src->last->state != Halted,
+		"Attempt by coroutine \"%.256s\" (%p) to suspend back to terminated coroutine \"%.256s\" (%p).\n"
+		"Possible cause is terminated coroutine's main routine has already returned.",
+		src->name, src, src->last->name, src->last );
+
+	CoroutineCtxSwitch( src, src->last );
+}
+
+// Resume implementation inlined for performance
+forall(dtype T | is_coroutine(T))
+static inline void resume(T & cor) {
+	// optimization : read TLS once and reuse it
+	// Safety note: this is preemption safe since if
+	// preemption occurs after this line, the pointer
+	// will also migrate which means this value will
+	// stay in syn with the TLS
+	coroutine_desc * src = TL_GET( this_coroutine );
+	coroutine_desc * dst = get_coroutine(cor);
+
+	if( unlikely(!dst->stack.base) ) {
+		create_stack(&dst->stack, dst->stack.size);
+		CtxStart(&cor, CtxInvokeCoroutine);
+	}
+
+	// not resuming self ?
+	if ( src != dst ) {
+		assertf( dst->state != Halted ,
+			"Attempt by coroutine %.256s (%p) to resume terminated coroutine %.256s (%p).\n"
+			"Possible cause is terminated coroutine's main routine has already returned.",
+			src->name, src, dst->name, dst );
+
+		// set last resumer
+		dst->last = src;
+		dst->starter = dst->starter ? dst->starter : src;
+	}
+
+	// always done for performance testing
+	CoroutineCtxSwitch( src, dst );
+}
+
+static inline void resume(coroutine_desc * dst) {
+	// optimization : read TLS once and reuse it
+	// Safety note: this is preemption safe since if
+	// preemption occurs after this line, the pointer
+	// will also migrate which means this value will
+	// stay in syn with the TLS
+	coroutine_desc * src = TL_GET( this_coroutine );
+
+	// not resuming self ?
+	if ( src != dst ) {
+		assertf( dst->state != Halted ,
+			"Attempt by coroutine %.256s (%p) to resume terminated coroutine %.256s (%p).\n"
+			"Possible cause is terminated coroutine's main routine has already returned.",
+			src->name, src, dst->name, dst );
+
+		// set last resumer
+		dst->last = src;
+	}
+
+	// always done for performance testing
+	CoroutineCtxSwitch( src, dst );
+}
+
+// Local Variables: //
+// mode: c //
+// tab-width: 4 //
+// End: //
Index: libcfa/src/concurrency/invoke.h
===================================================================
--- libcfa/src/concurrency/invoke.h	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ libcfa/src/concurrency/invoke.h	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -14,7 +14,7 @@
 //
 
-#include "bits/containers.h"
-#include "bits/defs.h"
-#include "bits/locks.h"
+#include "bits/containers.hfa"
+#include "bits/defs.hfa"
+#include "bits/locks.hfa"
 
 #ifdef __cforall
Index: libcfa/src/concurrency/kernel
===================================================================
--- libcfa/src/concurrency/kernel	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ 	(revision )
@@ -1,205 +1,0 @@
-//
-// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
-//
-// The contents of this file are covered under the licence agreement in the
-// file "LICENCE" distributed with Cforall.
-//
-// kernel --
-//
-// Author           : Thierry Delisle
-// Created On       : Tue Jan 17 12:27:26 2017
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Tue Apr 10 14:46:49 2018
-// Update Count     : 10
-//
-
-#pragma once
-
-#include <stdbool.h>
-
-#include "invoke.h"
-#include "time_t.h"
-
-extern "C" {
-#include <pthread.h>
-#include <semaphore.h>
-}
-
-//-----------------------------------------------------------------------------
-// Locks
-struct semaphore {
-	__spinlock_t lock;
-	int count;
-	__queue_t(thread_desc) waiting;
-};
-
-void  ?{}(semaphore & this, int count = 1);
-void ^?{}(semaphore & this);
-void   P (semaphore & this);
-void   V (semaphore & this);
-
-
-//-----------------------------------------------------------------------------
-// Processor
-extern struct cluster * mainCluster;
-
-enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule, Callback };
-
-typedef void (*__finish_callback_fptr_t)(void);
-
-//TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
-struct FinishAction {
-	FinishOpCode action_code;
-	/*
-	// Union of possible actions
-	union {
-		// Option 1 : locks and threads
-		struct {
-			// 1 thread or N thread
-			union {
-				thread_desc * thrd;
-				struct {
-					thread_desc ** thrds;
-					unsigned short thrd_count;
-				};
-			};
-			// 1 lock or N lock
-			union {
-				__spinlock_t * lock;
-				struct {
-					__spinlock_t ** locks;
-					unsigned short lock_count;
-				};
-			};
-		};
-		// Option 2 : action pointer
-		__finish_callback_fptr_t callback;
-	};
-	/*/
-	thread_desc * thrd;
-	thread_desc ** thrds;
-	unsigned short thrd_count;
-	__spinlock_t * lock;
-	__spinlock_t ** locks;
-	unsigned short lock_count;
-	__finish_callback_fptr_t callback;
-	//*/
-};
-static inline void ?{}(FinishAction & this) {
-	this.action_code = No_Action;
-	this.thrd = NULL;
-	this.lock = NULL;
-}
-static inline void ^?{}(FinishAction & this) {}
-
-// Processor
-coroutine processorCtx_t {
-	struct processor * proc;
-};
-
-// Wrapper around kernel threads
-struct processor {
-	// Main state
-	// Coroutine ctx who does keeps the state of the processor
-	struct processorCtx_t runner;
-
-	// Cluster from which to get threads
-	struct cluster * cltr;
-
-	// Name of the processor
-	const char * name;
-
-	// Handle to pthreads
-	pthread_t kernel_thread;
-
-	// RunThread data
-	// Action to do after a thread is ran
-	struct FinishAction finish;
-
-	// Preemption data
-	// Node which is added in the discrete event simulaiton
-	struct alarm_node_t * preemption_alarm;
-
-	// If true, a preemption was triggered in an unsafe region, the processor must preempt as soon as possible
-	bool pending_preemption;
-
-	// Idle lock
-	__bin_sem_t idleLock;
-
-	// Termination
-	// Set to true to notify the processor should terminate
-	volatile bool do_terminate;
-
-	// Termination synchronisation
-	semaphore terminated;
-
-	// Link lists fields
-	struct __dbg_node_proc {
-		struct processor * next;
-		struct processor * prev;
-	} node;
-
-#ifdef __CFA_DEBUG__
-	// Last function to enable preemption on this processor
-	const char * last_enable;
-#endif
-};
-
-void  ?{}(processor & this, const char * name, struct cluster & cltr);
-void ^?{}(processor & this);
-
-static inline void  ?{}(processor & this)                    { this{ "Anonymous Processor", *mainCluster}; }
-static inline void  ?{}(processor & this, struct cluster & cltr)    { this{ "Anonymous Processor", cltr}; }
-static inline void  ?{}(processor & this, const char * name) { this{name, *mainCluster }; }
-
-static inline [processor *&, processor *& ] __get( processor & this ) {
-	return this.node.[next, prev];
-}
-
-//-----------------------------------------------------------------------------
-// Cluster
-struct cluster {
-	// Ready queue locks
-	__spinlock_t ready_queue_lock;
-
-	// Ready queue for threads
-	__queue_t(thread_desc) ready_queue;
-
-	// Name of the cluster
-	const char * name;
-
-	// Preemption rate on this cluster
-	Duration preemption_rate;
-
-	// List of processors
-	__spinlock_t proc_list_lock;
-	__dllist_t(struct processor) procs;
-	__dllist_t(struct processor) idles;
-
-	// List of processors
-	__spinlock_t thread_list_lock;
-	__dllist_t(struct thread_desc) threads;
-
-	// Link lists fields
-	struct __dbg_node_cltr {
-		cluster * next;
-		cluster * prev;
-	} node;
-};
-extern Duration default_preemption();
-
-void ?{} (cluster & this, const char * name, Duration preemption_rate);
-void ^?{}(cluster & this);
-
-static inline void ?{} (cluster & this)                           { this{"Anonymous Cluster", default_preemption()}; }
-static inline void ?{} (cluster & this, Duration preemption_rate) { this{"Anonymous Cluster", preemption_rate}; }
-static inline void ?{} (cluster & this, const char * name)        { this{name, default_preemption()}; }
-
-static inline [cluster *&, cluster *& ] __get( cluster & this ) {
-	return this.node.[next, prev];
-}
-
-// Local Variables: //
-// mode: c //
-// tab-width: 4 //
-// End: //
Index: libcfa/src/concurrency/kernel.cfa
===================================================================
--- libcfa/src/concurrency/kernel.cfa	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ libcfa/src/concurrency/kernel.cfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -22,5 +22,5 @@
 #include <fenv.h>
 #include <sys/resource.h>
-#include <signal.h>
+#include <signal.hfa>
 #include <unistd.h>
 }
@@ -28,7 +28,7 @@
 //CFA Includes
 #include "time"
-#include "kernel_private.h"
-#include "preemption.h"
-#include "startup.h"
+#include "kernel_private.hfa"
+#include "preemption.hfa"
+#include "startup.hfa"
 
 //Private includes
Index: libcfa/src/concurrency/kernel.hfa
===================================================================
--- libcfa/src/concurrency/kernel.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
+++ libcfa/src/concurrency/kernel.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -0,0 +1,205 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// kernel --
+//
+// Author           : Thierry Delisle
+// Created On       : Tue Jan 17 12:27:26 2017
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Tue Apr 10 14:46:49 2018
+// Update Count     : 10
+//
+
+#pragma once
+
+#include <stdbool.h>
+
+#include "invoke.h"
+#include "time_t.hfa"
+
+extern "C" {
+#include <pthread.h>
+#include <semaphore.h>
+}
+
+//-----------------------------------------------------------------------------
+// Locks
+struct semaphore {
+	__spinlock_t lock;
+	int count;
+	__queue_t(thread_desc) waiting;
+};
+
+void  ?{}(semaphore & this, int count = 1);
+void ^?{}(semaphore & this);
+void   P (semaphore & this);
+void   V (semaphore & this);
+
+
+//-----------------------------------------------------------------------------
+// Processor
+extern struct cluster * mainCluster;
+
+enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule, Callback };
+
+typedef void (*__finish_callback_fptr_t)(void);
+
+//TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
+struct FinishAction {
+	FinishOpCode action_code;
+	/*
+	// Union of possible actions
+	union {
+		// Option 1 : locks and threads
+		struct {
+			// 1 thread or N thread
+			union {
+				thread_desc * thrd;
+				struct {
+					thread_desc ** thrds;
+					unsigned short thrd_count;
+				};
+			};
+			// 1 lock or N lock
+			union {
+				__spinlock_t * lock;
+				struct {
+					__spinlock_t ** locks;
+					unsigned short lock_count;
+				};
+			};
+		};
+		// Option 2 : action pointer
+		__finish_callback_fptr_t callback;
+	};
+	/*/
+	thread_desc * thrd;
+	thread_desc ** thrds;
+	unsigned short thrd_count;
+	__spinlock_t * lock;
+	__spinlock_t ** locks;
+	unsigned short lock_count;
+	__finish_callback_fptr_t callback;
+	//*/
+};
+static inline void ?{}(FinishAction & this) {
+	this.action_code = No_Action;
+	this.thrd = NULL;
+	this.lock = NULL;
+}
+static inline void ^?{}(FinishAction & this) {}
+
+// Processor
+coroutine processorCtx_t {
+	struct processor * proc;
+};
+
+// Wrapper around kernel threads
+struct processor {
+	// Main state
+	// Coroutine ctx who does keeps the state of the processor
+	struct processorCtx_t runner;
+
+	// Cluster from which to get threads
+	struct cluster * cltr;
+
+	// Name of the processor
+	const char * name;
+
+	// Handle to pthreads
+	pthread_t kernel_thread;
+
+	// RunThread data
+	// Action to do after a thread is ran
+	struct FinishAction finish;
+
+	// Preemption data
+	// Node which is added in the discrete event simulaiton
+	struct alarm_node_t * preemption_alarm;
+
+	// If true, a preemption was triggered in an unsafe region, the processor must preempt as soon as possible
+	bool pending_preemption;
+
+	// Idle lock
+	__bin_sem_t idleLock;
+
+	// Termination
+	// Set to true to notify the processor should terminate
+	volatile bool do_terminate;
+
+	// Termination synchronisation
+	semaphore terminated;
+
+	// Link lists fields
+	struct __dbg_node_proc {
+		struct processor * next;
+		struct processor * prev;
+	} node;
+
+#ifdef __CFA_DEBUG__
+	// Last function to enable preemption on this processor
+	const char * last_enable;
+#endif
+};
+
+void  ?{}(processor & this, const char * name, struct cluster & cltr);
+void ^?{}(processor & this);
+
+static inline void  ?{}(processor & this)                    { this{ "Anonymous Processor", *mainCluster}; }
+static inline void  ?{}(processor & this, struct cluster & cltr)    { this{ "Anonymous Processor", cltr}; }
+static inline void  ?{}(processor & this, const char * name) { this{name, *mainCluster }; }
+
+static inline [processor *&, processor *& ] __get( processor & this ) {
+	return this.node.[next, prev];
+}
+
+//-----------------------------------------------------------------------------
+// Cluster
+struct cluster {
+	// Ready queue locks
+	__spinlock_t ready_queue_lock;
+
+	// Ready queue for threads
+	__queue_t(thread_desc) ready_queue;
+
+	// Name of the cluster
+	const char * name;
+
+	// Preemption rate on this cluster
+	Duration preemption_rate;
+
+	// List of processors
+	__spinlock_t proc_list_lock;
+	__dllist_t(struct processor) procs;
+	__dllist_t(struct processor) idles;
+
+	// List of processors
+	__spinlock_t thread_list_lock;
+	__dllist_t(struct thread_desc) threads;
+
+	// Link lists fields
+	struct __dbg_node_cltr {
+		cluster * next;
+		cluster * prev;
+	} node;
+};
+extern Duration default_preemption();
+
+void ?{} (cluster & this, const char * name, Duration preemption_rate);
+void ^?{}(cluster & this);
+
+static inline void ?{} (cluster & this)                           { this{"Anonymous Cluster", default_preemption()}; }
+static inline void ?{} (cluster & this, Duration preemption_rate) { this{"Anonymous Cluster", preemption_rate}; }
+static inline void ?{} (cluster & this, const char * name)        { this{name, default_preemption()}; }
+
+static inline [cluster *&, cluster *& ] __get( cluster & this ) {
+	return this.node.[next, prev];
+}
+
+// Local Variables: //
+// mode: c //
+// tab-width: 4 //
+// End: //
Index: libcfa/src/concurrency/kernel_private.h
===================================================================
--- libcfa/src/concurrency/kernel_private.h	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ 	(revision )
@@ -1,114 +1,0 @@
-//
-// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
-//
-// The contents of this file are covered under the licence agreement in the
-// file "LICENCE" distributed with Cforall.
-//
-// kernel_private.h --
-//
-// Author           : Thierry Delisle
-// Created On       : Mon Feb 13 12:27:26 2017
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Mar 29 14:06:40 2018
-// Update Count     : 3
-//
-
-#pragma once
-
-#include "kernel"
-#include "thread"
-
-#include "alarm.h"
-
-
-//-----------------------------------------------------------------------------
-// Scheduler
-
-extern "C" {
-	void disable_interrupts();
-	void enable_interrupts_noPoll();
-	void enable_interrupts( __cfaabi_dbg_ctx_param );
-}
-
-void ScheduleThread( thread_desc * );
-static inline void WakeThread( thread_desc * thrd ) {
-	if( !thrd ) return;
-
-	disable_interrupts();
-	ScheduleThread( thrd );
-	enable_interrupts( __cfaabi_dbg_ctx );
-}
-thread_desc * nextThread(cluster * this);
-
-//Block current thread and release/wake-up the following resources
-void BlockInternal(void);
-void BlockInternal(__spinlock_t * lock);
-void BlockInternal(thread_desc * thrd);
-void BlockInternal(__spinlock_t * lock, thread_desc * thrd);
-void BlockInternal(__spinlock_t * locks [], unsigned short count);
-void BlockInternal(__spinlock_t * locks [], unsigned short count, thread_desc * thrds [], unsigned short thrd_count);
-void BlockInternal(__finish_callback_fptr_t callback);
-void LeaveThread(__spinlock_t * lock, thread_desc * thrd);
-
-//-----------------------------------------------------------------------------
-// Processor
-void main(processorCtx_t *);
-
-static inline void wake_fast(processor * this) {
-	__cfaabi_dbg_print_safe("Kernel : Waking up processor %p\n", this);
-	post( this->idleLock );
-}
-
-static inline void wake(processor * this) {
-	disable_interrupts();
-	wake_fast(this);
-	enable_interrupts( __cfaabi_dbg_ctx );
-}
-
-struct event_kernel_t {
-	alarm_list_t alarms;
-	__spinlock_t lock;
-};
-
-extern event_kernel_t * event_kernel;
-
-struct __cfa_kernel_preemption_state_t {
-	bool enabled;
-	bool in_progress;
-	unsigned short disable_count;
-};
-
-extern volatile thread_local __cfa_kernel_preemption_state_t preemption_state;
-
-//-----------------------------------------------------------------------------
-// Threads
-extern "C" {
-      forall(dtype T | is_thread(T))
-      void CtxInvokeThread(T * this);
-}
-
-extern void ThreadCtxSwitch(coroutine_desc * src, coroutine_desc * dst);
-
-__cfaabi_dbg_debug_do(
-	extern void __cfaabi_dbg_thread_register  ( thread_desc * thrd );
-	extern void __cfaabi_dbg_thread_unregister( thread_desc * thrd );
-)
-
-//-----------------------------------------------------------------------------
-// Utils
-#define KERNEL_STORAGE(T,X) static char storage_##X[sizeof(T)]
-
-
-void doregister( struct cluster & cltr );
-void unregister( struct cluster & cltr );
-
-void doregister( struct cluster * cltr, struct thread_desc & thrd );
-void unregister( struct cluster * cltr, struct thread_desc & thrd );
-
-void doregister( struct cluster * cltr, struct processor * proc );
-void unregister( struct cluster * cltr, struct processor * proc );
-
-// Local Variables: //
-// mode: c //
-// tab-width: 4 //
-// End: //
Index: libcfa/src/concurrency/kernel_private.hfa
===================================================================
--- libcfa/src/concurrency/kernel_private.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
+++ libcfa/src/concurrency/kernel_private.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -0,0 +1,114 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// kernel_private.hfa --
+//
+// Author           : Thierry Delisle
+// Created On       : Mon Feb 13 12:27:26 2017
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Thu Mar 29 14:06:40 2018
+// Update Count     : 3
+//
+
+#pragma once
+
+#include "kernel"
+#include "thread"
+
+#include "alarm.hfa"
+
+
+//-----------------------------------------------------------------------------
+// Scheduler
+
+extern "C" {
+	void disable_interrupts();
+	void enable_interrupts_noPoll();
+	void enable_interrupts( __cfaabi_dbg_ctx_param );
+}
+
+void ScheduleThread( thread_desc * );
+static inline void WakeThread( thread_desc * thrd ) {
+	if( !thrd ) return;
+
+	disable_interrupts();
+	ScheduleThread( thrd );
+	enable_interrupts( __cfaabi_dbg_ctx );
+}
+thread_desc * nextThread(cluster * this);
+
+//Block current thread and release/wake-up the following resources
+void BlockInternal(void);
+void BlockInternal(__spinlock_t * lock);
+void BlockInternal(thread_desc * thrd);
+void BlockInternal(__spinlock_t * lock, thread_desc * thrd);
+void BlockInternal(__spinlock_t * locks [], unsigned short count);
+void BlockInternal(__spinlock_t * locks [], unsigned short count, thread_desc * thrds [], unsigned short thrd_count);
+void BlockInternal(__finish_callback_fptr_t callback);
+void LeaveThread(__spinlock_t * lock, thread_desc * thrd);
+
+//-----------------------------------------------------------------------------
+// Processor
+void main(processorCtx_t *);
+
+static inline void wake_fast(processor * this) {
+	__cfaabi_dbg_print_safe("Kernel : Waking up processor %p\n", this);
+	post( this->idleLock );
+}
+
+static inline void wake(processor * this) {
+	disable_interrupts();
+	wake_fast(this);
+	enable_interrupts( __cfaabi_dbg_ctx );
+}
+
+struct event_kernel_t {
+	alarm_list_t alarms;
+	__spinlock_t lock;
+};
+
+extern event_kernel_t * event_kernel;
+
+struct __cfa_kernel_preemption_state_t {
+	bool enabled;
+	bool in_progress;
+	unsigned short disable_count;
+};
+
+extern volatile thread_local __cfa_kernel_preemption_state_t preemption_state;
+
+//-----------------------------------------------------------------------------
+// Threads
+extern "C" {
+      forall(dtype T | is_thread(T))
+      void CtxInvokeThread(T * this);
+}
+
+extern void ThreadCtxSwitch(coroutine_desc * src, coroutine_desc * dst);
+
+__cfaabi_dbg_debug_do(
+	extern void __cfaabi_dbg_thread_register  ( thread_desc * thrd );
+	extern void __cfaabi_dbg_thread_unregister( thread_desc * thrd );
+)
+
+//-----------------------------------------------------------------------------
+// Utils
+#define KERNEL_STORAGE(T,X) static char storage_##X[sizeof(T)]
+
+
+void doregister( struct cluster & cltr );
+void unregister( struct cluster & cltr );
+
+void doregister( struct cluster * cltr, struct thread_desc & thrd );
+void unregister( struct cluster * cltr, struct thread_desc & thrd );
+
+void doregister( struct cluster * cltr, struct processor * proc );
+void unregister( struct cluster * cltr, struct processor * proc );
+
+// Local Variables: //
+// mode: c //
+// tab-width: 4 //
+// End: //
Index: libcfa/src/concurrency/monitor
===================================================================
--- libcfa/src/concurrency/monitor	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ 	(revision )
@@ -1,149 +1,0 @@
-//
-// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
-//
-// The contents of this file are covered under the licence agreement in the
-// file "LICENCE" distributed with Cforall.
-//
-// monitor --
-//
-// Author           : Thierry Delisle
-// Created On       : Thd Feb 23 12:27:26 2017
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Oct  7 18:06:45 2017
-// Update Count     : 10
-//
-
-#pragma once
-
-#include <stddef.h>
-
-#include <assert.h>
-#include "invoke.h"
-#include "stdlib"
-
-trait is_monitor(dtype T) {
-	monitor_desc * get_monitor( T & );
-	void ^?{}( T & mutex );
-};
-
-static inline void ?{}(monitor_desc & this) with( this ) {
-	lock{};
-	entry_queue{};
-	signal_stack{};
-	owner         = NULL;
-	recursion     = 0;
-	mask.accepted = NULL;
-	mask.data     = NULL;
-	mask.size     = 0;
-	dtor_node     = NULL;
-}
-
-struct monitor_guard_t {
-	monitor_desc ** 	m;
-	__lock_size_t   	count;
-	__monitor_group_t prev;
-};
-
-void ?{}( monitor_guard_t & this, monitor_desc ** m, __lock_size_t count, void (*func)() );
-void ^?{}( monitor_guard_t & this );
-
-struct monitor_dtor_guard_t {
-	monitor_desc *    m;
-	__monitor_group_t prev;
-};
-
-void ?{}( monitor_dtor_guard_t & this, monitor_desc ** m, void (*func)() );
-void ^?{}( monitor_dtor_guard_t & this );
-
-static inline forall( dtype T | sized(T) | { void ^?{}( T & mutex ); } )
-void delete( T * th ) {
-	^(*th){};
-	free( th );
-}
-
-//-----------------------------------------------------------------------------
-// Internal scheduling
-
-struct __condition_criterion_t {
-	// Whether or not the criterion is met (True if met)
-	bool ready;
-
-	// The monitor this criterion concerns
-	monitor_desc * target;
-
-	// The parent node to which this criterion belongs
-	struct __condition_node_t * owner;
-
-	// Intrusive linked list Next field
-	__condition_criterion_t * next;
-};
-
-static inline __condition_criterion_t * & get_next( __condition_criterion_t & this ) {
-	return this.next;
-}
-
-struct __condition_node_t {
-	// Thread that needs to be woken when all criteria are met
-	thread_desc * waiting_thread;
-
-	// Array of criteria (Criterions are contiguous in memory)
-	__condition_criterion_t * criteria;
-
-	// Number of criterions in the criteria
-	__lock_size_t count;
-
-	// Intrusive linked list Next field
-	__condition_node_t * next;
-
-	// Custom user info accessible before signalling
-	uintptr_t user_info;
-};
-
-static inline __condition_node_t * & get_next( __condition_node_t & this ) {
-	return this.next;
-}
-
-void ?{}(__condition_node_t & this, thread_desc * waiting_thread, __lock_size_t count, uintptr_t user_info );
-void ?{}(__condition_criterion_t & this );
-void ?{}(__condition_criterion_t & this, monitor_desc * target, __condition_node_t * owner );
-
-struct condition {
-	// Link list which contains the blocked threads as-well as the information needed to unblock them
-	__queue_t(__condition_node_t) blocked;
-
-	// Array of monitor pointers (Monitors are NOT contiguous in memory)
-	monitor_desc ** monitors;
-
-	// Number of monitors in the array
-	__lock_size_t monitor_count;
-};
-
-static inline void ?{}( condition & this ) {
-	this.monitors = NULL;
-	this.monitor_count = 0;
-}
-
-static inline void ^?{}( condition & this ) {
-	free( this.monitors );
-}
-
-              void wait        ( condition & this, uintptr_t user_info = 0 );
-              bool signal      ( condition & this );
-              bool signal_block( condition & this );
-static inline bool is_empty    ( condition & this ) { return !this.blocked.head; }
-         uintptr_t front       ( condition & this );
-
-//-----------------------------------------------------------------------------
-// External scheduling
-
-struct __acceptable_t {
-	inline struct __monitor_group_t;
-	bool is_dtor;
-};
-
-void __waitfor_internal( const __waitfor_mask_t & mask, int duration );
-
-// Local Variables: //
-// mode: c //
-// tab-width: 4 //
-// End: //
Index: libcfa/src/concurrency/monitor.cfa
===================================================================
--- libcfa/src/concurrency/monitor.cfa	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ libcfa/src/concurrency/monitor.cfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -16,10 +16,10 @@
 #include "monitor"
 
-#include <stdlib>
+#include <stdlib.hfa>
 #include <inttypes.h>
 
-#include "kernel_private.h"
-
-#include "bits/algorithms.h"
+#include "kernel_private.hfa"
+
+#include "bits/algorithms.hfa"
 
 //-----------------------------------------------------------------------------
Index: libcfa/src/concurrency/monitor.hfa
===================================================================
--- libcfa/src/concurrency/monitor.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
+++ libcfa/src/concurrency/monitor.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -0,0 +1,149 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// monitor --
+//
+// Author           : Thierry Delisle
+// Created On       : Thd Feb 23 12:27:26 2017
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Sat Oct  7 18:06:45 2017
+// Update Count     : 10
+//
+
+#pragma once
+
+#include <stddef.h>
+
+#include <assert.h>
+#include "invoke.h"
+#include "stdlib"
+
+trait is_monitor(dtype T) {
+	monitor_desc * get_monitor( T & );
+	void ^?{}( T & mutex );
+};
+
+static inline void ?{}(monitor_desc & this) with( this ) {
+	lock{};
+	entry_queue{};
+	signal_stack{};
+	owner         = NULL;
+	recursion     = 0;
+	mask.accepted = NULL;
+	mask.data     = NULL;
+	mask.size     = 0;
+	dtor_node     = NULL;
+}
+
+struct monitor_guard_t {
+	monitor_desc ** 	m;
+	__lock_size_t   	count;
+	__monitor_group_t prev;
+};
+
+void ?{}( monitor_guard_t & this, monitor_desc ** m, __lock_size_t count, void (*func)() );
+void ^?{}( monitor_guard_t & this );
+
+struct monitor_dtor_guard_t {
+	monitor_desc *    m;
+	__monitor_group_t prev;
+};
+
+void ?{}( monitor_dtor_guard_t & this, monitor_desc ** m, void (*func)() );
+void ^?{}( monitor_dtor_guard_t & this );
+
+static inline forall( dtype T | sized(T) | { void ^?{}( T & mutex ); } )
+void delete( T * th ) {
+	^(*th){};
+	free( th );
+}
+
+//-----------------------------------------------------------------------------
+// Internal scheduling
+
+struct __condition_criterion_t {
+	// Whether or not the criterion is met (True if met)
+	bool ready;
+
+	// The monitor this criterion concerns
+	monitor_desc * target;
+
+	// The parent node to which this criterion belongs
+	struct __condition_node_t * owner;
+
+	// Intrusive linked list Next field
+	__condition_criterion_t * next;
+};
+
+static inline __condition_criterion_t * & get_next( __condition_criterion_t & this ) {
+	return this.next;
+}
+
+struct __condition_node_t {
+	// Thread that needs to be woken when all criteria are met
+	thread_desc * waiting_thread;
+
+	// Array of criteria (Criterions are contiguous in memory)
+	__condition_criterion_t * criteria;
+
+	// Number of criterions in the criteria
+	__lock_size_t count;
+
+	// Intrusive linked list Next field
+	__condition_node_t * next;
+
+	// Custom user info accessible before signalling
+	uintptr_t user_info;
+};
+
+static inline __condition_node_t * & get_next( __condition_node_t & this ) {
+	return this.next;
+}
+
+void ?{}(__condition_node_t & this, thread_desc * waiting_thread, __lock_size_t count, uintptr_t user_info );
+void ?{}(__condition_criterion_t & this );
+void ?{}(__condition_criterion_t & this, monitor_desc * target, __condition_node_t * owner );
+
+struct condition {
+	// Link list which contains the blocked threads as-well as the information needed to unblock them
+	__queue_t(__condition_node_t) blocked;
+
+	// Array of monitor pointers (Monitors are NOT contiguous in memory)
+	monitor_desc ** monitors;
+
+	// Number of monitors in the array
+	__lock_size_t monitor_count;
+};
+
+static inline void ?{}( condition & this ) {
+	this.monitors = NULL;
+	this.monitor_count = 0;
+}
+
+static inline void ^?{}( condition & this ) {
+	free( this.monitors );
+}
+
+              void wait        ( condition & this, uintptr_t user_info = 0 );
+              bool signal      ( condition & this );
+              bool signal_block( condition & this );
+static inline bool is_empty    ( condition & this ) { return !this.blocked.head; }
+         uintptr_t front       ( condition & this );
+
+//-----------------------------------------------------------------------------
+// External scheduling
+
+struct __acceptable_t {
+	inline struct __monitor_group_t;
+	bool is_dtor;
+};
+
+void __waitfor_internal( const __waitfor_mask_t & mask, int duration );
+
+// Local Variables: //
+// mode: c //
+// tab-width: 4 //
+// End: //
Index: libcfa/src/concurrency/mutex
===================================================================
--- libcfa/src/concurrency/mutex	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ 	(revision )
@@ -1,171 +1,0 @@
-
-//                              -*- Mode: CFA -*-
-//
-// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
-//
-// The contents of this file are covered under the licence agreement in the
-// file "LICENCE" distributed with Cforall.
-//
-// mutex --
-//
-// Author           : Thierry Delisle
-// Created On       : Fri May 25 01:24:09 2018
-// Last Modified By : Thierry Delisle
-// Last Modified On : Fri May 25 01:24:12 2018
-// Update Count     : 0
-//
-
-#pragma once
-
-#include <stdbool.h>
-
-#include "bits/algorithms.h"
-#include "bits/locks.h"
-
-#include "invoke.h"
-#include "time_t.h"
-
-//-----------------------------------------------------------------------------
-// Locks
-
-// Exclusive lock - non-recursive
-// ---
-struct mutex_lock {
-	// Spin lock used for mutual exclusion
-	__spinlock_t lock;
-
-	// List of blocked threads
-	__queue_t(struct thread_desc) blocked_threads;
-
-	// Locked flag
-	bool is_locked;
-};
-
-void ?{}(mutex_lock & this);
-void ^?{}(mutex_lock & this);
-void lock(mutex_lock & this);
-bool try_lock(mutex_lock & this);
-void unlock(mutex_lock & this);
-
-// Exclusive lock - recursive
-// ---
-struct recursive_mutex_lock{
-	// Spin lock used for mutual exclusion
-	__spinlock_t lock;
-
-	// List of blocked threads
-	__queue_t(struct thread_desc) blocked_threads;
-
-	// Current thread owning the lock
-	struct thread_desc * owner;
-
-	// Number of recursion level
-	size_t recursion_count;
-};
-
-void ?{}(recursive_mutex_lock & this);
-void ^?{}(recursive_mutex_lock & this);
-void lock(recursive_mutex_lock & this);
-bool try_lock(recursive_mutex_lock & this);
-void unlock(recursive_mutex_lock & this);
-
-trait is_lock(dtype L | sized(L)) {
-	void lock  (L &);
-	void unlock(L &);
-};
-
-//-----------------------------------------------------------------------------
-// Condition variables
-
-struct condition_variable {
-	// Spin lock used for mutual exclusion
-	__spinlock_t lock;
-
-	// List of blocked threads
-	__queue_t(struct thread_desc) blocked_threads;
-};
-
-void ?{}(condition_variable & this);
-void ^?{}(condition_variable & this);
-
-void notify_one(condition_variable & this);
-void notify_all(condition_variable & this);
-
-void wait(condition_variable & this);
-
-forall(dtype L | is_lock(L))
-void wait(condition_variable & this, L & l);
-
-//-----------------------------------------------------------------------------
-// Scopes
-forall(dtype L | is_lock(L)) {
-	#if !defined( __TUPLE_ARRAYS_EXIST__ )
-	void lock  ( L * locks [], size_t count);
-	void unlock( L * locks [], size_t count);
-
-	struct lock_scope {
-		L **   locks;
-		size_t count;
-	};
-
-	static inline void ?{}(lock_scope(L) & this) {
-		this.locks = NULL;
-		this.count = 0;
-	}
-
-	static inline void ^?{}(lock_scope(L) & this) {
-		if(this.count > 0) {
-			unlock(this.locks, this.count);
-		}
-	}
-
-	static inline lock_scope(L) lock( L * locks [], size_t count, lock_scope(L) & scope) {
-		lock(locks, count);
-		scope.locks = locks;
-		scope.count = count;
-	}
-
-	static inline void unlock( lock_scope(L) & this ) {
-		unlock(this.locks, this.count);
-		this.count = 0;
-	}
-
-	static inline void release( lock_scope(L) & this ) {
-		this.count = 0;
-	}
-	#else
-	void lock( [L &...] locks );
-	void unlock( [L &...] locks );
-
-	forall(size_t N)
-	struct lock_scope {
-		bool released;
-		[L &... N] locks;
-	};
-
-	void ?{}(lock_scope(L) & this) = void;
-	void ?{}(lock_scope(L) & this, lock_scope(L) other) = void;
-	void ?move?(lock_scope(L) & this, lock_scope(L) & other) = default;
-
-	static inline void ^?{}(lock_scope(L) & this) {
-		if( !this.released ) {
-			unlock(this.locks);
-		}
-	}
-
-	forall(size_t N)
-	static inline lock_scope(L, N) lock( [L &...] locks ) {
-		lock(locks);
-		return @{false, locks};
-	}
-
-	static inline void unlock( lock_scope(L) & this ) {
-		unlock(this.locks);
-		this.released = true
-	}
-
-	static inline void release( lock_scope(L) & this ) {
-		this.released = true;
-	}
-	#endif
-}
Index: libcfa/src/concurrency/mutex.cfa
===================================================================
--- libcfa/src/concurrency/mutex.cfa	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ libcfa/src/concurrency/mutex.cfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -18,5 +18,5 @@
 #include "mutex"
 
-#include "kernel_private.h"
+#include "kernel_private.hfa"
 
 //-----------------------------------------------------------------------------
Index: libcfa/src/concurrency/mutex.hfa
===================================================================
--- libcfa/src/concurrency/mutex.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
+++ libcfa/src/concurrency/mutex.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -0,0 +1,171 @@
+
+//                              -*- Mode: CFA -*-
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// mutex --
+//
+// Author           : Thierry Delisle
+// Created On       : Fri May 25 01:24:09 2018
+// Last Modified By : Thierry Delisle
+// Last Modified On : Fri May 25 01:24:12 2018
+// Update Count     : 0
+//
+
+#pragma once
+
+#include <stdbool.h>
+
+#include "bits/algorithms.hfa"
+#include "bits/locks.hfa"
+
+#include "invoke.h"
+#include "time_t.hfa"
+
+//-----------------------------------------------------------------------------
+// Locks
+
+// Exclusive lock - non-recursive
+// ---
+struct mutex_lock {
+	// Spin lock used for mutual exclusion
+	__spinlock_t lock;
+
+	// List of blocked threads
+	__queue_t(struct thread_desc) blocked_threads;
+
+	// Locked flag
+	bool is_locked;
+};
+
+void ?{}(mutex_lock & this);
+void ^?{}(mutex_lock & this);
+void lock(mutex_lock & this);
+bool try_lock(mutex_lock & this);
+void unlock(mutex_lock & this);
+
+// Exclusive lock - recursive
+// ---
+struct recursive_mutex_lock{
+	// Spin lock used for mutual exclusion
+	__spinlock_t lock;
+
+	// List of blocked threads
+	__queue_t(struct thread_desc) blocked_threads;
+
+	// Current thread owning the lock
+	struct thread_desc * owner;
+
+	// Number of recursion level
+	size_t recursion_count;
+};
+
+void ?{}(recursive_mutex_lock & this);
+void ^?{}(recursive_mutex_lock & this);
+void lock(recursive_mutex_lock & this);
+bool try_lock(recursive_mutex_lock & this);
+void unlock(recursive_mutex_lock & this);
+
+trait is_lock(dtype L | sized(L)) {
+	void lock  (L &);
+	void unlock(L &);
+};
+
+//-----------------------------------------------------------------------------
+// Condition variables
+
+struct condition_variable {
+	// Spin lock used for mutual exclusion
+	__spinlock_t lock;
+
+	// List of blocked threads
+	__queue_t(struct thread_desc) blocked_threads;
+};
+
+void ?{}(condition_variable & this);
+void ^?{}(condition_variable & this);
+
+void notify_one(condition_variable & this);
+void notify_all(condition_variable & this);
+
+void wait(condition_variable & this);
+
+forall(dtype L | is_lock(L))
+void wait(condition_variable & this, L & l);
+
+//-----------------------------------------------------------------------------
+// Scopes
+forall(dtype L | is_lock(L)) {
+	#if !defined( __TUPLE_ARRAYS_EXIST__ )
+	void lock  ( L * locks [], size_t count);
+	void unlock( L * locks [], size_t count);
+
+	struct lock_scope {
+		L **   locks;
+		size_t count;
+	};
+
+	static inline void ?{}(lock_scope(L) & this) {
+		this.locks = NULL;
+		this.count = 0;
+	}
+
+	static inline void ^?{}(lock_scope(L) & this) {
+		if(this.count > 0) {
+			unlock(this.locks, this.count);
+		}
+	}
+
+	static inline lock_scope(L) lock( L * locks [], size_t count, lock_scope(L) & scope) {
+		lock(locks, count);
+		scope.locks = locks;
+		scope.count = count;
+	}
+
+	static inline void unlock( lock_scope(L) & this ) {
+		unlock(this.locks, this.count);
+		this.count = 0;
+	}
+
+	static inline void release( lock_scope(L) & this ) {
+		this.count = 0;
+	}
+	#else
+	void lock( [L &...] locks );
+	void unlock( [L &...] locks );
+
+	forall(size_t N)
+	struct lock_scope {
+		bool released;
+		[L &... N] locks;
+	};
+
+	void ?{}(lock_scope(L) & this) = void;
+	void ?{}(lock_scope(L) & this, lock_scope(L) other) = void;
+	void ?move?(lock_scope(L) & this, lock_scope(L) & other) = default;
+
+	static inline void ^?{}(lock_scope(L) & this) {
+		if( !this.released ) {
+			unlock(this.locks);
+		}
+	}
+
+	forall(size_t N)
+	static inline lock_scope(L, N) lock( [L &...] locks ) {
+		lock(locks);
+		return @{false, locks};
+	}
+
+	static inline void unlock( lock_scope(L) & this ) {
+		unlock(this.locks);
+		this.released = true
+	}
+
+	static inline void release( lock_scope(L) & this ) {
+		this.released = true;
+	}
+	#endif
+}
Index: libcfa/src/concurrency/preemption.cfa
===================================================================
--- libcfa/src/concurrency/preemption.cfa	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ libcfa/src/concurrency/preemption.cfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -14,5 +14,5 @@
 //
 
-#include "preemption.h"
+#include "preemption.hfa"
 #include <assert.h>
 
@@ -24,5 +24,5 @@
 }
 
-#include "bits/signal.h"
+#include "bits/signal.hfa"
 
 #if !defined(__CFA_DEFAULT_PREEMPTION__)
Index: libcfa/src/concurrency/preemption.h
===================================================================
--- libcfa/src/concurrency/preemption.h	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ 	(revision )
@@ -1,36 +1,0 @@
-//
-// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
-//
-// The contents of this file are covered under the licence agreement in the
-// file "LICENCE" distributed with Cforall.
-//
-// preemption.h --
-//
-// Author           : Thierry Delisle
-// Created On       : Mon Jun 5 14:20:42 2017
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Fri Mar 23 17:18:53 2018
-// Update Count     : 2
-//
-
-#pragma once
-
-#include "alarm.h"
-#include "kernel_private.h"
-
-void kernel_start_preemption();
-void kernel_stop_preemption();
-void update_preemption( processor * this, Duration duration );
-
-struct preemption_scope {
-	alarm_node_t alarm;
-	processor * proc;
-};
-
-void ?{}( preemption_scope & this, processor * proc );
-void ^?{}( preemption_scope & this );
-
-// Local Variables: //
-// mode: c //
-// tab-width: 4 //
-// End: //
Index: libcfa/src/concurrency/preemption.hfa
===================================================================
--- libcfa/src/concurrency/preemption.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
+++ libcfa/src/concurrency/preemption.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -0,0 +1,36 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// preemption.hfa --
+//
+// Author           : Thierry Delisle
+// Created On       : Mon Jun 5 14:20:42 2017
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Fri Mar 23 17:18:53 2018
+// Update Count     : 2
+//
+
+#pragma once
+
+#include "alarm.hfa"
+#include "kernel_private.hfa"
+
+void kernel_start_preemption();
+void kernel_stop_preemption();
+void update_preemption( processor * this, Duration duration );
+
+struct preemption_scope {
+	alarm_node_t alarm;
+	processor * proc;
+};
+
+void ?{}( preemption_scope & this, processor * proc );
+void ^?{}( preemption_scope & this );
+
+// Local Variables: //
+// mode: c //
+// tab-width: 4 //
+// End: //
Index: libcfa/src/concurrency/thread
===================================================================
--- libcfa/src/concurrency/thread	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ 	(revision )
@@ -1,96 +1,0 @@
-//
-// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
-//
-// The contents of this file are covered under the licence agreement in the
-// file "LICENCE" distributed with Cforall.
-//
-// thread --
-//
-// Author           : Thierry Delisle
-// Created On       : Tue Jan 17 12:27:26 2017
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Mar 29 14:07:11 2018
-// Update Count     : 4
-//
-
-#pragma once
-
-#include <assert.h>
-#include "invoke.h"
-
-#include "coroutine"
-#include "kernel"
-#include "monitor"
-
-//-----------------------------------------------------------------------------
-// thread trait
-trait is_thread(dtype T) {
-      void ^?{}(T& mutex this);
-      void main(T& this);
-      thread_desc* get_thread(T& this);
-};
-
-#define DECL_THREAD(X) thread_desc* get_thread(X& this) { return &this.__thrd; } void main(X& this)
-
-forall( dtype T | is_thread(T) )
-static inline coroutine_desc* get_coroutine(T & this) {
-	return &get_thread(this)->self_cor;
-}
-
-forall( dtype T | is_thread(T) )
-static inline monitor_desc* get_monitor(T & this) {
-	return &get_thread(this)->self_mon;
-}
-
-static inline coroutine_desc* get_coroutine(thread_desc * this) {
-	return &this->self_cor;
-}
-
-static inline monitor_desc* get_monitor(thread_desc * this) {
-	return &this->self_mon;
-}
-
-extern struct cluster * mainCluster;
-
-forall( dtype T | is_thread(T) )
-void __thrd_start( T & this );
-
-//-----------------------------------------------------------------------------
-// Ctors and dtors
-void ?{}(thread_desc & this, const char * const name, struct cluster & cl, void * storage, size_t storageSize );
-void ^?{}(thread_desc & this);
-
-static inline void ?{}(thread_desc & this)                                                                  { this{ "Anonymous Thread", *mainCluster, NULL, 0 }; }
-static inline void ?{}(thread_desc & this, size_t stackSize )                                               { this{ "Anonymous Thread", *mainCluster, NULL, stackSize }; }
-static inline void ?{}(thread_desc & this, void * storage, size_t storageSize )                             { this{ "Anonymous Thread", *mainCluster, storage, storageSize }; }
-static inline void ?{}(thread_desc & this, struct cluster & cl )                                            { this{ "Anonymous Thread", cl, NULL, 0 }; }
-static inline void ?{}(thread_desc & this, struct cluster & cl, size_t stackSize )                          { this{ "Anonymous Thread", cl, 0, stackSize }; }
-static inline void ?{}(thread_desc & this, struct cluster & cl, void * storage, size_t storageSize )        { this{ "Anonymous Thread", cl, storage, storageSize }; }
-static inline void ?{}(thread_desc & this, const char * const name)                                         { this{ name, *mainCluster, NULL, 0 }; }
-static inline void ?{}(thread_desc & this, const char * const name, struct cluster & cl )                   { this{ name, cl, NULL, 0 }; }
-static inline void ?{}(thread_desc & this, const char * const name, struct cluster & cl, size_t stackSize ) { this{ name, cl, NULL, stackSize }; }
-
-//-----------------------------------------------------------------------------
-// thread runner
-// Structure that actually start and stop threads
-forall( dtype T | sized(T) | is_thread(T) )
-struct scoped {
-	T handle;
-};
-
-forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
-void ?{}( scoped(T)& this );
-
-forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
-void ?{}( scoped(T)& this, P params );
-
-forall( dtype T | sized(T) | is_thread(T) )
-void ^?{}( scoped(T)& this );
-
-void yield();
-void yield( unsigned times );
-
-// Local Variables: //
-// mode: c //
-// tab-width: 4 //
-// End: //
Index: libcfa/src/concurrency/thread.cfa
===================================================================
--- libcfa/src/concurrency/thread.cfa	(revision 37fe3525f53534b29c07f4f1204c5f779836d193)
+++ libcfa/src/concurrency/thread.cfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -16,5 +16,5 @@
 #include "thread"
 
-#include "kernel_private.h"
+#include "kernel_private.hfa"
 
 #define __CFA_INVOKE_PRIVATE__
Index: libcfa/src/concurrency/thread.hfa
===================================================================
--- libcfa/src/concurrency/thread.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
+++ libcfa/src/concurrency/thread.hfa	(revision 73abe950d807eab747c9e14353b158fcca827308)
@@ -0,0 +1,96 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// thread --
+//
+// Author           : Thierry Delisle
+// Created On       : Tue Jan 17 12:27:26 2017
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Thu Mar 29 14:07:11 2018
+// Update Count     : 4
+//
+
+#pragma once
+
+#include <assert.h>
+#include "invoke.h"
+
+#include "coroutine"
+#include "kernel"
+#include "monitor"
+
+//-----------------------------------------------------------------------------
+// thread trait
+trait is_thread(dtype T) {
+      void ^?{}(T& mutex this);
+      void main(T& this);
+      thread_desc* get_thread(T& this);
+};
+
+#define DECL_THREAD(X) thread_desc* get_thread(X& this) { return &this.__thrd; } void main(X& this)
+
+forall( dtype T | is_thread(T) )
+static inline coroutine_desc* get_coroutine(T & this) {
+	return &get_thread(this)->self_cor;
+}
+
+forall( dtype T | is_thread(T) )
+static inline monitor_desc* get_monitor(T & this) {
+	return &get_thread(this)->self_mon;
+}
+
+static inline coroutine_desc* get_coroutine(thread_desc * this) {
+	return &this->self_cor;
+}
+
+static inline monitor_desc* get_monitor(thread_desc * this) {
+	return &this->self_mon;
+}
+
+extern struct cluster * mainCluster;
+
+forall( dtype T | is_thread(T) )
+void __thrd_start( T & this );
+
+//-----------------------------------------------------------------------------
+// Ctors and dtors
+void ?{}(thread_desc & this, const char * const name, struct cluster & cl, void * storage, size_t storageSize );
+void ^?{}(thread_desc & this);
+
+static inline void ?{}(thread_desc & this)                                                                  { this{ "Anonymous Thread", *mainCluster, NULL, 0 }; }
+static inline void ?{}(thread_desc & this, size_t stackSize )                                               { this{ "Anonymous Thread", *mainCluster, NULL, stackSize }; }
+static inline void ?{}(thread_desc & this, void * storage, size_t storageSize )                             { this{ "Anonymous Thread", *mainCluster, storage, storageSize }; }
+static inline void ?{}(thread_desc & this, struct cluster & cl )                                            { this{ "Anonymous Thread", cl, NULL, 0 }; }
+static inline void ?{}(thread_desc & this, struct cluster & cl, size_t stackSize )                          { this{ "Anonymous Thread", cl, 0, stackSize }; }
+static inline void ?{}(thread_desc & this, struct cluster & cl, void * storage, size_t storageSize )        { this{ "Anonymous Thread", cl, storage, storageSize }; }
+static inline void ?{}(thread_desc & this, const char * const name)                                         { this{ name, *mainCluster, NULL, 0 }; }
+static inline void ?{}(thread_desc & this, const char * const name, struct cluster & cl )                   { this{ name, cl, NULL, 0 }; }
+static inline void ?{}(thread_desc & this, const char * const name, struct cluster & cl, size_t stackSize ) { this{ name, cl, NULL, stackSize }; }
+
+//-----------------------------------------------------------------------------
+// thread runner
+// Structure that actually start and stop threads
+forall( dtype T | sized(T) | is_thread(T) )
+struct scoped {
+	T handle;
+};
+
+forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
+void ?{}( scoped(T)& this );
+
+forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
+void ?{}( scoped(T)& this, P params );
+
+forall( dtype T | sized(T) | is_thread(T) )
+void ^?{}( scoped(T)& this );
+
+void yield();
+void yield( unsigned times );
+
+// Local Variables: //
+// mode: c //
+// tab-width: 4 //
+// End: //
