[Pkg-voip-commits] [janus] 149/282: Made a few recorder properties atomic
Jonas Smedegaard
dr at jones.dk
Wed Dec 20 21:53:36 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/0.2.6-1
in repository janus.
commit 453252a796b4d9cd51425af23c6af2eec3d6a67a
Author: Lorenzo Miniero <lminiero at gmail.com>
Date: Tue Oct 24 15:07:22 2017 +0200
Made a few recorder properties atomic
---
record.c | 13 ++++++-------
record.h | 4 ++--
2 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/record.c b/record.c
index 080da71..e794853 100644
--- a/record.c
+++ b/record.c
@@ -160,9 +160,9 @@ janus_recorder *janus_recorder_create(const char *dir, const char *codec, const
rc->type = type;
/* Write the first part of the header */
fwrite(header, sizeof(char), strlen(header), rc->file);
- rc->writable = 1;
+ g_atomic_int_set(&rc->writable, 1);
/* We still need to also write the info header first */
- rc->header = 0;
+ g_atomic_int_set(&rc->header, 0);
janus_mutex_init(&rc->mutex);
return rc;
}
@@ -179,11 +179,11 @@ int janus_recorder_save_frame(janus_recorder *recorder, char *buffer, uint lengt
janus_mutex_unlock_nodebug(&recorder->mutex);
return -3;
}
- if(!recorder->writable) {
+ if(!g_atomic_int_get(&recorder->writable)) {
janus_mutex_unlock_nodebug(&recorder->mutex);
return -4;
}
- if(!recorder->header) {
+ if(!g_atomic_int_get(&recorder->header)) {
/* Write info header as a JSON formatted info */
json_t *info = json_object();
/* FIXME Codecs should be configurable in the future */
@@ -205,7 +205,7 @@ int janus_recorder_save_frame(janus_recorder *recorder, char *buffer, uint lengt
fwrite(info_text, sizeof(char), strlen(info_text), recorder->file);
free(info_text);
/* Done */
- recorder->header = 1;
+ g_atomic_int_set(&recorder->header, 1);
}
/* Write frame header */
fwrite(frame_header, sizeof(char), strlen(frame_header), recorder->file);
@@ -233,10 +233,9 @@ int janus_recorder_save_frame(janus_recorder *recorder, char *buffer, uint lengt
}
int janus_recorder_close(janus_recorder *recorder) {
- if(!recorder || !recorder->writable)
+ if(!recorder || !g_atomic_int_compare_and_exchange(&recorder->writable, 1, 0))
return -1;
janus_mutex_lock_nodebug(&recorder->mutex);
- recorder->writable = 0;
if(recorder->file) {
fseek(recorder->file, 0L, SEEK_END);
size_t fsize = ftell(recorder->file);
diff --git a/record.h b/record.h
index 30f9012..f52d1b4 100644
--- a/record.h
+++ b/record.h
@@ -49,9 +49,9 @@ typedef struct janus_recorder {
/*! \brief Media this instance is recording */
janus_recorder_medium type;
/*! \brief Whether the info header for this recorder instance has already been written or not */
- int header:1;
+ volatile int header;
/*! \brief Whether this recorder instance can be used for writing or not */
- int writable:1;
+ volatile int writable;
/*! \brief Mutex to lock/unlock this recorder instance */
janus_mutex mutex;
} janus_recorder;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/janus.git
More information about the Pkg-voip-commits
mailing list