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
48ad408a
Commit
48ad408a
authored
Dec 15, 2012
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduced #ifdef statements to minimum
parent
c249a61c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
69 deletions
+69
-69
CMakeLists.txt
CMakeLists.txt
+8
-8
src/fiber.cpp
src/fiber.cpp
+61
-61
No files found.
CMakeLists.txt
View file @
48ad408a
cmake_minimum_required
(
VERSION 2.8
)
cmake_minimum_required
(
VERSION 2.8
)
project
(
cppa CXX
C
)
project
(
cppa CXX
)
set
(
LIBCPPA_VERSION_MAJOR 0
)
set
(
LIBCPPA_VERSION_MAJOR 0
)
set
(
LIBCPPA_VERSION_MINOR 5
)
set
(
LIBCPPA_VERSION_MINOR 5
)
...
@@ -30,14 +30,14 @@ else (CMAKE_CXX_FLAGS)
...
@@ -30,14 +30,14 @@ else (CMAKE_CXX_FLAGS)
set
(
CMAKE_CXX_FLAGS_RELWITHDEBINFO
"-O2 -g"
)
set
(
CMAKE_CXX_FLAGS_RELWITHDEBINFO
"-O2 -g"
)
endif
(
CMAKE_CXX_FLAGS
)
endif
(
CMAKE_CXX_FLAGS
)
include
(
CheckIncludeFiles
)
include
(
CheckIncludeFileCXX
)
check_include_files
(
"valgrind/valgrind.h"
HAVE_VALGRIND_H
)
check_include_file_cxx
(
"valgrind/valgrind.h"
HAVE_VALGRIND_H
)
set
(
VALGRIND
"no"
)
if
(
HAVE_VALGRIND_H
)
if
(
NOT HAVE_VALGRIND_H
)
add_definitions
(
-DNVALGRIND
)
else
(
NOT HAVE_VALGRIND_H
)
set
(
VALGRIND
"yes"
)
set
(
VALGRIND
"yes"
)
endif
(
NOT HAVE_VALGRIND_H
)
add_definitions
(
-DCPPA_ANNOTATE_VALGRIND
)
else
(
HAVE_VALGRIND_H
)
set
(
VALGRIND
"no"
)
endif
(
AVE_VALGRIND_H
)
# check for g++ >= 4.7 or clang++ > = 3.2
# check for g++ >= 4.7 or clang++ > = 3.2
try_run
(
ProgramResult
try_run
(
ProgramResult
...
...
src/fiber.cpp
View file @
48ad408a
...
@@ -51,7 +51,7 @@ void fiber::swap(fiber&, fiber&) {
...
@@ -51,7 +51,7 @@ void fiber::swap(fiber&, fiber&) {
#else // ifdef CPPA_DISABLE_CONTEXT_SWITCHING
#else // ifdef CPPA_DISABLE_CONTEXT_SWITCHING
#if
ndef N
VALGRIND
#if
def CPPA_ANNOTATE_
VALGRIND
#include <valgrind/valgrind.h>
#include <valgrind/valgrind.h>
#endif
#endif
#include <boost/version.hpp>
#include <boost/version.hpp>
...
@@ -59,39 +59,77 @@ void fiber::swap(fiber&, fiber&) {
...
@@ -59,39 +59,77 @@ void fiber::swap(fiber&, fiber&) {
namespace
cppa
{
namespace
util
{
namespace
cppa
{
namespace
util
{
class
fiber_impl
;
void
fiber_trampoline
(
intptr_t
iptr
);
void
fiber_trampoline
(
intptr_t
iptr
);
namespace
{
#if CPPA_ANNOTATE_VALGRIND
typedef
int
vg_member
;
inline
void
vg_register
(
vg_member
&
stack_id
,
void
*
ptr1
,
void
*
ptr2
)
{
stack_id
=
VALGRIND_STACK_REGISTER
(
ptr1
,
ptr2
);
}
inline
void
vg_deregister
(
vg_member
stack_id
)
{
VALGRIND_STACK_DEREGISTER
(
stack_id
);
}
#else
struct
vg_member
{
};
template
<
typename
...
Ts
>
inline
void
vg_register
(
const
Ts
&
...)
{
}
inline
void
vg_deregister
(
const
vg_member
&
)
{
}
#endif
#if BOOST_VERSION == 105100
#if BOOST_VERSION == 105100
namespace
ctx
=
boost
::
ctx
;
namespace
ctx
=
boost
::
ctx
;
typedef
ctx
::
fcontext_t
fc_member
;
typedef
ctx
::
stack_allocator
fc_allocator
;
inline
void
fc_jump
(
fc_member
&
from
,
fc_member
&
to
,
fiber_impl
*
ptr
)
{
ctx
::
jump_fcontext
(
&
from
,
&
to
,
(
intptr_t
)
ptr
);
}
inline
void
fc_make
(
fc_member
&
storage
,
fc_allocator
&
alloc
,
vg_member
&
vgm
)
{
size_t
stacksize
=
ctx
::
minimum_stacksize
();
storage
.
fc_stack
.
base
=
alloc
.
allocate
(
stacksize
);
storage
.
fc_stack
.
limit
=
reinterpret_cast
<
void
*>
(
reinterpret_cast
<
intptr_t
>
(
storage
.
fc_stack
.
base
)
-
stacksize
);
ctx
::
make_fcontext
(
&
storage
,
fiber_trampoline
);
vg_register
(
vgm
,
storage
.
fc_stack
.
base
,
reinterpret_cast
<
intptr_t
>
(
storage
.
fc_stack
.
base
)
-
stacksize
);
}
#else
#else
namespace
ctx
=
boost
::
context
;
namespace
ctx
=
boost
::
context
;
typedef
ctx
::
fcontext_t
*
fc_member
;
typedef
ctx
::
guarded_stack_allocator
fc_allocator
;
inline
void
fc_jump
(
fc_member
&
from
,
fc_member
&
to
,
fiber_impl
*
ptr
)
{
ctx
::
jump_fcontext
(
from
,
to
,
(
intptr_t
)
ptr
);
}
inline
void
fc_make
(
fc_member
&
storage
,
fc_allocator
&
alloc
,
vg_member
&
vgm
)
{
size_t
mss
=
fc_allocator
::
minimum_stacksize
();
storage
=
ctx
::
make_fcontext
(
alloc
.
allocate
(
mss
),
mss
,
fiber_trampoline
);
vg_register
(
vgm
,
storage
->
fc_stack
.
sp
,
reinterpret_cast
<
intptr_t
>
(
storage
->
fc_stack
.
sp
)
-
mss
);
}
#endif
#endif
}
// namespace <anonymous>
class
fiber_impl
{
class
fiber_impl
{
public:
public:
fiber_impl
()
:
m_ctx
{}
{
}
fiber_impl
()
:
m_ctx
()
{
}
virtual
~
fiber_impl
()
{
}
virtual
~
fiber_impl
()
{
}
virtual
void
run
()
{
}
virtual
void
run
()
{
}
void
swap
(
fiber_impl
*
to
)
{
void
swap
(
fiber_impl
*
to
)
{
#if BOOST_VERSION == 105100
fc_jump
(
m_ctx
,
to
->
m_ctx
,
to
);
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:
protected:
#if BOOST_VERSION == 105100
fc_member
m_ctx
;
ctx
::
fcontext_t
m_ctx
;
#else
ctx
::
fcontext_t
*
m_ctx
;
#endif
};
};
...
@@ -100,65 +138,31 @@ class converted_fiber : public fiber_impl {
...
@@ -100,65 +138,31 @@ class converted_fiber : public fiber_impl {
public:
public:
#if BOOST_VERSION == 105100
converted_fiber
()
{
converted_fiber
()
{
m_ctx
=
m_ctx_obj
;
}
# if BOOST_VERSION > 105100
#else
m_ctx
=
&
m_ctx_obj
;
converted_fiber
()
{
m_ctx
=
&
m_ctx_obj
;
}
# endif
#endif
}
private:
private:
# if BOOST_VERSION > 105100
ctx
::
fcontext_t
m_ctx_obj
;
ctx
::
fcontext_t
m_ctx_obj
;
# endif
};
};
// a fiber executing a function
// a fiber executing a function
class
fun_fiber
:
public
fiber_impl
{
class
fun_fiber
:
public
fiber_impl
{
#if BOOST_VERSION == 105100
typedef
ctx
::
stack_allocator
allocator
;
#else
typedef
ctx
::
guarded_stack_allocator
allocator
;
#endif
public:
public:
fun_fiber
(
void
(
*
fun
)(
void
*
),
void
*
arg
)
:
m_arg
(
arg
),
m_fun
(
fun
)
{
fun_fiber
(
void
(
*
fun
)(
void
*
),
void
*
arg
)
:
m_arg
(
arg
),
m_fun
(
fun
)
{
#if BOOST_VERSION == 105100
fc_make
(
m_ctx
,
m_alloc
,
m_vgm
);
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
()
{
~
fun_fiber
()
{
#ifndef NVALGRIND
vg_deregister
(
m_vgm
);
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
()
{
virtual
void
run
()
{
...
@@ -170,12 +174,8 @@ class fun_fiber : public fiber_impl {
...
@@ -170,12 +174,8 @@ class fun_fiber : public fiber_impl {
void
*
m_arg
;
void
*
m_arg
;
void
(
*
m_fun
)(
void
*
);
void
(
*
m_fun
)(
void
*
);
allocator
m_alloc
;
fc_allocator
m_alloc
;
#ifndef NVALGRIND
vg_member
m_vgm
;
//! 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