Skip to content

Commit

Permalink
[Common] wait for thread with lock
Browse files Browse the repository at this point in the history
Add lock to wait for creating new thread for data transfer.

Signed-off-by: Jaeyun Jung <[email protected]>
  • Loading branch information
jaeyun-jung authored and myungjoo committed Dec 6, 2023
1 parent 1b313de commit 863a42d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/libnnstreamer-edge/nnstreamer-edge-internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,11 @@ _nns_edge_send_thread (void *thread_data)
char *val;
int ret;

nns_edge_lock (eh);
eh->sending = true;
nns_edge_cond_signal (eh);
nns_edge_unlock (eh);

while (eh->sending &&
NNS_EDGE_ERROR_NONE == nns_edge_queue_wait_pop (eh->send_queue, 0U,
&data_h, &data_size)) {
Expand Down Expand Up @@ -914,23 +917,25 @@ _nns_edge_send_thread (void *thread_data)

/**
* @brief Create thread to send data.
* @note This should be called with lock.
*/
static int
_nns_edge_create_send_thread (nns_edge_handle_s * eh)
{
int status;

status = pthread_create (&eh->send_thread, NULL, _nns_edge_send_thread, eh);
while (!eh->sending) {
nns_edge_cond_wait (eh);
}

if (status != 0) {
nns_edge_loge ("Failed to create sender thread.");
eh->send_thread = 0;
eh->sending = false;
return NNS_EDGE_ERROR_IO;
}

/* Wait for starting thread. */
nns_edge_cond_wait (eh);

return NNS_EDGE_ERROR_NONE;
}

Expand Down

0 comments on commit 863a42d

Please sign in to comment.