From 3a8f9e5806ca7da408a2d5a880436d096499a01d Mon Sep 17 00:00:00 2001 From: "jijoong.moon" Date: Tue, 27 Nov 2018 16:57:26 +0900 Subject: [PATCH] [Repo] Split Cond variable to use push and pull the data In order to keep the synchronization better, two cond variable is used. **Self evaluation:** 1. Build test: [X]Passed [ ]Failed [ ]Skipped 2. Run test: [X]Passed [ ]Failed [ ]Skipped Signed-off-by: jijoong.moon --- gst/nnstreamer/tensor_repo.c | 18 ++++++++++-------- gst/nnstreamer/tensor_repo.h | 12 ++++++++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/gst/nnstreamer/tensor_repo.c b/gst/nnstreamer/tensor_repo.c index 84bcb0e..8e80288 100644 --- a/gst/nnstreamer/tensor_repo.c +++ b/gst/nnstreamer/tensor_repo.c @@ -67,7 +67,8 @@ gst_tensor_repo_add_repodata (guint nth) new = g_new (GstTensorRepoData, 1); new->eos = FALSE; new->buffer = NULL; - g_cond_init (&new->cond); + g_cond_init (&new->cond_push); + g_cond_init (&new->cond_pull); g_mutex_init (&new->lock); ret = g_hash_table_insert (_repo.hash, GINT_TO_POINTER (nth), new); @@ -91,9 +92,8 @@ gst_tensor_repo_set_buffer (guint nth, GstBuffer * buffer) GstTensorRepoData *data = gst_tensor_repo_get_repodata (nth); - if (data == NULL) { - GST_TENSOR_REPO_UNLOCK (nth); - return FALSE; + while (data->buffer != NULL) { + GST_TENSOR_REPO_WAIT_PULL (nth); } data->buffer = buffer; @@ -102,7 +102,7 @@ gst_tensor_repo_set_buffer (guint nth, GstBuffer * buffer) GST_DEBUG ("Pushed [%d] (size : %lu)\n", nth, size); } - GST_TENSOR_REPO_SIGNAL (nth); + GST_TENSOR_REPO_SIGNAL_PUSH (nth); GST_TENSOR_REPO_UNLOCK (nth); return TRUE; } @@ -130,7 +130,7 @@ gst_tensor_repo_set_eos (guint nth) GST_TENSOR_REPO_LOCK (nth); GstTensorRepoData *data = gst_tensor_repo_get_repodata (nth); data->eos = TRUE; - GST_TENSOR_REPO_SIGNAL (nth); + GST_TENSOR_REPO_SIGNAL_PUSH (nth); GST_TENSOR_REPO_UNLOCK (nth); return data->eos; } @@ -154,7 +154,7 @@ gst_tensor_repo_get_buffer (guint nth) eos = TRUE; break; } - GST_TENSOR_REPO_WAIT (nth); + GST_TENSOR_REPO_WAIT_PUSH (nth); } if (eos) { if (DBG) @@ -168,6 +168,7 @@ gst_tensor_repo_get_buffer (guint nth) } } current_data->buffer = NULL; + GST_TENSOR_REPO_SIGNAL_PULL (nth); GST_TENSOR_REPO_UNLOCK (nth); return buf; } @@ -181,7 +182,8 @@ gst_tensor_repo_remove_repodata (guint nth) gboolean ret; GST_REPO_LOCK (); g_mutex_clear (GST_TENSOR_REPO_GET_LOCK (nth)); - g_cond_clear (GST_TENSOR_REPO_GET_COND (nth)); + g_cond_clear (GST_TENSOR_REPO_GET_COND_PULL (nth)); + g_cond_clear (GST_TENSOR_REPO_GET_COND_PUSH (nth)); ret = g_hash_table_remove (_repo.hash, GINT_TO_POINTER (nth)); diff --git a/gst/nnstreamer/tensor_repo.h b/gst/nnstreamer/tensor_repo.h index 9fb6215..3496c79 100644 --- a/gst/nnstreamer/tensor_repo.h +++ b/gst/nnstreamer/tensor_repo.h @@ -43,7 +43,8 @@ G_BEGIN_DECLS typedef struct { GstBuffer *buffer; - GCond cond; + GCond cond_push; + GCond cond_pull; GMutex lock; gboolean eos; } GstTensorRepoData; @@ -120,11 +121,14 @@ gst_tensor_repo_wait(); * @brief Macro for Lock & Cond */ #define GST_TENSOR_REPO_GET_LOCK(id) (&((GstTensorRepoData*)(gst_tensor_repo_get_repodata(id)))->lock) -#define GST_TENSOR_REPO_GET_COND(id) (&((GstTensorRepoData*)(gst_tensor_repo_get_repodata(id)))->cond) +#define GST_TENSOR_REPO_GET_COND_PUSH(id) (&((GstTensorRepoData*)(gst_tensor_repo_get_repodata(id)))->cond_push) +#define GST_TENSOR_REPO_GET_COND_PULL(id) (&((GstTensorRepoData*)(gst_tensor_repo_get_repodata(id)))->cond_pull) #define GST_TENSOR_REPO_LOCK(id) (g_mutex_lock(GST_TENSOR_REPO_GET_LOCK(id))) #define GST_TENSOR_REPO_UNLOCK(id) (g_mutex_unlock(GST_TENSOR_REPO_GET_LOCK(id))) -#define GST_TENSOR_REPO_WAIT(id) (g_cond_wait(GST_TENSOR_REPO_GET_COND(id), GST_TENSOR_REPO_GET_LOCK(id))) -#define GST_TENSOR_REPO_SIGNAL(id) (g_cond_signal (GST_TENSOR_REPO_GET_COND(id))) +#define GST_TENSOR_REPO_WAIT_PULL(id) (g_cond_wait(GST_TENSOR_REPO_GET_COND_PULL(id), GST_TENSOR_REPO_GET_LOCK(id))) +#define GST_TENSOR_REPO_WAIT_PUSH(id) (g_cond_wait(GST_TENSOR_REPO_GET_COND_PUSH(id), GST_TENSOR_REPO_GET_LOCK(id))) +#define GST_TENSOR_REPO_SIGNAL_PULL(id) (g_cond_signal (GST_TENSOR_REPO_GET_COND_PULL(id))) +#define GST_TENSOR_REPO_SIGNAL_PUSH(id) (g_cond_signal (GST_TENSOR_REPO_GET_COND_PUSH(id))) #define GST_REPO_LOCK()(g_mutex_lock(&_repo.repo_lock)) #define GST_REPO_UNLOCK()(g_mutex_unlock(&_repo.repo_lock)) #define GST_REPO_WAIT() (g_cond_wait(&_repo.repo_cond, &_repo.repo_lock)) -- 2.7.4