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
d713ec10
Commit
d713ec10
authored
Jul 10, 2012
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed build with CPPA_DISABLE_CONTEXT_SWITCHING set
parent
e9ce5447
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
110 additions
and
46 deletions
+110
-46
cppa/context_switching_actor.hpp
cppa/context_switching_actor.hpp
+1
-6
cppa/detail/thread_pool_scheduler.hpp
cppa/detail/thread_pool_scheduler.hpp
+0
-14
cppa/util/fiber.hpp
cppa/util/fiber.hpp
+0
-16
src/fiber.cpp
src/fiber.cpp
+18
-4
src/thread_pool_scheduler.cpp
src/thread_pool_scheduler.cpp
+34
-6
unit_testing/test__spawn.cpp
unit_testing/test__spawn.cpp
+57
-0
No files found.
cppa/context_switching_actor.hpp
View file @
d713ec10
...
...
@@ -31,12 +31,9 @@
#ifndef CPPA_CONTEXT_SWITCHING_ACTOR_HPP
#define CPPA_CONTEXT_SWITCHING_ACTOR_HPP
#include "cppa/config.hpp"
#ifndef CPPA_DISABLE_CONTEXT_SWITCHING
#include <stack>
#include "cppa/config.hpp"
#include "cppa/either.hpp"
#include "cppa/pattern.hpp"
...
...
@@ -122,6 +119,4 @@ class context_switching_actor : public detail::stacked_actor_mixin<
}
// namespace cppa
#endif // CPPA_DISABLE_CONTEXT_SWITCHING
#endif // CPPA_CONTEXT_SWITCHING_ACTOR_HPP
cppa/detail/thread_pool_scheduler.hpp
View file @
d713ec10
...
...
@@ -81,20 +81,6 @@ class thread_pool_scheduler : public scheduler {
actor_ptr
spawn_as_thread
(
void_function
fun
,
init_callback
cb
,
bool
hidden
);
# ifndef CPPA_DISABLE_CONTEXT_SWITCHING
template
<
typename
F
>
actor_ptr
spawn_impl
(
void_function
fun
,
scheduling_hint
sh
,
F
cb
)
{
if
(
sh
==
scheduled
)
{
scheduled_actor_ptr
ptr
{
new
context_switching_actor
(
std
::
move
(
fun
))};
ptr
->
attach_to_scheduler
(
this
);
cb
(
ptr
.
get
());
return
spawn_impl
(
std
::
move
(
ptr
));
}
else
{
return
spawn_as_thread
(
std
::
move
(
fun
),
std
::
move
(
cb
));
}
}
# endif
};
}
}
// namespace cppa::detail
...
...
cppa/util/fiber.hpp
View file @
d713ec10
...
...
@@ -31,20 +31,6 @@
#ifndef CPPA_FIBER_HPP
#define CPPA_FIBER_HPP
#include <memory>
#include "cppa/config.hpp"
#ifdef CPPA_DISABLE_CONTEXT_SWITCHING
namespace
cppa
{
namespace
util
{
class
fiber
{
public:
inline
static
void
swap
(
fiber
&
,
fiber
&
)
{
}
};
}
}
// namespace cppa::util
#else // CPPA_DISABLE_CONTEXT_SWITCHING
namespace
cppa
{
namespace
util
{
struct
fiber_impl
;
...
...
@@ -69,6 +55,4 @@ class fiber {
}
}
// namespace cppa::util
#endif // CPPA_DISABLE_CONTEXT_SWITCHING
#endif // CPPA_FIBER_HPP
src/fiber.cpp
View file @
d713ec10
...
...
@@ -28,17 +28,31 @@
\******************************************************************************/
#include <cstdint>
#include <stdexcept>
#include "cppa/util/fiber.hpp"
#ifdef CPPA_DISABLE_CONTEXT_SWITCHING
namespace
{
int
keep_compiler_happy
()
{
return
42
;
}
}
namespace
cppa
{
namespace
util
{
fiber
::
fiber
()
throw
()
:
m_impl
(
nullptr
)
{
}
fiber
::
fiber
(
void
(
*
)(
void
*
),
void
*
)
:
m_impl
(
nullptr
)
{
}
fiber
::~
fiber
()
{
}
void
fiber
::
swap
(
fiber
&
,
fiber
&
)
{
throw
std
::
logic_error
(
"libcppa was compiled using "
"CPPA_DISABLE_CONTEXT_SWITCHING"
);
}
}
}
// namespace cppa::util
#else // ifdef CPPA_DISABLE_CONTEXT_SWITCHING
#include <cstdint>
#include <boost/context/all.hpp>
#include "cppa/util/fiber.hpp"
namespace
cppa
{
namespace
util
{
void
fiber_trampoline
(
intptr_t
iptr
);
...
...
src/thread_pool_scheduler.cpp
View file @
d713ec10
...
...
@@ -51,6 +51,24 @@ namespace {
typedef
std
::
unique_lock
<
std
::
mutex
>
guard_type
;
typedef
intrusive
::
single_reader_queue
<
thread_pool_scheduler
::
worker
>
worker_queue
;
/*
template<typename F>
actor_ptr spawn_void_fun_impl(thread_pool_scheduler* _this,
void_function fun,
scheduling_hint sh,
F cb ) {
if (sh == scheduled) {
scheduled_actor_ptr ptr{new context_switching_actor(std::move(fun))};
ptr->attach_to_scheduler(_this);
cb(ptr.get());
return _this->spawn_impl(std::move(ptr));
}
else {
return _this->spawn_as_thread(std::move(fun), std::move(cb));
}
}
*/
}
// namespace <anonmyous>
struct
thread_pool_scheduler
::
worker
{
...
...
@@ -245,6 +263,7 @@ actor_ptr thread_pool_scheduler::spawn(scheduled_actor* raw, init_callback cb) {
}
#ifndef CPPA_DISABLE_CONTEXT_SWITCHING
actor_ptr
thread_pool_scheduler
::
spawn
(
void_function
fun
,
scheduling_hint
sh
)
{
if
(
sh
==
scheduled
)
{
scheduled_actor_ptr
ptr
{
new
context_switching_actor
(
std
::
move
(
fun
))};
...
...
@@ -267,17 +286,26 @@ actor_ptr thread_pool_scheduler::spawn(void_function fun,
return
spawn_impl
(
std
::
move
(
ptr
));
}
else
{
return
spawn_as_thread
(
std
::
move
(
fun
),
std
::
move
(
init_cb
),
sh
==
detached_and_hidden
);
return
spawn_as_thread
(
std
::
move
(
fun
),
std
::
move
(
init_cb
),
sh
==
detached_and_hidden
);
}
}
#else
actor_ptr
thread_pool_scheduler
::
spawn
(
void_function
what
,
scheduling_hint
)
{
return
spawn_as_thread
(
std
::
move
(
what
),
[](
local_actor
*
)
{
});
#else // CPPA_DISABLE_CONTEXT_SWITCHING
actor_ptr
thread_pool_scheduler
::
spawn
(
void_function
what
,
scheduling_hint
sh
)
{
return
spawn_as_thread
(
std
::
move
(
what
),
[](
local_actor
*
)
{
},
sh
==
detached_and_hidden
);
}
actor_ptr
thread_pool_scheduler
::
spawn
(
void_function
what
,
scheduling_hint
,
scheduling_hint
sh
,
init_callback
init_cb
)
{
return
spawn_as_thread
(
std
::
move
(
what
),
std
::
move
(
init_cb
));
return
spawn_as_thread
(
std
::
move
(
what
),
std
::
move
(
init_cb
),
sh
==
detached_and_hidden
);
}
#endif
...
...
unit_testing/test__spawn.cpp
View file @
d713ec10
...
...
@@ -604,6 +604,63 @@ size_t test__spawn() {
await_all_others_done
();
CPPA_IF_VERBOSE
(
cout
<<
"ok"
<<
endl
);
auto
inflater
=
factory
::
event_based
(
[](
std
::
string
*
,
actor_ptr
*
receiver
)
{
self
->
become
(
on_arg_match
>>
[
=
](
int
n
,
const
std
::
string
&
s
)
{
send
(
*
receiver
,
n
*
2
,
s
);
},
on
(
atom
(
"done"
))
>>
[]()
{
self
->
quit
();
}
);
}
);
auto
joe
=
inflater
.
spawn
(
"Joe"
,
self
);
auto
bob
=
inflater
.
spawn
(
"Bob"
,
joe
);
send
(
bob
,
1
,
"hello actor"
);
receive
(
on
(
4
,
"hello actor"
)
>>
[]()
{
// done
},
others
()
>>
[]
{
cerr
<<
"unexpected: "
<<
to_string
(
self
->
last_dequeued
())
<<
endl
;
}
);
// kill joe and bob
auto
poison_pill
=
make_any_tuple
(
atom
(
"done"
));
joe
<<
poison_pill
;
bob
<<
poison_pill
;
await_all_others_done
();
std
::
function
<
actor_ptr
(
const
std
::
string
&
,
const
actor_ptr
&
)
>
spawn_next
;
auto
kr34t0r
=
factory
::
event_based
(
// it's safe to pass spawn_next as reference here, because
// - it is guaranteeed to outlive kr34t0r by general scoping rules
// - the lambda is always executed in the current actor's thread
// but using spawn_next in a message handler could
// still cause undefined behavior!
[
&
spawn_next
](
std
::
string
*
name
,
actor_ptr
*
pal
)
{
if
(
*
name
==
"Joe"
&&
!*
pal
)
{
*
pal
=
spawn_next
(
"Bob"
,
self
);
}
self
->
become
(
others
()
>>
[
pal
,
name
]()
{
cout
<<
"hello & bye from "
<<
*
name
<<
endl
;
// forward message and die
*
pal
<<
self
->
last_dequeued
();
self
->
quit
();
}
);
}
);
spawn_next
=
[
&
kr34t0r
](
const
std
::
string
&
name
,
const
actor_ptr
&
pal
)
{
return
kr34t0r
.
spawn
(
name
,
pal
);
};
auto
joe_the_second
=
kr34t0r
.
spawn
(
"Joe"
);
send
(
joe_the_second
,
atom
(
"done"
));
await_all_others_done
();
int
zombie_init_called
=
0
;
int
zombie_on_exit_called
=
0
;
factory
::
event_based
([
&
]()
{
...
...
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