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
7ad237ca
Commit
7ad237ca
authored
May 22, 2021
by
aligungr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
L3 RRC/NAS developments
parent
dc57e410
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
0 deletions
+73
-0
src/utils/light_sync.cpp
src/utils/light_sync.cpp
+9
-0
src/utils/light_sync.hpp
src/utils/light_sync.hpp
+64
-0
No files found.
src/utils/light_sync.cpp
0 → 100644
View file @
7ad237ca
//
// This file is a part of UERANSIM open source project.
// Copyright (c) 2021 ALİ GÜNGÖR.
//
// The software and all associated files are licensed under GPL-3.0
// and subject to the terms and conditions defined in LICENSE file.
//
#include "light_sync.hpp"
src/utils/light_sync.hpp
0 → 100644
View file @
7ad237ca
//
// This file is a part of UERANSIM open source project.
// Copyright (c) 2021 ALİ GÜNGÖR.
//
// The software and all associated files are licensed under GPL-3.0
// and subject to the terms and conditions defined in LICENSE file.
//
#include "common.hpp"
#include <atomic>
#include <memory>
#include <stdexcept>
template
<
typename
TInput
,
typename
TOutput
>
class
LightSync
{
const
int
m_validForMs
;
const
int64_t
m_validUntil
;
const
std
::
unique_ptr
<
TInput
>
m_input
;
std
::
atomic_bool
m_processed
;
std
::
shared_ptr
<
TOutput
>
m_output
;
public:
LightSync
(
int
validForMs
,
std
::
unique_ptr
<
TInput
>
&&
input
)
:
m_validForMs
{
validForMs
},
m_validUntil
{
utils
::
CurrentTimeMillis
()
+
static_cast
<
int64_t
>
(
validForMs
)},
m_input
{
std
::
move
(
input
)},
m_processed
{},
m_output
{}
{
if
(
validForMs
>=
2000
)
throw
std
::
runtime_error
(
"LightSync timeout is too large"
);
}
const
TInput
&
getInput
()
{
return
*
m_input
;
}
bool
isValid
()
{
return
utils
::
CurrentTimeMillis
()
<=
m_validUntil
;
}
// Only producer can call at most once
void
notifyProcessed
(
std
::
unique_ptr
<
TOutput
>
&&
output
)
{
if
(
m_processed
)
throw
std
::
runtime_error
(
"LightSync processed more than once"
);
m_output
=
std
::
move
(
output
);
m_processed
=
true
;
}
// Only consumer can call at most once
std
::
shared_ptr
<
TOutput
>
waitForProcess
()
{
while
(
true
)
{
if
(
!
isValid
())
return
nullptr
;
if
(
m_processed
)
return
m_output
;
}
}
};
\ No newline at end of file
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