ContextImplコンセプト

現時点のHamigaki.Coroutineのcoroutineは引数なし戻り値ありのコルーチンのみ対応しています。
coroutineのレベルで複数の実装を吸収しているため、これを汎用化させると実装ごとに汎用化の作業が発生してしまい、よくありません。
coroutineより下のレベルで抽象化が必要なので、Boost.CoroutineのContextImplコンセプトに合わせてみることにしました。
コンセプトの概要はdefault_context_impl.hppにコメントで書いてあります。
ContextImplコンセプトはこんな感じです。

class ContextImplBase
{
public:
    ContextImplBase();
    ContextImplBase(const ContextImplBase&);
    ContextImplBase& operator=(const ContextImplBase&);

    // 09/05修正: static -> friend & 非テンプレートに
    // コンテキストをfromからtoへ切り替える
    // Hintはdefault_hint, yield_hint, yield_to_hint, invoke_hintのいずれか
    frined void swap_context(
        ContextImplBase& from, const ContextImplBase& to, Hint);
};

class ContextImpl
{
public:
    typedef ContextImplBase context_impl_base;

    // fはコンテキストのエントリポイント関数オブジェクト
    // stack_sizeはスタックのサイズ
    template<typename Functor>
    ContextImpl(Functor f, std::ptrdiff_t stack_size);
}

これに合わせてpthreadを使った実装を書いてみました。
<hamigaki/coroutine/detail/pthread_context.hpp>
pthread_cleanup_push()を使ったのは初めてかもしれません。
Boost.Coroutineに組み込んで試したところ、うまく動いてくれました。
Hamigaki.CoroutineはContextImplに対応していないので、まだ試せません。


#今更ながら、Boost.Coroutineの名前空間が、boost::coroutinesであることに気が付いた、、、。