Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
c249a61c
Commit
c249a61c
authored
Dec 14, 2012
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/toffaletti/libcppa
into unstable
parents
756ca14c
1ea993b2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
7 deletions
+74
-7
CMakeLists.txt
CMakeLists.txt
+12
-2
src/fiber.cpp
src/fiber.cpp
+62
-5
No files found.
CMakeLists.txt
View file @
c249a61c
cmake_minimum_required
(
VERSION 2.8
)
project
(
cppa CXX
)
project
(
cppa CXX
C
)
set
(
LIBCPPA_VERSION_MAJOR 0
)
set
(
LIBCPPA_VERSION_MINOR 5
)
...
...
@@ -30,6 +30,15 @@ else (CMAKE_CXX_FLAGS)
set
(
CMAKE_CXX_FLAGS_RELWITHDEBINFO
"-O2 -g"
)
endif
(
CMAKE_CXX_FLAGS
)
include
(
CheckIncludeFiles
)
check_include_files
(
"valgrind/valgrind.h"
HAVE_VALGRIND_H
)
set
(
VALGRIND
"no"
)
if
(
NOT HAVE_VALGRIND_H
)
add_definitions
(
-DNVALGRIND
)
else
(
NOT HAVE_VALGRIND_H
)
set
(
VALGRIND
"yes"
)
endif
(
NOT HAVE_VALGRIND_H
)
# check for g++ >= 4.7 or clang++ > = 3.2
try_run
(
ProgramResult
CompilationSucceeded
...
...
@@ -162,7 +171,7 @@ set(LD_FLAGS ${CMAKE_LD_LIBS} ${PTHREAD_LIBRARIES})
if
(
DISABLE_CONTEXT_SWITCHING
)
# explicitly disabled
else
(
DISABLE_CONTEXT_SWITCHING
)
find_package
(
Boost 1.5
2
.0 COMPONENTS context
)
find_package
(
Boost 1.5
1
.0 COMPONENTS context
)
# without REQUIRED, find_package(Boost...) returns with Boost_FOUND=FALSE
if
(
NOT Boost_FOUND
)
set
(
DISABLE_CONTEXT_SWITCHING true
)
...
...
@@ -347,6 +356,7 @@ message("\n====================| Build Summary |===================="
"
\n
Debug mode:
${
DEBUG_MODE_STR
}
"
"
\n
Log level:
${
LOG_LEVEL_STR
}
"
"
\n
Context switching:
${
CONTEXT_SWITCHING
}
"
"
\n
Valgrind:
${
VALGRIND
}
"
"
\n
Build examples:
${
BUILD_EXAMPLES
}
"
"
\n
Build unit tests:
${
BUILD_UNIT_TESTS
}
"
"
\n
Build static:
${
CPPA_BUILD_STATIC
}
"
...
...
src/fiber.cpp
View file @
c249a61c
...
...
@@ -51,31 +51,47 @@ void fiber::swap(fiber&, fiber&) {
#else // ifdef CPPA_DISABLE_CONTEXT_SWITCHING
#ifndef NVALGRIND
#include <valgrind/valgrind.h>
#endif
#include <boost/version.hpp>
#include <boost/context/all.hpp>
namespace
cppa
{
namespace
util
{
void
fiber_trampoline
(
intptr_t
iptr
);
#if BOOST_VERSION == 105100
namespace
ctx
=
boost
::
ctx
;
#else
namespace
ctx
=
boost
::
context
;
#endif
class
fiber_impl
{
public:
fiber_impl
()
:
m_ctx
(
nullptr
)
{
}
fiber_impl
()
:
m_ctx
{}
{
}
virtual
~
fiber_impl
()
{
}
virtual
void
run
()
{
}
void
swap
(
fiber_impl
*
to
)
{
#if BOOST_VERSION == 105100
ctx
::
jump_fcontext
(
&
m_ctx
,
&
to
->
m_ctx
,
(
intptr_t
)
to
);
#else
ctx
::
jump_fcontext
(
m_ctx
,
to
->
m_ctx
,
(
intptr_t
)
to
);
#endif
}
protected:
#if BOOST_VERSION == 105100
ctx
::
fcontext_t
m_ctx
;
#else
ctx
::
fcontext_t
*
m_ctx
;
#endif
};
...
...
@@ -84,7 +100,11 @@ class converted_fiber : public fiber_impl {
public:
#if BOOST_VERSION == 105100
converted_fiber
()
{
m_ctx
=
m_ctx_obj
;
}
#else
converted_fiber
()
{
m_ctx
=
&
m_ctx_obj
;
}
#endif
private:
...
...
@@ -95,17 +115,50 @@ class converted_fiber : public fiber_impl {
// a fiber executing a function
class
fun_fiber
:
public
fiber_impl
{
#if BOOST_VERSION == 105100
typedef
ctx
::
stack_allocator
allocator
;
#else
typedef
ctx
::
guarded_stack_allocator
allocator
;
#endif
public:
fun_fiber
(
void
(
*
fun
)(
void
*
),
void
*
arg
)
:
m_arg
(
arg
),
m_fun
(
fun
)
{
m_size
=
allocator
::
minimum_stacksize
();
m_ctx
=
ctx
::
make_fcontext
(
m_alloc
.
allocate
(
m_size
),
m_size
,
fiber_trampoline
);
#if BOOST_VERSION == 105100
size_t
stacksize
=
ctx
::
minimum_stacksize
();
m_ctx
.
fc_stack
.
base
=
m_alloc
.
allocate
(
stacksize
);
m_ctx
.
fc_stack
.
limit
=
reinterpret_cast
<
void
*>
(
reinterpret_cast
<
intptr_t
>
(
m_ctx
.
fc_stack
.
base
)
-
stacksize
);
ctx
::
make_fcontext
(
&
m_ctx
,
fiber_trampoline
);
#ifndef NVALGRIND
m_valgrind_stack_id
=
VALGRIND_STACK_REGISTER
(
m_ctx
.
fc_stack
.
base
,
reinterpret_cast
<
intptr_t
>
(
m_ctx
.
fc_stack
.
base
)
-
stacksize
);
#endif
#else // BOOST_VERSION
size_t
stacksize
=
allocator
::
minimum_stacksize
();
m_ctx
=
ctx
::
make_fcontext
(
m_alloc
.
allocate
(
stacksize
),
stacksize
,
fiber_trampoline
);
#ifndef NVALGRIND
m_valgrind_stack_id
=
VALGRIND_STACK_REGISTER
(
m_ctx
->
fc_stack
.
sp
,
reinterpret_cast
<
intptr_t
>
(
m_ctx
->
fc_stack
.
sp
)
-
stacksize
);
#endif
#endif // BOOST_VERSION
}
~
fun_fiber
()
{
m_alloc
.
deallocate
(
m_ctx
->
fc_stack
.
sp
,
m_size
);
#ifndef NVALGRIND
VALGRIND_STACK_DEREGISTER
(
m_valgrind_stack_id
);
#endif
#if BOOST_VERSION == 105100
size_t
stacksize
=
reinterpret_cast
<
intptr_t
>
(
m_ctx
.
fc_stack
.
base
)
-
reinterpret_cast
<
intptr_t
>
(
m_ctx
.
fc_stack
.
base
);
m_alloc
.
deallocate
(
m_ctx
.
fc_stack
.
base
,
stacksize
);
#else
m_alloc
.
deallocate
(
m_ctx
->
fc_stack
.
sp
,
m_ctx
->
fc_stack
.
size
);
#endif
}
virtual
void
run
()
{
...
...
@@ -117,8 +170,12 @@ class fun_fiber : public fiber_impl {
void
*
m_arg
;
void
(
*
m_fun
)(
void
*
);
size_t
m_size
;
allocator
m_alloc
;
#ifndef NVALGRIND
//! stack id so valgrind doesn't freak when stack swapping happens
int
m_valgrind_stack_id
;
#endif
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment