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
37a59d02
Commit
37a59d02
authored
May 29, 2017
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove dead code
parent
3799bc11
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
314 deletions
+0
-314
libcaf_core/CMakeLists.txt
libcaf_core/CMakeLists.txt
+0
-1
libcaf_core/caf/detail/memory.hpp
libcaf_core/caf/detail/memory.hpp
+0
-194
libcaf_core/src/memory.cpp
libcaf_core/src/memory.cpp
+0
-119
No files found.
libcaf_core/CMakeLists.txt
View file @
37a59d02
...
...
@@ -65,7 +65,6 @@ set (LIBCAF_CORE_SRCS
src/logger.cpp
src/mailbox_element.cpp
src/match_case.cpp
src/memory.cpp
src/memory_managed.cpp
src/merged_tuple.cpp
src/message.cpp
...
...
libcaf_core/caf/detail/memory.hpp
deleted
100644 → 0
View file @
3799bc11
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2017 *
* 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_DETAIL_MEMORY_HPP
#define CAF_DETAIL_MEMORY_HPP
#include <new>
#include <vector>
#include <memory>
#include <utility>
#include <typeinfo>
#include "caf/config.hpp"
#include "caf/ref_counted.hpp"
#include "caf/detail/embedded.hpp"
namespace
caf
{
class
mailbox_element
;
}
// namespace caf
namespace
caf
{
namespace
detail
{
namespace
{
constexpr
size_t
s_alloc_size
=
1024
*
1024
;
// allocate ~1mb chunks
constexpr
size_t
s_cache_size
=
10
*
1024
*
1024
;
// cache about 10mb per thread
constexpr
size_t
s_min_elements
=
5
;
// don't create < 5 elements
constexpr
size_t
s_max_elements
=
20
;
// don't create > 20 elements
}
// namespace <anonymous>
using
embedded_storage
=
std
::
pair
<
intrusive_ptr
<
ref_counted
>
,
void
*>
;
class
memory_cache
{
public:
virtual
~
memory_cache
();
virtual
embedded_storage
new_embedded_storage
()
=
0
;
};
template
<
class
T
>
class
basic_memory_cache
;
#ifdef CAF_NO_MEM_MANAGEMENT
class
memory
{
public:
memory
()
=
delete
;
// Allocates storage, initializes a new object, and returns the new instance.
template
<
class
T
,
class
...
Ts
>
static
T
*
create
(
Ts
&&
...
xs
)
{
return
new
T
(
std
::
forward
<
Ts
>
(
xs
)...);
}
static
inline
memory_cache
*
get_cache_map_entry
(
const
std
::
type_info
*
)
{
return
nullptr
;
}
};
#else // CAF_NO_MEM_MANAGEMENT
template
<
class
T
>
class
basic_memory_cache
:
public
memory_cache
{
public:
static
constexpr
size_t
ne
=
s_alloc_size
/
sizeof
(
T
);
static
constexpr
size_t
ms
=
ne
<
s_min_elements
?
s_min_elements
:
ne
;
static
constexpr
size_t
dsize
=
ms
>
s_max_elements
?
s_max_elements
:
ms
;
static_assert
(
dsize
>
0
,
"dsize == 0"
);
using
embedded_t
=
embedded
<
T
>
;
struct
wrapper
{
union
{
embedded_t
instance
;
};
wrapper
()
{
// nop
}
~
wrapper
()
{
// nop
}
};
class
storage
:
public
ref_counted
{
public:
storage
()
:
pos_
(
0
)
{
// nop
}
~
storage
()
override
{
// nop
}
bool
has_next
()
{
return
pos_
<
dsize
;
}
embedded_t
*
next
()
{
return
&
(
data_
[
pos_
++
].
instance
);
}
private:
size_t
pos_
;
wrapper
data_
[
dsize
];
};
embedded_storage
new_embedded_storage
()
override
{
// allocate cache on-the-fly
if
(
!
cache_
)
{
cache_
.
reset
(
new
storage
,
false
);
// starts with ref count of 1
CAF_ASSERT
(
cache_
->
unique
());
}
auto
res
=
cache_
->
next
();
if
(
cache_
->
has_next
())
{
return
{
cache_
,
res
};
}
// we got the last element out of the cache; pass the reference to the
// client to avoid pointless increase/decrease ops on the reference count
embedded_storage
result
;
result
.
first
.
reset
(
cache_
.
detach
(),
false
);
result
.
second
=
res
;
return
result
;
}
private:
intrusive_ptr
<
storage
>
cache_
;
};
class
memory
{
memory
()
=
delete
;
template
<
class
>
friend
class
basic_memory_cache
;
public:
// Allocates storage, initializes a new object, and returns the new instance.
template
<
class
T
,
class
...
Ts
>
static
T
*
create
(
Ts
&&
...
xs
)
{
using
embedded_t
=
embedded
<
T
>
;
auto
mc
=
get_or_set_cache_map_entry
<
T
>
();
auto
es
=
mc
->
new_embedded_storage
();
auto
ptr
=
reinterpret_cast
<
embedded_t
*>
(
es
.
second
);
new
(
ptr
)
embedded_t
(
std
::
move
(
es
.
first
),
std
::
forward
<
Ts
>
(
xs
)...);
return
ptr
;
}
static
memory_cache
*
get_cache_map_entry
(
const
std
::
type_info
*
tinf
);
private:
static
void
add_cache_map_entry
(
const
std
::
type_info
*
tinf
,
memory_cache
*
instance
);
template
<
class
T
>
static
inline
memory_cache
*
get_or_set_cache_map_entry
()
{
auto
mc
=
get_cache_map_entry
(
&
typeid
(
T
));
if
(
!
mc
)
{
mc
=
new
basic_memory_cache
<
T
>
;
add_cache_map_entry
(
&
typeid
(
T
),
mc
);
}
return
mc
;
}
};
#endif // CAF_NO_MEM_MANAGEMENT
}
// namespace detail
}
// namespace caf
#endif // CAF_DETAIL_MEMORY_HPP
libcaf_core/src/memory.cpp
deleted
100644 → 0
View file @
3799bc11
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2017 *
* 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/config.hpp"
#include "caf/detail/memory.hpp"
#include <vector>
#include <typeinfo>
#include "caf/mailbox_element.hpp"
#ifdef CAF_NO_MEM_MANAGEMENT
int
caf_memory_keep_compiler_happy
()
{
// this function shuts up a linker warning saying that the
// object file has no symbols
return
0
;
}
#else // CAF_NO_MEM_MANAGEMENT
namespace
caf
{
namespace
detail
{
namespace
{
using
cache_map
=
std
::
map
<
const
std
::
type_info
*
,
std
::
unique_ptr
<
memory_cache
>>
;
}
// namespace <anonymous>
#if defined(CAF_NO_THREAD_LOCAL)
namespace
{
pthread_key_t
s_key
;
pthread_once_t
s_key_once
=
PTHREAD_ONCE_INIT
;
}
// namespace <anonymous>
void
cache_map_destructor
(
void
*
ptr
)
{
delete
reinterpret_cast
<
cache_map
*>
(
ptr
);
}
void
make_cache_map
()
{
pthread_key_create
(
&
s_key
,
cache_map_destructor
);
}
cache_map
&
get_cache_map
()
{
pthread_once
(
&
s_key_once
,
make_cache_map
);
auto
cache
=
reinterpret_cast
<
cache_map
*>
(
pthread_getspecific
(
s_key
));
if
(
cache
==
nullptr
)
{
cache
=
new
cache_map
;
pthread_setspecific
(
s_key
,
cache
);
// insert default types
//std::unique_ptr<memory_cache> tmp(new basic_memory_cache<mailbox_element>);
//cache->emplace(&typeid(mailbox_element), std::move(tmp));
}
return
*
cache
;
}
#else // !CAF_NO_THREAD_LOCAL
namespace
{
thread_local
std
::
unique_ptr
<
cache_map
>
s_key
;
}
// namespace <anonymous>
cache_map
&
get_cache_map
()
{
if
(
!
s_key
)
{
s_key
=
std
::
unique_ptr
<
cache_map
>
(
new
cache_map
);
// insert default types
std
::
unique_ptr
<
memory_cache
>
tmp
(
new
basic_memory_cache
<
mailbox_element
>
);
s_key
->
emplace
(
&
typeid
(
mailbox_element
),
std
::
move
(
tmp
));
}
return
*
s_key
;
}
#endif // !CAF_NO_THREAD_LOCAL
memory_cache
::~
memory_cache
()
{
// nop
}
memory_cache
*
memory
::
get_cache_map_entry
(
const
std
::
type_info
*
tinf
)
{
auto
&
cache
=
get_cache_map
();
auto
i
=
cache
.
find
(
tinf
);
if
(
i
!=
cache
.
end
())
{
return
i
->
second
.
get
();
}
return
nullptr
;
}
void
memory
::
add_cache_map_entry
(
const
std
::
type_info
*
tinf
,
memory_cache
*
instance
)
{
auto
&
cache
=
get_cache_map
();
cache
[
tinf
].
reset
(
instance
);
}
}
// namespace detail
}
// namespace caf
#endif // CAF_NO_MEM_MANAGEMENT
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