Skip to content
Snippets Groups Projects
Commit 9a58b0f9 authored by Loic Hausammann's avatar Loic Hausammann
Browse files

Logger history thread safe

parent b37aff5b
No related branches found
No related tags found
1 merge request!1245Logger history thread safe
...@@ -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);
} }
/** /**
......
...@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment