Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
cython-plus
typon
Commits
4954832c
Commit
4954832c
authored
Jun 06, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate ring logic from ring_buffer into binary_ring
parent
8020c3af
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
6 deletions
+44
-6
rt/include/typon/fundamental/binary_ring.hpp
rt/include/typon/fundamental/binary_ring.hpp
+36
-0
rt/include/typon/fundamental/ring_buffer.hpp
rt/include/typon/fundamental/ring_buffer.hpp
+8
-6
No files found.
rt/include/typon/fundamental/binary_ring.hpp
0 → 100644
View file @
4954832c
#ifndef TYPON_FUNDAMENTAL_BINARY_RING_HPP_INCLUDED
#define TYPON_FUNDAMENTAL_BINARY_RING_HPP_INCLUDED
#include <atomic>
#include <cstdint>
#include <type_traits>
namespace
typon
::
fdt
{
template
<
typename
I
>
requires
std
::
is_unsigned_v
<
I
>
struct
binary_ring
{
const
I
_mask
;
binary_ring
(
std
::
uint_least8_t
bits
)
noexcept
:
_mask
((
I
(
1
)
<<
bits
)
-
1
)
{}
I
size
()
noexcept
{
return
_mask
+
1
;
}
friend
I
operator
%
(
I
x
,
binary_ring
ring
)
noexcept
{
return
x
&
ring
.
_mask
;
}
};
}
#endif // TYPON_FUNDAMENTAL_BINARY_RING_HPP_INCLUDED
rt/include/typon/fundamental/ring_buffer.hpp
View file @
4954832c
...
...
@@ -6,6 +6,8 @@
#include <cstdint>
#include <type_traits>
#include <typon/fundamental/binary_ring.hpp>
namespace
typon
::
fdt
::
lock_free
{
...
...
@@ -19,12 +21,12 @@ namespace typon::fdt::lock_free
using
enum
std
::
memory_order
;
const
u64
_mask
;
binary_ring
<
u64
>
_ring
;
ring_buffer
*
_next
;
std
::
atomic
<
T
>
*
const
_array
;
ring_buffer
(
u8
bits
,
ring_buffer
*
next
=
nullptr
)
noexcept
:
_
mask
((
u64
(
1
)
<<
bits
)
-
1
)
:
_
ring
(
bits
)
,
_next
(
next
)
,
_array
(
new
std
::
atomic
<
T
>
[
this
->
capacity
()])
{}
...
...
@@ -40,17 +42,17 @@ namespace typon::fdt::lock_free
u64
capacity
()
noexcept
{
return
_
mask
+
1
;
return
_
ring
.
size
()
;
}
void
put
(
u64
index
,
T
object
)
noexcept
{
_array
[
index
&
_mask
].
store
(
std
::
move
(
object
),
relaxed
);
_array
[
index
%
_ring
].
store
(
std
::
move
(
object
),
relaxed
);
}
T
get
(
u64
index
)
noexcept
{
return
_array
[
index
&
_mask
].
load
(
relaxed
);
return
_array
[
index
%
_ring
].
load
(
relaxed
);
}
ring_buffer
*
fill
(
ring_buffer
*
sink
,
u64
start
,
u64
end
)
noexcept
...
...
@@ -64,7 +66,7 @@ namespace typon::fdt::lock_free
ring_buffer
*
grow
(
u64
start
,
u64
end
)
noexcept
{
auto
buffer
=
new
ring_buffer
(
std
::
countr_
one
(
_mask
)
+
1
,
this
);
auto
buffer
=
new
ring_buffer
(
std
::
countr_
zero
(
_ring
.
size
()
)
+
1
,
this
);
return
fill
(
buffer
,
start
,
end
);
}
...
...
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