Index: src/libcfa/concurrency/threads
===================================================================
--- src/libcfa/concurrency/threads	(revision 80d9e49c456e684d40f6c36e46ac4cd4b438d54c)
+++ src/libcfa/concurrency/threads	(revision f7ff3fba1d98de23216f2c17fe82d71ab5e67308)
@@ -18,10 +18,11 @@
 #define __THREADS_H__
 
+#include "assert"       //
 #include "invoke.h"
 
-void ?{}(coStack_t* this);
-
-void ?{}(coroutine* this);
-
+//-----------------------------------------------------------------------------
+// Coroutine trait
+// Anything that implements this trait can be resumed.
+// Anything that is resumed is a coroutine.
 trait is_coroutine(dtype T) {
       void co_main(T* this);
@@ -29,11 +30,84 @@
 };
 
-void suspend(void);
+//-----------------------------------------------------------------------------
+// Ctors and dtors
+void ?{}(coStack_t* this);
+void ?{}(coroutine* this);
+void ^?{}(coStack_t* this);
+void ^?{}(coroutine* this);
+
+//-----------------------------------------------------------------------------
+// Public coroutine API
+static inline void suspend();
 
 forall(dtype T | is_coroutine(T))
-void resume(T* cor);
+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*));
+}
+
+// Get current coroutine
+extern coroutine* current_coroutine; //PRIVATE, never use directly
+static inline coroutine* this_coroutine(void) {
+	return current_coroutine;
+}
+
+// Private wrappers for context switch and stack creation
+extern void corCxtSw(coroutine* src, coroutine* dst);
+extern void create_stack( coStack_t* this, unsigned int storageSize );
+
+// Suspend implementation inlined for performance
+static inline void suspend() {
+      coroutine* src = this_coroutine();		// optimization
+
+	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->notHalted, 
+		"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 );
+
+	corCxtSw( src, src->last );
+}
+
+// Resume implementation inlined for performance
+forall(dtype T | is_coroutine(T))
+static inline void resume(T* cor) {
+	coroutine* src = this_coroutine();		// optimization
+	coroutine* 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->notHalted , 
+			"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;
+	} // if
+
+      // always done for performance testing
+	corCxtSw( src, dst );
+}
 
 #endif //__THREADS_H__
