Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Kowalke committed Jul 17, 2011
0 parents commit db24843
Show file tree
Hide file tree
Showing 152 changed files with 14,411 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
bin.v2/**/*
dist/**/*
doc/**/*
html/**/*
stage/**/*
docbook*
*~
*.html
*.sw*
*.xml
15 changes: 15 additions & 0 deletions boost/context/all.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_CONTEXTS_ALL_H
#define BOOST_CONTEXTS_ALL_H

#include <boost/context/context.hpp>
#include <boost/context/fcontext.hpp>
#include <boost/context/protected_stack.hpp>
#include <boost/context/stack_helper.hpp>

#endif // BOOST_CONTEXTS_ALL_H
267 changes: 267 additions & 0 deletions boost/context/context.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@

// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_CONTEXTS_CONTEXT_H
#define BOOST_CONTEXTS_CONTEXT_H

#include <boost/assert.hpp>
#include <boost/bind.hpp>
#include <boost/config.hpp>
#include <boost/move/move.hpp>
#include <boost/preprocessor/repetition.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/utility/enable_if.hpp>

#include <boost/context/detail/context_base.hpp>
#include <boost/context/detail/context_object.hpp>
#include <boost/context/protected_stack.hpp>

#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif

namespace boost {
namespace contexts {

template< typename StackT = protected_stack >
class context
{
private:
typedef typename detail::context_base< StackT >::ptr_t base_ptr_t;

base_ptr_t impl_;

BOOST_MOVABLE_BUT_NOT_COPYABLE( context);

#ifndef BOOST_NO_RVALUE_REFERENCES
static base_ptr_t make_context_(
void( * fn)(), StackT && stack, bool do_unwind, bool do_return)
{
return base_ptr_t(
new detail::context_object< void(*)(), StackT >(
fn, boost::move( stack), do_unwind, do_return) );
}

static base_ptr_t make_context_(
void( * fn)(), StackT && stack, bool do_unwind, context & nxt)
{
BOOST_ASSERT( nxt);
return base_ptr_t(
new detail::context_object< void(*)(), StackT >(
fn, boost::move( stack), do_unwind, nxt.impl_) );
}

template< typename Fn >
static base_ptr_t make_context_(
Fn && fn, StackT && stack, bool do_unwind, bool do_return)
{
return base_ptr_t(
new detail::context_object< typename remove_reference< Fn >::type, StackT >(
fn, boost::move( stack), do_unwind, do_return) );
}

template< typename Fn >
static base_ptr_t make_context_(
Fn && fn, StackT && stack, bool do_unwind, context & nxt)
{
BOOST_ASSERT( nxt);
return base_ptr_t(
new detail::context_object< typename remove_reference< Fn >::type, StackT >(
fn, boost::move( stack), do_unwind, nxt.impl_) );
}
#else
template< typename Fn >
static base_ptr_t make_context_(
Fn fn, BOOST_RV_REF( StackT) stack, bool do_unwind, bool do_return)
{
return base_ptr_t(
new detail::context_object< Fn, StackT >(
fn, boost::move( stack), do_unwind, do_return) );
}

template< typename Fn >
static base_ptr_t make_context_(
Fn fn, BOOST_RV_REF( StackT) stack, bool do_unwind, context & nxt)
{
BOOST_ASSERT( nxt);
return base_ptr_t(
new detail::context_object< Fn, StackT >(
fn, boost::move( stack), do_unwind, nxt.impl_) );
}

template< typename Fn >
static base_ptr_t make_context_(
BOOST_RV_REF( Fn) fn, BOOST_RV_REF( StackT) stack, bool do_unwind, bool do_return)
{
return base_ptr_t(
new detail::context_object< Fn, StackT >(
fn, boost::move( stack), do_unwind, do_return) );
}

template< typename Fn >
static base_ptr_t make_context_(
BOOST_RV_REF( Fn) fn, BOOST_RV_REF( StackT) stack, bool do_unwind, context & nxt)
{
BOOST_ASSERT( nxt);
return base_ptr_t(
new detail::context_object< Fn, StackT >(
fn, boost::move( stack), do_unwind, nxt.impl_) );
}
#endif

public:
typedef void ( * unspecified_bool_type)( context ***);

static void unspecified_bool( context ***) {}

context() :
impl_()
{}

#ifndef BOOST_NO_RVALUE_REFERENCES
# ifdef BOOST_MSVC
template< typename Fn >
context( Fn & fn, StackT && stack, bool do_unwind, bool do_return = true) :
impl_( make_context_( static_cast< Fn & >( fn), boost::move( stack), do_unwind, do_return) )
{}

template< typename Fn >
context( Fn & fn, StackT && stack, bool do_unwind, context & nxt) :
impl_( make_context_( static_cast< Fn & >( fn), boost::move( stack), do_unwind, nxt) )
{}
# endif
template< typename Fn >
context( Fn && fn, StackT && stack, bool do_unwind, bool do_return = true) :
impl_( make_context_( static_cast< Fn && >( fn), boost::move( stack), do_unwind, do_return) )
{}

template< typename Fn >
context( Fn && fn, StackT && stack, bool do_unwind, context & nxt) :
impl_( make_context_( static_cast< Fn && >( fn), boost::move( stack), do_unwind, nxt) )
{}
#else
template< typename Fn >
context( Fn fn, BOOST_RV_REF( StackT) stack, bool do_unwind, bool do_return = true) :
impl_( make_context_( fn, boost::move( stack), do_unwind, do_return) )
{}

template< typename Fn >
context( Fn fn, BOOST_RV_REF( StackT) stack, bool do_unwind, context & nxt) :
impl_( make_context_( fn, boost::move( stack), do_unwind, nxt) )
{}

template< typename Fn >
context( BOOST_RV_REF( Fn) fn, BOOST_RV_REF( StackT) stack, bool do_unwind, bool do_return = true) :
impl_( make_context_( fn, boost::move( stack), do_unwind, do_return) )
{}

template< typename Fn >
context( BOOST_RV_REF( Fn) fn, BOOST_RV_REF( StackT) stack, bool do_unwind, context & nxt) :
impl_( make_context_( fn, boost::move( stack), do_unwind, nxt) )
{}
#endif

#define BOOST_CONTEXT_ARG(z, n, unused) BOOST_PP_CAT(A, n) BOOST_PP_CAT(a, n)

#define BOOST_CONTEXT_ARGS(n) BOOST_PP_ENUM(n, BOOST_CONTEXT_ARG, ~)

#define BOOST_CONTEXT_CTOR(z, n, unused) \
template< typename Fn, BOOST_PP_ENUM_PARAMS(n, typename A) > \
context( Fn fn, BOOST_CONTEXT_ARGS(n), BOOST_RV_REF( StackT) stack, bool do_unwind, bool do_return = true) : \
impl_( \
make_context_( \
boost::bind( boost::type< void >(), fn, BOOST_PP_ENUM_PARAMS(n, a) ), \
boost::move( stack), do_unwind, do_return) ) \
{} \
\
template< typename Fn, BOOST_PP_ENUM_PARAMS(n, typename A) > \
context( Fn fn, BOOST_CONTEXT_ARGS(n), BOOST_RV_REF( StackT) stack, bool do_unwind, context & nxt) : \
impl_( \
make_context_( \
boost::bind( boost::type< void >(), fn, BOOST_PP_ENUM_PARAMS(n, a) ), \
boost::move( stack), do_unwind, nxt) ) \
{} \

#ifndef BOOST_CONTEXT_ARITY
#define BOOST_CONTEXT_ARITY 10
#endif

BOOST_PP_REPEAT_FROM_TO( 1, BOOST_CONTEXT_ARITY, BOOST_CONTEXT_CTOR, ~)

#undef BOOST_CONTEXT_CTOR
#undef BOOST_CONTEXT_ARGS
#undef BOOST_CONTEXT_ARG

context( BOOST_RV_REF( context) other) :
impl_()
{ swap( other); }

context & operator=( BOOST_RV_REF( context) other)
{
if ( this == & other) return * this;
context tmp( boost::move( other) );
swap( tmp);
return * this;
}

operator unspecified_bool_type() const
{ return impl_ ? unspecified_bool : 0; }

bool operator!() const
{ return ! impl_; }

void swap( context & other)
{ impl_.swap( other.impl_); }

void resume()
{
BOOST_ASSERT( impl_);
return impl_->resume();
}

void suspend()
{
BOOST_ASSERT( impl_);
return impl_->suspend();
}

void unwind_stack()
{
BOOST_ASSERT( impl_);
impl_->unwind_stack();
}

bool is_complete() const
{
BOOST_ASSERT( impl_);
return impl_->is_complete();
}

bool owns_stack() const
{
BOOST_ASSERT( impl_);
return impl_->owns_stack();
}

StackT release_stack()
{
BOOST_ASSERT( impl_);
return impl_->release_stack();
}
};

template< typename StackT >
void swap( context< StackT > & l, context< StackT > & r)
{ l.swap( r); }

}}

#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif

#endif // BOOST_CONTEXTS_CONTEXT_H
31 changes: 31 additions & 0 deletions boost/context/detail/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_CONTEXTS_DETAIL_CONFIG_H
#define BOOST_CONTEXTS_DETAIL_CONFIG_H

#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>

#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_CONTEXT_DYN_LINK)
# if defined(BOOST_CONTEXT_SOURCE)
# define BOOST_CONTEXT_DECL BOOST_SYMBOL_EXPORT
# else
# define BOOST_CONTEXT_DECL BOOST_SYMBOL_IMPORT
# endif
#else
# define BOOST_CONTEXT_DECL
#endif

#if ! defined(BOOST_CONTEXT_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_CONTEXT_NO_LIB)
# define BOOST_LIB_NAME boost_context
# if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_CONTEXT_DYN_LINK)
# define BOOST_DYN_LINK
# endif
# include <boost/config/auto_link.hpp>
#endif

#endif // BOOST_CONTEXTS_DETAIL_CONFIG_H
31 changes: 31 additions & 0 deletions boost/context/detail/context_base.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <boost/config.hpp>

#if defined(BOOST_WINDOWS)
# if defined(BOOST_CONTEXT_FIBER)
# include <boost/context/detail/context_base_fiber.hpp>
# else
# if defined(_M_IX86)
# include <boost/context/detail/context_base_fctx_win32.hpp>
# elif defined(_M_X64)
# include <boost/context/detail/context_base_fctx_win64.hpp>
# else
# error "fcontext_t not supported by this architecture"
# endif
# endif
#else
# if defined(BOOST_CONTEXT_UCTX)
# include <boost/context/detail/context_base_uctx.hpp>
# else
# if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__mips__) || defined(__powerpc__)
# include <boost/context/detail/context_base_fctx_posix.hpp>
# else
# error "fcontext_t not supported by this architecture"
# endif
# endif
#endif
Loading

0 comments on commit db24843

Please sign in to comment.