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
3d0421da
Commit
3d0421da
authored
Jan 01, 2012
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pth support
parent
67bd88cf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
7 deletions
+81
-7
src/fiber.cpp
src/fiber.cpp
+81
-7
No files found.
src/fiber.cpp
View file @
3d0421da
...
...
@@ -33,18 +33,24 @@
#endif
#include <atomic>
#include <cstddef>
#include <cstring>
#include <cstdint>
#include <type_traits>
#include <ucontext.h>
#include <sys/mman.h>
#include <signal.h>
#include <cstddef>
#include "cppa/util/fiber.hpp"
#include "cppa/detail/thread.hpp"
#ifdef CPPA_USE_UCONTEXT_IMPL
#if defined(CPPA_USE_UCONTEXT_IMPL) || defined(CPPA_USE_PTH_IMPL)
#include <signal.h>
#include <sys/mman.h>
#ifdef CPPA_USE_PTH_IMPL
#include "pth.h"
#else
#include <ucontext.h>
#endif
namespace
{
...
...
@@ -135,6 +141,7 @@ void release_stack_node(stack_node* node)
typedef
void
(
*
void_function
)();
typedef
void
(
*
void_ptr_function
)(
void
*
);
#ifndef CPPA_USE_PTH_IMPL
template
<
size_t
PointerSize
,
typename
FunType
=
void_function
,
typename
IntType
=
int
>
...
...
@@ -188,11 +195,15 @@ struct trampoline<8, FunType, IntType>
4
,
func_addr
[
0
],
func_addr
[
1
],
arg_addr
[
0
],
arg_addr
[
1
]);
}
};
#else
cppa
::
detail
::
mutex
s_uctx_make_mtx
;
#endif
}
// namespace <anonymous>
namespace
cppa
{
namespace
util
{
#ifndef CPPA_USE_PTH_IMPL
struct
fiber_impl
{
...
...
@@ -216,6 +227,11 @@ struct fiber_impl
{
}
inline
void
swap
(
fiber_impl
*
to
)
{
swapcontext
(
&
(
m_ctx
),
&
(
to
->
m_ctx
));
}
void
initialize
()
{
m_initialized
=
true
;
...
...
@@ -239,7 +255,65 @@ struct fiber_impl
}
};
#else
struct
fiber_impl
{
bool
m_initialized
;
stack_node
*
m_node
;
void
(
*
m_func
)(
void
*
);
void
*
m_arg
;
pth_uctx_t
m_ctx
;
fiber_impl
()
throw
()
:
m_initialized
(
true
),
m_node
(
0
),
m_func
(
0
),
m_arg
(
0
)
{
memset
(
&
m_ctx
,
0
,
sizeof
(
pth_uctx_t
));
pth_uctx_create
(
&
m_ctx
);
}
fiber_impl
(
void
(
*
func
)(
void
*
),
void
*
arg
)
:
m_initialized
(
false
)
,
m_node
(
nullptr
)
,
m_func
(
func
)
,
m_arg
(
arg
)
{
}
inline
void
swap
(
fiber_impl
*
to
)
{
pth_uctx_switch
(
m_ctx
,
to
->
m_ctx
);
}
void
initialize
()
{
m_initialized
=
true
;
m_node
=
get_stack_node
();
memset
(
&
m_ctx
,
0
,
sizeof
(
pth_uctx_t
));
pth_uctx_create
(
&
m_ctx
);
// lifetime scope of guard
{
// pth uses static data to initialize m_ctx
detail
::
unique_lock
<
detail
::
mutex
>
guard
(
s_uctx_make_mtx
);
pth_uctx_make
(
m_ctx
,
reinterpret_cast
<
char
*>
(
m_node
->
s
),
STACK_SIZE
,
nullptr
,
m_func
,
m_arg
,
nullptr
);
}
}
inline
void
lazy_init
()
{
if
(
!
m_initialized
)
initialize
();
}
~
fiber_impl
()
{
if
(
m_node
)
release_stack_node
(
m_node
);
pth_uctx_destroy
(
m_ctx
);
}
};
#endif
fiber
::
fiber
()
throw
()
:
m_impl
(
new
fiber_impl
)
{
...
...
@@ -257,7 +331,7 @@ fiber::~fiber()
void
fiber
::
swap
(
fiber
&
from
,
fiber
&
to
)
{
to
.
m_impl
->
lazy_init
();
swapcontext
(
&
(
from
.
m_impl
->
m_ctx
),
&
(
to
.
m_impl
->
m_ctx
)
);
from
.
m_impl
->
swap
(
to
.
m_impl
);
}
}
}
// namespace cppa::util
...
...
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