Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ycai
simbricks
Commits
48dc6a89
Commit
48dc6a89
authored
Jun 18, 2022
by
Antoine Kaufmann
Browse files
lib/simbricks/base: add handling for incoming terminate messages
Includes setting a terminated flag and a call to detect this.
parent
96273b5f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
14 deletions
+37
-14
lib/simbricks/base/if.h
lib/simbricks/base/if.h
+37
-14
No files found.
lib/simbricks/base/if.h
View file @
48dc6a89
...
...
@@ -96,6 +96,8 @@ struct SimbricksBaseIf {
size_t
out_enum
;
uint64_t
out_timestamp
;
bool
in_terminated
;
int
conn_state
;
int
sync
;
struct
SimbricksBaseIfParams
params
;
...
...
@@ -178,6 +180,19 @@ int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs,
void
SimbricksBaseIfClose
(
struct
SimbricksBaseIf
*
base_if
);
void
SimbricksBaseIfUnlink
(
struct
SimbricksBaseIf
*
base_if
);
/**
* Read message type from received message.
*
* @param base_if Base interface handle (connected).
* @param msg Pointer to the previously received message.
*/
static
inline
uint8_t
SimbricksBaseIfInType
(
struct
SimbricksBaseIf
*
base_if
,
volatile
union
SimbricksProtoBaseMsg
*
msg
)
{
return
(
msg
->
header
.
own_type
&
~
SIMBRICKS_PROTO_MSG_OWN_MASK
);
}
/**
* Poll for an incoming message without advancing the position if one is found.
* Message must be retrieved again with a call to `SimbricksBaseIfInPoll`
...
...
@@ -223,22 +238,18 @@ static inline volatile union SimbricksProtoBaseMsg *SimbricksBaseIfInPoll(
volatile
union
SimbricksProtoBaseMsg
*
msg
=
SimbricksBaseIfInPeek
(
base_if
,
timestamp
);
if
(
msg
!=
NULL
)
if
(
msg
!=
NULL
)
{
base_if
->
in_pos
=
(
base_if
->
in_pos
+
1
)
%
base_if
->
in_enum
;
return
msg
;
}
/**
* Read message type from received message.
*
* @param base_if Base interface handle (connected).
* @param msg Pointer to the previously received message.
*/
static
inline
uint8_t
SimbricksBaseIfInType
(
struct
SimbricksBaseIf
*
base_if
,
volatile
union
SimbricksProtoBaseMsg
*
msg
)
{
return
(
msg
->
header
.
own_type
&
~
SIMBRICKS_PROTO_MSG_OWN_MASK
);
if
(
SimbricksBaseIfInType
(
base_if
,
msg
)
==
SIMBRICKS_PROTO_MSG_TYPE_TERMINATE
)
{
base_if
->
in_terminated
=
true
;
base_if
->
sync
=
false
;
base_if
->
in_timestamp
=
UINT64_MAX
;
base_if
->
out_timestamp
=
UINT64_MAX
;
}
}
return
msg
;
}
/**
...
...
@@ -270,6 +281,16 @@ static inline uint64_t SimbricksBaseIfInTimestamp(
return
base_if
->
in_timestamp
;
}
/**
* Check if incoming channel has been terminated by peer.
*
* @param base_if Base interface handle (connected).
*/
static
inline
int
SimbricksBaseIfInTerminated
(
struct
SimbricksBaseIf
*
base_if
)
{
return
base_if
->
in_terminated
;
}
/**
* Allocate a new message in the queue. Must be followed by a call to
* `SimbricksBaseIfOutSend`.
...
...
@@ -351,6 +372,8 @@ static inline int SimbricksBaseIfOutSync(struct SimbricksBaseIf *base_if,
static
inline
uint64_t
SimbricksBaseIfOutNextSync
(
struct
SimbricksBaseIf
*
base_if
)
{
if
(
base_if
->
out_timestamp
==
UINT64_MAX
)
return
UINT64_MAX
;
return
base_if
->
out_timestamp
+
base_if
->
params
.
sync_interval
;
}
...
...
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