You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/12/20 08:17:16 UTC

[incubator-nuttx-apps] 01/02: system/lzf: replace the semaphore to pthread to ensuring compatibility

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 0f632f1d66cc1883b0de6edc9bee3f817e0b22ad
Author: chao.an <an...@xiaomi.com>
AuthorDate: Mon Dec 20 13:31:57 2021 +0800

    system/lzf: replace the semaphore to pthread to ensuring compatibility
    
    Private SEM_INITIALIZER is incompatible with other OS
    
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 system/lzf/lzf_main.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/system/lzf/lzf_main.c b/system/lzf/lzf_main.c
index 043067f..2f25274 100644
--- a/system/lzf/lzf_main.c
+++ b/system/lzf/lzf_main.c
@@ -41,7 +41,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <semaphore.h>
+#include <pthread.h>
 #include <getopt.h>
 #include <errno.h>
 #include <limits.h>
@@ -59,7 +59,7 @@
  ****************************************************************************/
 
 #if CONFIG_SYSTEM_LZF != CONFIG_m
-static sem_t g_exclsem = SEM_INITIALIZER(1);
+static pthread_mutex_t g_exclmutex = PTHREAD_MUTEX_INITIALIZER;
 #endif
 
 static off_t g_nread;
@@ -78,11 +78,11 @@ static uint8_t g_buf2[MAX_BLOCKSIZE + LZF_MAX_HDR_SIZE + 16];
  * Private Functions
  ****************************************************************************/
 
-#if CONFIG_SYSTEM_LZF != 2
+#if CONFIG_SYSTEM_LZF != CONFIG_m
 static void lzf_exit(int exitcode) noreturn_function;
 static void lzf_exit(int exitcode)
 {
-  sem_post(&g_exclsem);
+  pthread_mutex_unlock(&g_exclmutex);
   exit(exitcode);
 }
 #else
@@ -454,12 +454,7 @@ int main(int argc, FAR char *argv[])
    * global variables.
    */
 
-  ret = sem_wait(&g_exclsem);
-  if (ret < 0)
-    {
-      fprintf(stderr, "sem_wait failed: %d\n", errno);
-      exit(1);
-    }
+  pthread_mutex_lock(&g_exclmutex);
 #endif
 
   /* Set defaults. */