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
bea4b168
Commit
bea4b168
authored
Jun 26, 2014
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make `ref_counted` compatible to boost-style ptrs
parent
d71bfc8c
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
76 additions
and
44 deletions
+76
-44
cppa/detail/make_counted.hpp
cppa/detail/make_counted.hpp
+48
-0
cppa/intrusive_ptr.hpp
cppa/intrusive_ptr.hpp
+0
-36
cppa/opencl/actor_facade.hpp
cppa/opencl/actor_facade.hpp
+3
-1
cppa/ref_counted.hpp
cppa/ref_counted.hpp
+10
-0
cppa/spawn.hpp
cppa/spawn.hpp
+1
-0
src/broker.cpp
src/broker.cpp
+3
-2
src/group_manager.cpp
src/group_manager.cpp
+4
-3
src/middleman.cpp
src/middleman.cpp
+2
-1
src/unicast_network.cpp
src/unicast_network.cpp
+2
-1
unit_testing/test_intrusive_ptr.cpp
unit_testing/test_intrusive_ptr.cpp
+3
-0
No files found.
cppa/detail/make_counted.hpp
0 → 100644
View file @
bea4b168
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the Boost Software License, Version 1.0. See *
* accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt *
\******************************************************************************/
#ifndef CPPA_DETAIL_MAKE_COUNTED_HPP
#define CPPA_DETAIL_MAKE_COUNTED_HPP
#include <type_traits>
#include "cppa/intrusive_ptr.hpp"
#include "cppa/ref_counted.hpp"
#include "cppa/detail/memory.hpp"
namespace
cppa
{
namespace
detail
{
template
<
typename
T
,
typename
...
Ts
>
typename
std
::
enable_if
<
is_memory_cached
<
T
>::
value
,
intrusive_ptr
<
T
>>::
type
make_counted
(
Ts
&&
...
args
)
{
return
{
memory
::
create
<
T
>
(
std
::
forward
<
Ts
>
(
args
)...)};
}
template
<
typename
T
,
typename
...
Ts
>
typename
std
::
enable_if
<!
is_memory_cached
<
T
>::
value
,
intrusive_ptr
<
T
>>::
type
make_counted
(
Ts
&&
...
args
)
{
return
{
new
T
(
std
::
forward
<
Ts
>
(
args
)...)};
}
}
// namespace detail
}
// namespace cppa
#endif // CPPA_DETAIL_MAKE_COUNTED_HPP
cppa/intrusive_ptr.hpp
View file @
bea4b168
...
@@ -25,18 +25,10 @@
...
@@ -25,18 +25,10 @@
#include <stdexcept>
#include <stdexcept>
#include <type_traits>
#include <type_traits>
#include "cppa/memory_cached.hpp"
#include "cppa/util/comparable.hpp"
#include "cppa/util/comparable.hpp"
namespace
cppa
{
namespace
cppa
{
template
<
class
From
,
class
To
>
struct
convertible
{
inline
To
convert
()
const
{
return
static_cast
<
const
From
*>
(
this
)
->
do_convert
();
}
};
/**
/**
* @brief An intrusive, reference counting smart pointer impelementation.
* @brief An intrusive, reference counting smart pointer impelementation.
* @relates ref_counted
* @relates ref_counted
...
@@ -68,12 +60,6 @@ class intrusive_ptr : util::comparable<intrusive_ptr<T> >,
...
@@ -68,12 +60,6 @@ class intrusive_ptr : util::comparable<intrusive_ptr<T> >,
"Y* is not assignable to T*"
);
"Y* is not assignable to T*"
);
}
}
// enables "actor_ptr s = self"
template
<
typename
From
>
intrusive_ptr
(
const
convertible
<
From
,
pointer
>&
from
)
{
set_ptr
(
from
.
convert
());
}
~
intrusive_ptr
()
{
if
(
m_ptr
)
m_ptr
->
deref
();
}
~
intrusive_ptr
()
{
if
(
m_ptr
)
m_ptr
->
deref
();
}
inline
void
swap
(
intrusive_ptr
&
other
)
{
inline
void
swap
(
intrusive_ptr
&
other
)
{
...
@@ -131,12 +117,6 @@ class intrusive_ptr : util::comparable<intrusive_ptr<T> >,
...
@@ -131,12 +117,6 @@ class intrusive_ptr : util::comparable<intrusive_ptr<T> >,
return
*
this
;
return
*
this
;
}
}
template
<
typename
From
>
intrusive_ptr
&
operator
=
(
const
convertible
<
From
,
T
*>&
from
)
{
reset
(
from
.
convert
());
return
*
this
;
}
inline
pointer
get
()
const
{
return
m_ptr
;
}
inline
pointer
get
()
const
{
return
m_ptr
;
}
inline
pointer
operator
->
()
const
{
return
m_ptr
;
}
inline
pointer
operator
->
()
const
{
return
m_ptr
;
}
inline
reference
operator
*
()
const
{
return
*
m_ptr
;
}
inline
reference
operator
*
()
const
{
return
*
m_ptr
;
}
...
@@ -193,22 +173,6 @@ inline bool operator!=(const intrusive_ptr<X>& lhs, const intrusive_ptr<Y>& rhs)
...
@@ -193,22 +173,6 @@ inline bool operator!=(const intrusive_ptr<X>& lhs, const intrusive_ptr<Y>& rhs)
return
!
(
lhs
==
rhs
);
return
!
(
lhs
==
rhs
);
}
}
/**
* @brief Constructs an object of type T which must be a derived type
* of {@link ref_counted} and wraps it in an {@link intrusive_ptr}.
*/
template
<
typename
T
,
typename
...
Ts
>
typename
std
::
enable_if
<
is_memory_cached
<
T
>::
value
,
intrusive_ptr
<
T
>>::
type
make_counted
(
Ts
&&
...
args
)
{
return
{
detail
::
memory
::
create
<
T
>
(
std
::
forward
<
Ts
>
(
args
)...)};
}
template
<
typename
T
,
typename
...
Ts
>
typename
std
::
enable_if
<
not
is_memory_cached
<
T
>::
value
,
intrusive_ptr
<
T
>>::
type
make_counted
(
Ts
&&
...
args
)
{
return
{
new
T
(
std
::
forward
<
Ts
>
(
args
)...)};
}
}
// namespace cppa
}
// namespace cppa
#endif // CPPA_INTRUSIVE_PTR_HPP
#endif // CPPA_INTRUSIVE_PTR_HPP
cppa/opencl/actor_facade.hpp
View file @
bea4b168
...
@@ -47,6 +47,8 @@
...
@@ -47,6 +47,8 @@
#include "cppa/util/type_list.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/limited_vector.hpp"
#include "cppa/util/limited_vector.hpp"
#include "cppa/detail/make_counted.hpp"
#include "cppa/opencl/global.hpp"
#include "cppa/opencl/global.hpp"
#include "cppa/opencl/command.hpp"
#include "cppa/opencl/command.hpp"
#include "cppa/opencl/program.hpp"
#include "cppa/opencl/program.hpp"
...
@@ -157,7 +159,7 @@ class actor_facade<Ret(Args...)> : public abstract_actor {
...
@@ -157,7 +159,7 @@ class actor_facade<Ret(Args...)> : public abstract_actor {
args_vec
arguments
;
args_vec
arguments
;
add_arguments_to_kernel
<
Ret
>
(
events
,
arguments
,
m_result_size
,
add_arguments_to_kernel
<
Ret
>
(
events
,
arguments
,
m_result_size
,
get_ref
<
Is
>
(
*
opt
)...);
get_ref
<
Is
>
(
*
opt
)...);
auto
cmd
=
make_counted
<
command
<
actor_facade
,
Ret
>>
(
auto
cmd
=
detail
::
make_counted
<
command
<
actor_facade
,
Ret
>>
(
handle
,
this
,
handle
,
this
,
std
::
move
(
events
),
std
::
move
(
arguments
),
std
::
move
(
events
),
std
::
move
(
arguments
),
m_result_size
,
*
opt
m_result_size
,
*
opt
...
...
cppa/ref_counted.hpp
View file @
bea4b168
...
@@ -66,6 +66,16 @@ class ref_counted : public memory_managed {
...
@@ -66,6 +66,16 @@ class ref_counted : public memory_managed {
};
};
// compatibility with the intrusive_ptr implementation of boost
inline
void
intrusive_ptr_add_ref
(
ref_counted
*
p
)
{
p
->
ref
();
}
// compatibility with the intrusive_ptr implementation of boost
inline
void
intrusive_ptr_release
(
ref_counted
*
p
)
{
p
->
deref
();
}
}
// namespace cppa
}
// namespace cppa
#endif // CPPA_REF_COUNTED_HPP
#endif // CPPA_REF_COUNTED_HPP
cppa/spawn.hpp
View file @
bea4b168
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
#include "cppa/detail/cs_thread.hpp"
#include "cppa/detail/cs_thread.hpp"
#include "cppa/util/type_traits.hpp"
#include "cppa/util/type_traits.hpp"
#include "cppa/detail/make_counted.hpp"
#include "cppa/detail/proper_actor.hpp"
#include "cppa/detail/proper_actor.hpp"
#include "cppa/detail/typed_actor_util.hpp"
#include "cppa/detail/typed_actor_util.hpp"
...
...
src/broker.cpp
View file @
bea4b168
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
#include "cppa/io/middleman.hpp"
#include "cppa/io/middleman.hpp"
#include "cppa/io/buffered_writing.hpp"
#include "cppa/io/buffered_writing.hpp"
#include "cppa/detail/make_counted.hpp"
#include "cppa/detail/actor_registry.hpp"
#include "cppa/detail/actor_registry.hpp"
#include "cppa/detail/sync_request_bouncer.hpp"
#include "cppa/detail/sync_request_bouncer.hpp"
...
@@ -446,7 +447,7 @@ broker_ptr init_and_launch(broker_ptr ptr) {
...
@@ -446,7 +447,7 @@ broker_ptr init_and_launch(broker_ptr ptr) {
}
}
broker_ptr
broker
::
from_impl
(
std
::
function
<
behavior
(
broker
*
)
>
fun
)
{
broker_ptr
broker
::
from_impl
(
std
::
function
<
behavior
(
broker
*
)
>
fun
)
{
return
make_counted
<
default_broker
>
(
fun
);
return
detail
::
make_counted
<
default_broker
>
(
fun
);
}
}
broker_ptr
broker
::
from_impl
(
std
::
function
<
void
(
broker
*
)
>
fun
)
{
broker_ptr
broker
::
from_impl
(
std
::
function
<
void
(
broker
*
)
>
fun
)
{
...
@@ -504,7 +505,7 @@ actor broker::fork_impl(std::function<behavior (broker*)> fun,
...
@@ -504,7 +505,7 @@ actor broker::fork_impl(std::function<behavior (broker*)> fun,
throw
std
::
invalid_argument
(
"invalid handle"
);
throw
std
::
invalid_argument
(
"invalid handle"
);
}
}
scribe
*
sptr
=
i
->
second
.
get
();
// keep non-owning pointer
scribe
*
sptr
=
i
->
second
.
get
();
// keep non-owning pointer
auto
result
=
make_counted
<
default_broker
>
(
fun
);
auto
result
=
detail
::
make_counted
<
default_broker
>
(
fun
);
result
->
m_io
.
insert
(
make_pair
(
sptr
->
id
(),
move
(
i
->
second
)));
result
->
m_io
.
insert
(
make_pair
(
sptr
->
id
(),
move
(
i
->
second
)));
init_and_launch
(
result
);
init_and_launch
(
result
);
sptr
->
set_broker
(
result
);
// set new broker
sptr
->
set_broker
(
result
);
// set new broker
...
...
src/group_manager.cpp
View file @
bea4b168
...
@@ -37,6 +37,7 @@
...
@@ -37,6 +37,7 @@
#include "cppa/detail/raw_access.hpp"
#include "cppa/detail/raw_access.hpp"
#include "cppa/detail/types_array.hpp"
#include "cppa/detail/types_array.hpp"
#include "cppa/detail/make_counted.hpp"
#include "cppa/detail/group_manager.hpp"
#include "cppa/detail/group_manager.hpp"
#include "cppa/util/shared_spinlock.hpp"
#include "cppa/util/shared_spinlock.hpp"
...
@@ -290,7 +291,7 @@ class local_group_module : public abstract_group::module {
...
@@ -290,7 +291,7 @@ class local_group_module : public abstract_group::module {
return
{
i
->
second
};
return
{
i
->
second
};
}
}
else
{
else
{
auto
tmp
=
make_counted
<
local_group
>
(
true
,
this
,
identifier
);
auto
tmp
=
detail
::
make_counted
<
local_group
>
(
true
,
this
,
identifier
);
{
// lifetime scope of uguard
{
// lifetime scope of uguard
upgrade_guard
uguard
(
guard
);
upgrade_guard
uguard
(
guard
);
auto
p
=
m_instances
.
insert
(
make_pair
(
identifier
,
tmp
));
auto
p
=
m_instances
.
insert
(
make_pair
(
identifier
,
tmp
));
...
@@ -450,7 +451,7 @@ class remote_group_module : public abstract_group::module {
...
@@ -450,7 +451,7 @@ class remote_group_module : public abstract_group::module {
public:
public:
remote_group_module
()
:
super
(
"remote"
)
{
remote_group_module
()
:
super
(
"remote"
)
{
auto
sm
=
make_counted
<
shared_map
>
();
auto
sm
=
detail
::
make_counted
<
shared_map
>
();
abstract_group
::
module_ptr
this_group
{
this
};
abstract_group
::
module_ptr
this_group
{
this
};
m_map
=
sm
;
m_map
=
sm
;
typedef
map
<
string
,
pair
<
actor
,
vector
<
pair
<
string
,
remote_group_ptr
>>>>
typedef
map
<
string
,
pair
<
actor
,
vector
<
pair
<
string
,
remote_group_ptr
>>>>
...
@@ -494,7 +495,7 @@ class remote_group_module : public abstract_group::module {
...
@@ -494,7 +495,7 @@ class remote_group_module : public abstract_group::module {
on
(
atom
(
"GROUP"
),
arg_match
)
>>
[
=
](
const
group
&
g
)
{
on
(
atom
(
"GROUP"
),
arg_match
)
>>
[
=
](
const
group
&
g
)
{
auto
gg
=
dynamic_cast
<
local_group
*>
(
detail
::
raw_access
::
get
(
g
));
auto
gg
=
dynamic_cast
<
local_group
*>
(
detail
::
raw_access
::
get
(
g
));
if
(
gg
)
{
if
(
gg
)
{
auto
rg
=
make_counted
<
remote_group
>
(
this_group
,
key
,
gg
);
auto
rg
=
detail
::
make_counted
<
remote_group
>
(
this_group
,
key
,
gg
);
sm
->
put
(
key
,
rg
);
sm
->
put
(
key
,
rg
);
(
*
peers
)[
authority
].
second
.
push_back
(
make_pair
(
key
,
rg
));
(
*
peers
)[
authority
].
second
.
push_back
(
make_pair
(
key
,
rg
));
}
}
...
...
src/middleman.cpp
View file @
bea4b168
...
@@ -54,6 +54,7 @@
...
@@ -54,6 +54,7 @@
#include "cppa/io/middleman_event_handler.hpp"
#include "cppa/io/middleman_event_handler.hpp"
#include "cppa/detail/fd_util.hpp"
#include "cppa/detail/fd_util.hpp"
#include "cppa/detail/make_counted.hpp"
#include "cppa/detail/actor_registry.hpp"
#include "cppa/detail/actor_registry.hpp"
#include "cppa/intrusive/single_reader_queue.hpp"
#include "cppa/intrusive/single_reader_queue.hpp"
...
@@ -288,7 +289,7 @@ class middleman_impl : public middleman {
...
@@ -288,7 +289,7 @@ class middleman_impl : public middleman {
m_node
=
compute_node_id
();
m_node
=
compute_node_id
();
m_handler
=
middleman_event_handler
::
create
();
m_handler
=
middleman_event_handler
::
create
();
m_namespace
.
set_proxy_factory
([
=
](
actor_id
aid
,
node_id_ptr
ptr
)
{
m_namespace
.
set_proxy_factory
([
=
](
actor_id
aid
,
node_id_ptr
ptr
)
{
return
make_counted
<
remote_actor_proxy
>
(
aid
,
std
::
move
(
ptr
),
this
);
return
detail
::
make_counted
<
remote_actor_proxy
>
(
aid
,
std
::
move
(
ptr
),
this
);
});
});
m_namespace
.
set_new_element_callback
([
=
](
actor_id
aid
,
m_namespace
.
set_new_element_callback
([
=
](
actor_id
aid
,
const
node_id
&
node
)
{
const
node_id
&
node
)
{
...
...
src/unicast_network.cpp
View file @
bea4b168
...
@@ -40,6 +40,7 @@
...
@@ -40,6 +40,7 @@
#include "cppa/binary_deserializer.hpp"
#include "cppa/binary_deserializer.hpp"
#include "cppa/detail/raw_access.hpp"
#include "cppa/detail/raw_access.hpp"
#include "cppa/detail/make_counted.hpp"
#include "cppa/intrusive/single_reader_queue.hpp"
#include "cppa/intrusive/single_reader_queue.hpp"
...
@@ -178,7 +179,7 @@ abstract_actor_ptr remote_actor_impl(stream_ptr_pair io, string_set expected) {
...
@@ -178,7 +179,7 @@ abstract_actor_ptr remote_actor_impl(stream_ptr_pair io, string_set expected) {
" but found a strongly typed actor of type "
" but found a strongly typed actor of type "
+
iface_str
);
+
iface_str
);
}
}
auto
pinfptr
=
make_counted
<
node_id
>
(
peer_pid
,
peer_node_id
);
auto
pinfptr
=
detail
::
make_counted
<
node_id
>
(
peer_pid
,
peer_node_id
);
if
(
*
pinf
==
*
pinfptr
)
{
if
(
*
pinf
==
*
pinfptr
)
{
// this is a local actor, not a remote actor
// this is a local actor, not a remote actor
CPPA_LOGF_INFO
(
"remote_actor() called to access a local actor"
);
CPPA_LOGF_INFO
(
"remote_actor() called to access a local actor"
);
...
...
unit_testing/test_intrusive_ptr.cpp
View file @
bea4b168
...
@@ -4,9 +4,12 @@
...
@@ -4,9 +4,12 @@
#include "test.hpp"
#include "test.hpp"
#include "cppa/ref_counted.hpp"
#include "cppa/ref_counted.hpp"
#include "cppa/intrusive_ptr.hpp"
#include "cppa/intrusive_ptr.hpp"
#include "cppa/detail/make_counted.hpp"
using
namespace
cppa
;
using
namespace
cppa
;
using
detail
::
make_counted
;
namespace
{
namespace
{
int
class0_instances
=
0
;
int
class0_instances
=
0
;
...
...
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