diff mbox series

Sync update from file with CV

Message ID 20201231112252.132665-1-sbabic@denx.de
State Accepted
Headers show
Series Sync update from file with CV | expand

Commit Message

Stefano Babic Dec. 31, 2020, 11:22 a.m. UTC
Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 core/install_from_file.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/core/install_from_file.c b/core/install_from_file.c
index a595c30..987fa17 100644
--- a/core/install_from_file.c
+++ b/core/install_from_file.c
@@ -23,6 +23,7 @@  static pthread_mutex_t mymutex;
 static char buf[16 * 1024];
 static int fd = STDIN_FILENO;
 static int end_status = EXIT_SUCCESS;
+static pthread_cond_t cv_end = PTHREAD_COND_INITIALIZER;
 /*
  * this is the callback to get a new chunk of the
  * image.
@@ -54,6 +55,8 @@  static int endupdate(RECOVERY_STATUS status)
 		status == FAILURE ? "*failed* !" :
 			"was successful !");
 
+	pthread_mutex_lock(&mymutex);
+	pthread_cond_signal(&cv_end);
 	pthread_mutex_unlock(&mymutex);
 
 	return 0;
@@ -71,10 +74,6 @@  int install_from_file(const char *filename, bool check)
 
 	pthread_mutex_init(&mymutex, NULL);
 
-	/* synchronize with a mutex */
-	pthread_mutex_lock(&mymutex);
-
-
 	/* May be set non-zero by end() function on failure */
 	end_status = EXIT_SUCCESS;
 
@@ -102,8 +101,7 @@  int install_from_file(const char *filename, bool check)
 
 	/* Now block */
 	pthread_mutex_lock(&mymutex);
-
-	/* End called, unlock and exit */
+	pthread_cond_wait(&cv_end, &mymutex);
 	pthread_mutex_unlock(&mymutex);
 
 	if (filename)