Index: libcfa/src/concurrency/io.cfa
===================================================================
--- libcfa/src/concurrency/io.cfa	(revision 7812a7b58de49d3c24921120d935d3f6008cfc21)
+++ libcfa/src/concurrency/io.cfa	(revision 31bb2e17e96e4d00c4451ec54598a4daac67e612)
@@ -38,11 +38,12 @@
 
 #else
+	#define _GNU_SOURCE         /* See feature_test_macros(7) */
+	#include <errno.h>
+	#include <stdint.h>
+	#include <string.h>
+	#include <unistd.h>
+	#include <sys/mman.h>
+
 	extern "C" {
-		#define _GNU_SOURCE         /* See feature_test_macros(7) */
-		#include <errno.h>
-		#include <stdint.h>
-		#include <string.h>
-		#include <unistd.h>
-		#include <sys/mman.h>
 		#include <sys/syscall.h>
 
@@ -420,9 +421,4 @@
 // I/O Polling
 //=============================================================================================
-	struct io_user_data {
-		int32_t result;
-		$thread * thrd;
-	};
-
 	// Process a single completion message from the io_uring
 	// This is NOT thread-safe
@@ -505,5 +501,5 @@
 			/* paranoid */ verify(&cqe);
 
-			struct io_user_data * data = (struct io_user_data *)(uintptr_t)cqe.user_data;
+			struct __io_user_data_t * data = (struct __io_user_data_t *)(uintptr_t)cqe.user_data;
 			__cfadbg_print_safe( io, "Kernel I/O : Performed reading io cqe %p, result %d for %p\n", data, cqe.res, data->thrd );
 
@@ -681,5 +677,5 @@
 //
 
-	static inline [* struct io_uring_sqe, uint32_t] __submit_alloc( struct __io_data & ring, uint64_t data ) {
+	[* struct io_uring_sqe, uint32_t] __submit_alloc( struct __io_data & ring, uint64_t data ) {
 		verify( data != 0 );
 
@@ -730,5 +726,5 @@
 	}
 
-	static inline void __submit( struct __io_data & ring, uint32_t idx ) {
+	void __submit( struct __io_data & ring, uint32_t idx ) {
 		// Get now the data we definetely need
 		uint32_t * const tail = ring.submit_q.tail;
@@ -834,404 +830,2 @@
 		this.len = len;
 	}
-
-
-//=============================================================================================
-// I/O Interface
-//=============================================================================================
-
-	#define __submit_prelude \
-		io_user_data data = { 0, active_thread() }; \
-		struct __io_data & ring = *data.thrd->curr_cluster->io; \
-		struct io_uring_sqe * sqe; \
-		uint32_t idx; \
-		[sqe, idx] = __submit_alloc( ring, (uint64_t)(uintptr_t)&data );
-
-	#define __submit_wait \
-		/*__cfaabi_bits_print_safe( STDERR_FILENO, "Preparing user data %p for %p\n", &data, data.thrd );*/ \
-		verify( sqe->user_data == (uint64_t)(uintptr_t)&data ); \
-		__submit( ring, idx ); \
-		park( __cfaabi_dbg_ctx ); \
-		return data.result;
-#endif
-
-// Some forward declarations
-extern "C" {
-	#include <unistd.h>
-	#include <sys/types.h>
-	#include <sys/socket.h>
-	#include <sys/syscall.h>
-
-#if defined(HAVE_PREADV2)
-	struct iovec;
-	extern ssize_t preadv2 (int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
-#endif
-#if defined(HAVE_PWRITEV2)
-	struct iovec;
-	extern ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
-#endif
-
-	extern int fsync(int fd);
-	extern int sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags);
-
-	struct msghdr;
-	struct sockaddr;
-	extern ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
-	extern ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
-	extern ssize_t send(int sockfd, const void *buf, size_t len, int flags);
-	extern ssize_t recv(int sockfd, void *buf, size_t len, int flags);
-	extern int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
-	extern int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
-
-	extern int fallocate(int fd, int mode, uint64_t offset, uint64_t len);
-	extern int posix_fadvise(int fd, uint64_t offset, uint64_t len, int advice);
-	extern int madvise(void *addr, size_t length, int advice);
-
-	extern int openat(int dirfd, const char *pathname, int flags, mode_t mode);
-	extern int close(int fd);
-
-	extern ssize_t read (int fd, void *buf, size_t count);
-}
-
-//-----------------------------------------------------------------------------
-// Asynchronous operations
-#if defined(HAVE_PREADV2)
-	ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags) {
-		#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_READV)
-			return preadv2(fd, iov, iovcnt, offset, flags);
-		#else
-			__submit_prelude
-
-			(*sqe){ IORING_OP_READV, fd, iov, iovcnt, offset };
-
-			__submit_wait
-		#endif
-	}
-#endif
-
-#if defined(HAVE_PWRITEV2)
-	ssize_t cfa_pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags) {
-		#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_WRITEV)
-			return pwritev2(fd, iov, iovcnt, offset, flags);
-		#else
-			__submit_prelude
-
-			(*sqe){ IORING_OP_WRITEV, fd, iov, iovcnt, offset };
-
-			__submit_wait
-		#endif
-	}
-#endif
-
-int cfa_fsync(int fd) {
-	#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_FSYNC)
-		return fsync(fd);
-	#else
-		__submit_prelude
-
-		(*sqe){ IORING_OP_FSYNC, fd };
-
-		__submit_wait
-	#endif
-}
-
-int cfa_sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags) {
-	#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SYNC_FILE_RANGE)
-		return sync_file_range(fd, offset, nbytes, flags);
-	#else
-		__submit_prelude
-
-		(*sqe){ IORING_OP_SYNC_FILE_RANGE, fd };
-		sqe->off = offset;
-		sqe->len = nbytes;
-		sqe->sync_range_flags = flags;
-
-		__submit_wait
-	#endif
-}
-
-
-ssize_t cfa_sendmsg(int sockfd, const struct msghdr *msg, int flags) {
-	#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SENDMSG)
-		return sendmsg(sockfd, msg, flags);
-	#else
-		__submit_prelude
-
-		(*sqe){ IORING_OP_SENDMSG, sockfd, msg, 1, 0 };
-		sqe->msg_flags = flags;
-
-		__submit_wait
-	#endif
-}
-
-ssize_t cfa_recvmsg(int sockfd, struct msghdr *msg, int flags) {
-	#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_RECVMSG)
-		return recvmsg(sockfd, msg, flags);
-	#else
-		__submit_prelude
-
-		(*sqe){ IORING_OP_RECVMSG, sockfd, msg, 1, 0 };
-		sqe->msg_flags = flags;
-
-		__submit_wait
-	#endif
-}
-
-ssize_t cfa_send(int sockfd, const void *buf, size_t len, int flags) {
-	#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SEND)
-		return send( sockfd, buf, len, flags );
-	#else
-		__submit_prelude
-
-		(*sqe){ IORING_OP_SEND, sockfd };
-		sqe->addr = (uint64_t)buf;
-		sqe->len = len;
-		sqe->msg_flags = flags;
-
-		__submit_wait
-	#endif
-}
-
-ssize_t cfa_recv(int sockfd, void *buf, size_t len, int flags) {
-	#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_RECV)
-		return recv( sockfd, buf, len, flags );
-	#else
-		__submit_prelude
-
-		(*sqe){ IORING_OP_RECV, sockfd };
-		sqe->addr = (uint64_t)buf;
-		sqe->len = len;
-		sqe->msg_flags = flags;
-
-		__submit_wait
-	#endif
-}
-
-int cfa_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
-	#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_ACCEPT)
-		return accept4( sockfd, addr, addrlen, flags );
-	#else
-		__submit_prelude
-
-		(*sqe){ IORING_OP_ACCEPT, sockfd };
-		sqe->addr = addr;
-		sqe->addr2 = addrlen;
-		sqe->accept_flags = flags;
-
-		__submit_wait
-	#endif
-}
-
-int cfa_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
-	#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_CONNECT)
-		return connect( sockfd, addr, addrlen );
-	#else
-		__submit_prelude
-
-		(*sqe){ IORING_OP_CONNECT, sockfd };
-		sqe->addr = (uint64_t)addr;
-		sqe->off = addrlen;
-
-		__submit_wait
-	#endif
-}
-
-int cfa_fallocate(int fd, int mode, uint64_t offset, uint64_t len) {
-	#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_FALLOCATE)
-		return fallocate( fd, mode, offset, len );
-	#else
-		__submit_prelude
-
-		(*sqe){ IORING_OP_FALLOCATE, fd };
-		sqe->off = offset;
-		sqe->len = length;
-		sqe->mode = mode;
-
-		__submit_wait
-	#endif
-}
-
-int cfa_fadvise(int fd, uint64_t offset, uint64_t len, int advice) {
-	#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_FADVISE)
-		return posix_fadvise( fd, offset, len, advice );
-	#else
-		__submit_prelude
-
-		(*sqe){ IORING_OP_FADVISE, fd };
-		sqe->off = (uint64_t)offset;
-		sqe->len = length;
-		sqe->fadvise_advice = advice;
-
-		__submit_wait
-	#endif
-}
-
-int cfa_madvise(void *addr, size_t length, int advice) {
-	#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_MADVISE)
-		return madvise( addr, length, advice );
-	#else
-		__submit_prelude
-
-		(*sqe){ IORING_OP_MADVISE, 0 };
-		sqe->addr = (uint64_t)addr;
-		sqe->len = length;
-		sqe->fadvise_advice = advice;
-
-		__submit_wait
-	#endif
-}
-
-int cfa_openat(int dirfd, const char *pathname, int flags, mode_t mode) {
-	#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_OPENAT)
-		return openat( dirfd, pathname, flags, mode );
-	#else
-		__submit_prelude
-
-		(*sqe){ IORING_OP_OPENAT, dirfd };
-		sqe->addr = (uint64_t)pathname;
-		sqe->open_flags = flags;
-		sqe->mode = mode;
-
-		__submit_wait
-	#endif
-}
-
-int cfa_close(int fd) {
-	#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_CLOSE)
-		return close( fd );
-	#else
-		__submit_prelude
-
-		(*sqe){ IORING_OP_CLOSE, fd };
-
-		__submit_wait
-	#endif
-}
-
-
-ssize_t cfa_read(int fd, void *buf, size_t count) {
-	#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_READ)
-		return read( fd, buf, count );
-	#else
-		__submit_prelude
-
-		(*sqe){ IORING_OP_READ, fd, buf, count, 0 };
-
-		__submit_wait
-	#endif
-}
-
-ssize_t cfa_write(int fd, void *buf, size_t count) {
-	#if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_WRITE)
-		return read( fd, buf, count );
-	#else
-		__submit_prelude
-
-		(*sqe){ IORING_OP_WRITE, fd, buf, count, 0 };
-
-		__submit_wait
-	#endif
-}
-
-//-----------------------------------------------------------------------------
-// Check if a function is asynchronous
-
-// Macro magic to reduce the size of the following switch case
-#define IS_DEFINED_APPLY(f, ...) f(__VA_ARGS__)
-#define IS_DEFINED_SECOND(first, second, ...) second
-#define IS_DEFINED_TEST(expansion) _CFA_IO_FEATURE_##expansion
-#define IS_DEFINED(macro) IS_DEFINED_APPLY( IS_DEFINED_SECOND,IS_DEFINED_TEST(macro) false, true)
-
-bool has_user_level_blocking( fptr_t func ) {
-	#if defined(HAVE_LINUX_IO_URING_H)
-		#if defined(HAVE_PREADV2)
-			if( /*func == (fptr_t)preadv2 || */
-				func == (fptr_t)cfa_preadv2 )
-				#define _CFA_IO_FEATURE_IORING_OP_READV ,
-				return IS_DEFINED(IORING_OP_READV);
-		#endif
-
-		#if defined(HAVE_PWRITEV2)
-			if( /*func == (fptr_t)pwritev2 || */
-				func == (fptr_t)cfa_pwritev2 )
-				#define _CFA_IO_FEATURE_IORING_OP_WRITEV ,
-				return IS_DEFINED(IORING_OP_WRITEV);
-		#endif
-
-		if( /*func == (fptr_t)fsync || */
-			func == (fptr_t)cfa_fsync )
-			#define _CFA_IO_FEATURE_IORING_OP_FSYNC ,
-			return IS_DEFINED(IORING_OP_FSYNC);
-
-		if( /*func == (fptr_t)ync_file_range || */
-			func == (fptr_t)cfa_sync_file_range )
-			#define _CFA_IO_FEATURE_IORING_OP_SYNC_FILE_RANGE ,
-			return IS_DEFINED(IORING_OP_SYNC_FILE_RANGE);
-
-		if( /*func == (fptr_t)sendmsg || */
-			func == (fptr_t)cfa_sendmsg )
-			#define _CFA_IO_FEATURE_IORING_OP_SENDMSG ,
-			return IS_DEFINED(IORING_OP_SENDMSG);
-
-		if( /*func == (fptr_t)recvmsg || */
-			func == (fptr_t)cfa_recvmsg )
-			#define _CFA_IO_FEATURE_IORING_OP_RECVMSG ,
-			return IS_DEFINED(IORING_OP_RECVMSG);
-
-		if( /*func == (fptr_t)send || */
-			func == (fptr_t)cfa_send )
-			#define _CFA_IO_FEATURE_IORING_OP_SEND ,
-			return IS_DEFINED(IORING_OP_SEND);
-
-		if( /*func == (fptr_t)recv || */
-			func == (fptr_t)cfa_recv )
-			#define _CFA_IO_FEATURE_IORING_OP_RECV ,
-			return IS_DEFINED(IORING_OP_RECV);
-
-		if( /*func == (fptr_t)accept4 || */
-			func == (fptr_t)cfa_accept4 )
-			#define _CFA_IO_FEATURE_IORING_OP_ACCEPT ,
-			return IS_DEFINED(IORING_OP_ACCEPT);
-
-		if( /*func == (fptr_t)connect || */
-			func == (fptr_t)cfa_connect )
-			#define _CFA_IO_FEATURE_IORING_OP_CONNECT ,
-			return IS_DEFINED(IORING_OP_CONNECT);
-
-		if( /*func == (fptr_t)fallocate || */
-			func == (fptr_t)cfa_fallocate )
-			#define _CFA_IO_FEATURE_IORING_OP_FALLOCATE ,
-			return IS_DEFINED(IORING_OP_FALLOCATE);
-
-		if( /*func == (fptr_t)posix_fadvise || */
-			func == (fptr_t)cfa_fadvise )
-			#define _CFA_IO_FEATURE_IORING_OP_FADVISE ,
-			return IS_DEFINED(IORING_OP_FADVISE);
-
-		if( /*func == (fptr_t)madvise || */
-			func == (fptr_t)cfa_madvise )
-			#define _CFA_IO_FEATURE_IORING_OP_MADVISE ,
-			return IS_DEFINED(IORING_OP_MADVISE);
-
-		if( /*func == (fptr_t)openat || */
-			func == (fptr_t)cfa_openat )
-			#define _CFA_IO_FEATURE_IORING_OP_OPENAT ,
-			return IS_DEFINED(IORING_OP_OPENAT);
-
-		if( /*func == (fptr_t)close || */
-			func == (fptr_t)cfa_close )
-			#define _CFA_IO_FEATURE_IORING_OP_CLOSE ,
-			return IS_DEFINED(IORING_OP_CLOSE);
-
-		if( /*func == (fptr_t)read || */
-			func == (fptr_t)cfa_read )
-			#define _CFA_IO_FEATURE_IORING_OP_READ ,
-			return IS_DEFINED(IORING_OP_READ);
-
-		if( /*func == (fptr_t)write || */
-			func == (fptr_t)cfa_write )
-			#define _CFA_IO_FEATURE_IORING_OP_WRITE ,
-			return IS_DEFINED(IORING_OP_WRITE);
-	#endif
-
-	return false;
-}
