On Tue, Jul 21, 2009 at 03:57:33PM +0400, Pavel Shevaev wrote:
However trying to build it on x86_64 gave me a compile time error - "This file is for x86 CPUs only" in swapcontext.cpp, since there is a #if !defined(i386) guard which produces this error.
Sorry, folks, I'm replying to myself - the problem was gone once I excluded swapcontext.cpp from my custom build process. Looks like coroutine cleverly fallbacks to POSIX makecontext and friends for anything non-linux-x86. Anyway, I believe it would be great to support linux x86_64 with a faster assembler implementation of swapcontext. I'll play around with the code and report back(if I'm lucky :) )
Download this code: http://simula.no/research/networks/software/nornir.tar.bz2/view (all files are under the same license as written in the COPYRIGHT file in the top-level directory) The functions you're after are: ctx_init_internal() and ctx_swap_internal() in nornir/kahn/ctx_amd64.S. For each new coroutine, you have to manually allocate context and stack; for an example of how this is done, see the ctx_make() function in platform_ux.cc. The ''main'' coroutine needs just the space for saving the registers, as the OS takes care of allocating the stack. The *_internal() functions operate just on the regs field of the mctx_t structure defined in platform_ux.h. The ctx_init() function takes the TOP address of the stack, as it grows down on AMD64. This should be enough to get you started with integrating the code in boost.coroutine; if you have some questions, just ask.