Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
9a58b0f9
Commit
9a58b0f9
authored
4 years ago
by
Loic Hausammann
Browse files
Options
Downloads
Patches
Plain Diff
Logger history thread safe
parent
b37aff5b
No related branches found
No related tags found
1 merge request
!1245
Logger history thread safe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/logger_history.c
+8
-0
8 additions, 0 deletions
src/logger_history.c
src/logger_history.h
+3
-0
3 additions, 0 deletions
src/logger_history.h
with
11 additions
and
0 deletions
src/logger_history.c
+
8
−
0
View file @
9a58b0f9
...
@@ -41,6 +41,7 @@ void logger_history_init(struct logger_history *hist) {
...
@@ -41,6 +41,7 @@ void logger_history_init(struct logger_history *hist) {
/* Set the counters to their initial value */
/* Set the counters to their initial value */
hist
->
size
=
0
;
hist
->
size
=
0
;
hist
->
capacity
=
LOGGER_HISTORY_INIT_SIZE
;
hist
->
capacity
=
LOGGER_HISTORY_INIT_SIZE
;
lock_init
(
hist
->
lock
);
hist
->
data
=
(
struct
logger_index_data
*
)
swift_malloc
(
hist
->
data
=
(
struct
logger_index_data
*
)
swift_malloc
(
"logger_history"
,
"logger_history"
,
...
@@ -73,6 +74,7 @@ void logger_history_free(struct logger_history *hist) {
...
@@ -73,6 +74,7 @@ void logger_history_free(struct logger_history *hist) {
/* Set the counters to 0 */
/* Set the counters to 0 */
hist
->
size
=
0
;
hist
->
size
=
0
;
hist
->
capacity
=
0
;
hist
->
capacity
=
0
;
lock_destroy
(
hist
->
lock
);
/* Free the memory */
/* Free the memory */
if
(
hist
->
data
!=
NULL
)
{
if
(
hist
->
data
!=
NULL
)
{
...
@@ -99,6 +101,9 @@ void logger_history_log(struct logger_history *hist, const long long id,
...
@@ -99,6 +101,9 @@ void logger_history_log(struct logger_history *hist, const long long id,
#endif
#endif
const
struct
logger_index_data
data
=
{
id
,
last_offset
};
const
struct
logger_index_data
data
=
{
id
,
last_offset
};
/* Lock the history */
lock_lock
(
hist
->
lock
);
/* Check if enough space is left */
/* Check if enough space is left */
if
(
hist
->
size
==
hist
->
capacity
)
{
if
(
hist
->
size
==
hist
->
capacity
)
{
/* Compute the previous amount of memory */
/* Compute the previous amount of memory */
...
@@ -123,6 +128,9 @@ void logger_history_log(struct logger_history *hist, const long long id,
...
@@ -123,6 +128,9 @@ void logger_history_log(struct logger_history *hist, const long long id,
/* Increase the element counter */
/* Increase the element counter */
hist
->
size
+=
1
;
hist
->
size
+=
1
;
/* Unlock the history. */
lock_unlock
(
hist
->
lock
);
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
src/logger_history.h
+
3
−
0
View file @
9a58b0f9
...
@@ -65,6 +65,9 @@ struct logger_history {
...
@@ -65,6 +65,9 @@ struct logger_history {
/* Buffer containing the particles */
/* Buffer containing the particles */
struct
logger_index_data
*
data
;
struct
logger_index_data
*
data
;
/*! Spin lock for logging events. */
swift_lock_type
lock
;
};
};
void
logger_history_init
(
struct
logger_history
*
hist
);
void
logger_history_init
(
struct
logger_history
*
hist
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment