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
590fe019
Commit
590fe019
authored
Jun 06, 2016
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move global detached_threads to actor registry
parent
98faf8b9
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
38 additions
and
107 deletions
+38
-107
libcaf_core/CMakeLists.txt
libcaf_core/CMakeLists.txt
+0
-1
libcaf_core/caf/actor_registry.hpp
libcaf_core/caf/actor_registry.hpp
+13
-1
libcaf_core/caf/scheduler.hpp
libcaf_core/caf/scheduler.hpp
+0
-1
libcaf_core/caf/scheduler/detached_threads.hpp
libcaf_core/caf/scheduler/detached_threads.hpp
+0
-41
libcaf_core/src/actor_registry.cpp
libcaf_core/src/actor_registry.cpp
+18
-2
libcaf_core/src/detached_threads.cpp
libcaf_core/src/detached_threads.cpp
+0
-58
libcaf_core/src/local_actor.cpp
libcaf_core/src/local_actor.cpp
+7
-3
No files found.
libcaf_core/CMakeLists.txt
View file @
590fe019
...
...
@@ -41,7 +41,6 @@ set (LIBCAF_CORE_SRCS
src/deep_to_string.cpp
src/default_attachable.cpp
src/deserializer.cpp
src/detached_threads.cpp
src/duration.cpp
src/dynamic_message_data.cpp
src/error.cpp
...
...
libcaf_core/caf/actor_registry.hpp
View file @
590fe019
...
...
@@ -72,6 +72,15 @@ public:
/// (must be either 0 or 1).
void
await_running_count_equal
(
size_t
expected
)
const
;
/// Increases running-detached-threads-count by one.
void
inc_detached_threads
();
/// Decreases running-detached-threads-count by one.
void
dec_detached_threads
();
/// Blocks the caller until all detached threads are done.
void
await_detached_threads
();
/// Returns the actor associated with `key` or `invalid_actor`.
strong_actor_ptr
get
(
atom_value
key
)
const
;
...
...
@@ -97,7 +106,6 @@ private:
actor_registry
(
actor_system
&
sys
);
std
::
atomic
<
size_t
>
running_
;
mutable
std
::
mutex
running_mtx_
;
mutable
std
::
condition_variable
running_cv_
;
...
...
@@ -107,6 +115,10 @@ private:
name_map
named_entries_
;
mutable
detail
::
shared_spinlock
named_entries_mtx_
;
std
::
atomic
<
size_t
>
detached
;
mutable
std
::
mutex
detached_mtx
;
mutable
std
::
condition_variable
detached_cv
;
actor_system
&
system_
;
};
...
...
libcaf_core/caf/scheduler.hpp
View file @
590fe019
...
...
@@ -22,7 +22,6 @@
#include "caf/scheduler/worker.hpp"
#include "caf/scheduler/coordinator.hpp"
#include "caf/scheduler/detached_threads.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
#endif // CAF_SCHEDULER_HPP
libcaf_core/caf/scheduler/detached_threads.hpp
deleted
100644 → 0
View file @
98faf8b9
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_SCHEDULER_DETACHED_THREADS_HPP
#define CAF_SCHEDULER_DETACHED_THREADS_HPP
#include <cstddef>
namespace
caf
{
namespace
scheduler
{
/// Increases count for detached threads by one.
void
inc_detached_threads
();
/// Decreases count for detached threads by one.
void
dec_detached_threads
();
/// Blocks the caller until all detached threads are done.
void
await_detached_threads
();
}
// namespace scheduler
}
// namespace caf
#endif // CAF_SCHEDULER_DETACHED_THREADS_HPP
libcaf_core/src/actor_registry.cpp
View file @
590fe019
...
...
@@ -38,8 +38,6 @@
#include "caf/event_based_actor.hpp"
#include "caf/uniform_type_info_map.hpp"
#include "caf/scheduler/detached_threads.hpp"
#include "caf/detail/shared_spinlock.hpp"
namespace
caf
{
...
...
@@ -122,6 +120,24 @@ void actor_registry::await_running_count_equal(size_t expected) const {
}
}
void
actor_registry
::
inc_detached_threads
()
{
++
detached
;
}
void
actor_registry
::
dec_detached_threads
()
{
if
(
--
detached
==
0
)
{
std
::
unique_lock
<
std
::
mutex
>
guard
{
detached_mtx
};
detached_cv
.
notify_all
();
}
}
void
actor_registry
::
await_detached_threads
()
{
std
::
unique_lock
<
std
::
mutex
>
guard
{
detached_mtx
};
while
(
detached
!=
0
)
{
detached_cv
.
wait
(
guard
);
}
}
strong_actor_ptr
actor_registry
::
get
(
atom_value
key
)
const
{
shared_guard
guard
{
named_entries_mtx_
};
auto
i
=
named_entries_
.
find
(
key
);
...
...
libcaf_core/src/detached_threads.cpp
deleted
100644 → 0
View file @
98faf8b9
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/scheduler/detached_threads.hpp"
#include <mutex>
#include <atomic>
#include <condition_variable>
namespace
caf
{
namespace
scheduler
{
namespace
{
std
::
atomic
<
size_t
>
s_detached
;
std
::
mutex
s_detached_mtx
;
std
::
condition_variable
s_detached_cv
;
}
// namespace <anonymous>
void
inc_detached_threads
()
{
++
s_detached
;
}
void
dec_detached_threads
()
{
size_t
new_val
=
--
s_detached
;
if
(
new_val
==
0
)
{
std
::
unique_lock
<
std
::
mutex
>
guard
(
s_detached_mtx
);
s_detached_cv
.
notify_all
();
}
}
void
await_detached_threads
()
{
std
::
unique_lock
<
std
::
mutex
>
guard
{
s_detached_mtx
};
while
(
s_detached
!=
0
)
{
s_detached_cv
.
wait
(
guard
);
}
}
}
// namespace scheduler
}
// namespace caf
libcaf_core/src/local_actor.cpp
View file @
590fe019
...
...
@@ -51,9 +51,10 @@ public:
private_thread
(
local_actor
*
self
)
:
self_destroyed_
(
false
),
self_
(
self
),
state_
(
active
)
{
state_
(
active
),
registry
(
self
->
system
().
registry
())
{
intrusive_ptr_add_ref
(
self
->
ctrl
());
scheduler
::
inc_detached_threads
();
registry
.
inc_detached_threads
();
}
void
run
()
{
...
...
@@ -109,10 +110,12 @@ public:
static
void
exec
(
private_thread
*
this_ptr
)
{
this_ptr
->
run
();
scheduler
::
dec_detached_threads
();
// make sure to not destroy the private thread object before the
// detached actor is destroyed and this object is unreachable
this_ptr
->
await_self_destroyed
();
// signalize destruction of detached thread to registry
this_ptr
->
registry
.
dec_detached_threads
();
// done
delete
this_ptr
;
}
...
...
@@ -138,6 +141,7 @@ private:
volatile
bool
self_destroyed_
;
volatile
local_actor
*
self_
;
volatile
worker_state
state_
;
actor_registry
&
registry
;
};
result
<
message
>
reflect
(
local_actor
*
,
const
type_erased_tuple
*
x
)
{
...
...
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