Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
UERANSIM
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
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
Libraries
UERANSIM
Commits
feaeffb8
Commit
feaeffb8
authored
May 17, 2021
by
aligungr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
L3 RRC/NAS developments
parent
027d89d6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
2 deletions
+91
-2
src/lib/nas/storage.hpp
src/lib/nas/storage.hpp
+91
-2
No files found.
src/lib/nas/storage.hpp
View file @
feaeffb8
...
...
@@ -9,6 +9,7 @@
#include <array>
#include <functional>
#include <optional>
#include <type_traits>
#include <vector>
#include <utils/common.hpp>
...
...
@@ -16,6 +17,8 @@
namespace
nas
{
// TODO: Periodun sonuna geldiğinde erişilmezse, (autoClearIfNecessary çağrılmazsa) delete yapılmaz backup çalışmaz
/*
* - Items are unique, if already exists, deletes the previous one
* - List have fixed size, if capacity is full, oldest item is deleted
...
...
@@ -142,6 +145,9 @@ class NasList
private:
void
autoClearIfNecessary
()
{
if
(
m_autoClearingPeriod
<=
0
)
return
;
int64_t
currentTime
=
::
utils
::
CurrentTimeMillis
();
if
(
currentTime
-
m_lastAutoCleared
>=
m_autoClearingPeriod
)
{
...
...
@@ -158,11 +164,11 @@ class NasList
void
removeAt
(
size_t
index
)
{
touch
();
for
(
size_t
i
=
index
;
i
<
m_size
;
++
i
)
m_data
[
i
]
=
i
+
1
<
m_sizeLimit
?
m_data
[
i
+
1
]
:
T
{};
m_size
--
;
touch
();
}
void
touch
()
...
...
@@ -172,4 +178,87 @@ class NasList
}
};
template
<
typename
T
>
class
NasSlot
{
public:
using
backup_functor_type
=
std
::
function
<
void
(
const
T
&
value
)
>
;
private:
const
int64_t
m_autoClearingPeriod
;
const
std
::
optional
<
backup_functor_type
>
m_backupFunctor
;
T
m_value
;
int64_t
m_lastAutoCleared
;
static_assert
(
!
std
::
is_reference
<
T
>::
value
);
public:
NasSlot
(
int64_t
autoClearingPeriod
,
std
::
optional
<
backup_functor_type
>
backupFunctor
)
:
m_autoClearingPeriod
{
autoClearingPeriod
},
m_backupFunctor
{
backupFunctor
},
m_value
{},
m_lastAutoCleared
{
::
utils
::
CurrentTimeMillis
()}
{
}
T
get
()
{
autoClearIfNecessary
();
return
m_value
;
}
void
set
(
const
T
&
value
)
{
autoClearIfNecessary
();
m_value
=
value
;
touch
();
}
void
set
(
T
&&
value
)
{
autoClearIfNecessary
();
m_value
=
std
::
move
(
value
);
touch
();
}
template
<
typename
Functor
>
void
access
(
Functor
fun
)
{
autoClearIfNecessary
();
fun
((
const
T
&
)
m_value
);
}
template
<
typename
Functor
>
void
mutate
(
Functor
fun
)
{
autoClearIfNecessary
();
fun
((
T
&
)
m_value
);
touch
();
}
private:
void
autoClearIfNecessary
()
{
if
(
m_autoClearingPeriod
<=
0
)
return
;
int64_t
currentTime
=
::
utils
::
CurrentTimeMillis
();
if
(
currentTime
-
m_lastAutoCleared
>=
m_autoClearingPeriod
)
{
m_lastAutoCleared
=
currentTime
;
m_value
=
{};
}
}
void
touch
()
{
if
(
m_backupFunctor
)
(
*
m_backupFunctor
)(
m_value
);
}
};
}
// namespace nas
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