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
bdcee9fa
Commit
bdcee9fa
authored
Aug 21, 2011
by
Ilya Leoshkevich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
actor_count singleton
parent
0c5df318
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
31 deletions
+58
-31
cppa/detail/actor_count.hpp
cppa/detail/actor_count.hpp
+25
-4
src/actor_count.cpp
src/actor_count.cpp
+24
-18
src/mock_scheduler.cpp
src/mock_scheduler.cpp
+2
-2
src/scheduler.cpp
src/scheduler.cpp
+3
-3
src/task_scheduler.cpp
src/task_scheduler.cpp
+2
-2
src/thread_pool_scheduler.cpp
src/thread_pool_scheduler.cpp
+2
-2
No files found.
cppa/detail/actor_count.hpp
View file @
bdcee9fa
#ifndef ACTOR_COUNT_HPP
#define ACTOR_COUNT_HPP
#include <atomic>
#include <boost/thread.hpp>
#include "cppa/attachable.hpp"
namespace
cppa
{
namespace
detail
{
void
inc_actor_count
();
void
dec_actor_count
();
class
actor_count
{
public:
actor_count
();
void
inc
();
void
dec
();
// @pre expected <= 1
void
actor_count_wait_until
(
size_t
expected
);
// @pre expected <= 1
void
wait_until
(
size_t
expected
);
static
actor_count
&
get
();
private:
static
actor_count
*
s_instance
;
boost
::
mutex
m_ra_mtx
;
boost
::
condition_variable
m_ra_cv
;
std
::
atomic
<
size_t
>
m_running_actors
;
};
struct
exit_observer
:
cppa
::
attachable
{
...
...
src/actor_count.cpp
View file @
bdcee9fa
#include <limits>
#include <atomic>
#include <stdexcept>
#include <boost/thread.hpp>
#include "cppa/detail/actor_count.hpp"
namespace
{
boost
::
mutex
s_ra_mtx
;
boost
::
condition_variable
s_ra_cv
;
std
::
atomic
<
size_t
>
s_running_actors
(
0
);
typedef
boost
::
unique_lock
<
boost
::
mutex
>
guard_type
;
}
// namespace <anonymous>
namespace
cppa
{
namespace
detail
{
void
inc_actor_count
()
// TODO: free
actor_count
*
actor_count
::
s_instance
=
new
actor_count
();
actor_count
&
actor_count
::
get
()
{
return
*
s_instance
;
}
actor_count
::
actor_count
()
:
m_running_actors
(
0
)
{
}
void
actor_count
::
inc
()
{
++
s
_running_actors
;
++
m
_running_actors
;
}
void
dec_actor_count
()
void
actor_count
::
dec
()
{
size_t
new_val
=
--
s
_running_actors
;
size_t
new_val
=
--
m
_running_actors
;
if
(
new_val
==
std
::
numeric_limits
<
size_t
>::
max
())
{
throw
std
::
underflow_error
(
"
dec_actor_count
()"
);
throw
std
::
underflow_error
(
"
actor_count::dec
()"
);
}
else
if
(
new_val
<=
1
)
{
guard_type
guard
(
s
_ra_mtx
);
s
_ra_cv
.
notify_all
();
guard_type
guard
(
m
_ra_mtx
);
m
_ra_cv
.
notify_all
();
}
}
void
actor_count
_
wait_until
(
size_t
expected
)
void
actor_count
::
wait_until
(
size_t
expected
)
{
guard_type
lock
(
s
_ra_mtx
);
while
(
s
_running_actors
.
load
()
!=
expected
)
guard_type
lock
(
m
_ra_mtx
);
while
(
m
_running_actors
.
load
()
!=
expected
)
{
s
_ra_cv
.
wait
(
lock
);
m
_ra_cv
.
wait
(
lock
);
}
}
exit_observer
::~
exit_observer
()
{
cppa
::
detail
::
dec_actor_count
();
actor_count
::
get
().
dec
();
}
}
}
// namespace cppa::detail
src/mock_scheduler.cpp
View file @
bdcee9fa
...
...
@@ -34,7 +34,7 @@ void run_actor(cppa::intrusive_ptr<cppa::context> m_self,
catch
(...)
{
}
delete
behavior
;
}
cppa
::
detail
::
dec_actor_count
();
cppa
::
detail
::
actor_count
::
get
().
dec
();
}
}
// namespace <anonymous>
...
...
@@ -43,7 +43,7 @@ namespace cppa { namespace detail {
actor_ptr
mock_scheduler
::
spawn
(
actor_behavior
*
behavior
)
{
inc_actor_count
();
actor_count
::
get
().
inc
();
CPPA_MEMORY_BARRIER
();
intrusive_ptr
<
context
>
ctx
(
new
detail
::
converted_thread_context
);
boost
::
thread
(
run_actor
,
ctx
,
behavior
).
detach
();
...
...
src/scheduler.cpp
View file @
bdcee9fa
...
...
@@ -43,21 +43,21 @@ scheduler::~scheduler()
void
scheduler
::
await_others_done
()
{
detail
::
actor_count
_
wait_until
((
unchecked_self
()
==
nullptr
)
?
0
:
1
);
detail
::
actor_count
::
get
().
wait_until
((
unchecked_self
()
==
nullptr
)
?
0
:
1
);
}
void
scheduler
::
register_converted_context
(
context
*
what
)
{
if
(
what
)
{
detail
::
inc_actor_count
();
detail
::
actor_count
::
get
().
inc
();
what
->
attach
(
new
detail
::
exit_observer
);
}
}
attachable
*
scheduler
::
register_hidden_context
()
{
detail
::
inc_actor_count
();
detail
::
actor_count
::
get
().
inc
();
return
new
detail
::
exit_observer
;
}
...
...
src/task_scheduler.cpp
View file @
bdcee9fa
...
...
@@ -40,7 +40,7 @@ void task_scheduler::worker_loop(job_queue* jq, scheduled_actor* dummy)
{
if
(
!
job
->
deref
())
delete
job
;
CPPA_MEMORY_BARRIER
();
dec_actor_count
();
actor_count
::
get
().
dec
();
});
}
}
...
...
@@ -75,7 +75,7 @@ void task_scheduler::schedule(scheduled_actor* what)
actor_ptr
task_scheduler
::
spawn
(
actor_behavior
*
behavior
,
scheduling_hint
)
{
inc_actor_count
();
actor_count
::
get
().
inc
();
intrusive_ptr
<
scheduled_actor
>
ctx
(
new
scheduled_actor
(
behavior
,
enqueue_fun
,
this
));
...
...
src/thread_pool_scheduler.cpp
View file @
bdcee9fa
...
...
@@ -78,7 +78,7 @@ struct thread_pool_scheduler::worker
{
if
(
!
m_job
->
deref
())
delete
m_job
;
CPPA_MEMORY_BARRIER
();
dec_actor_count
();
actor_count
::
get
().
dec
();
});
if
(
reschedule
)
{
...
...
@@ -184,7 +184,7 @@ actor_ptr thread_pool_scheduler::spawn(actor_behavior* behavior,
}
else
{
inc_actor_count
();
actor_count
::
get
().
inc
();
CPPA_MEMORY_BARRIER
();
intrusive_ptr
<
scheduled_actor
>
ctx
(
new
scheduled_actor
(
behavior
,
enqueue_fun
,
...
...
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