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 2020/09/05 08:42:03 UTC

[incubator-nuttx] branch master updated (719246e -> 18b47f9)

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

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


    from 719246e  stm32h7:i2c driver fixed iterrupt storm
     new 5beb32b  arch/sim: Use pthread_cond for signalling CPU initialisation done
     new 18b47f9  arch/sim: Add the pthread_cond_* API to the nuttx-names.in list

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 arch/sim/src/nuttx-names.in  |  4 ++++
 arch/sim/src/sim/up_simsmp.c | 41 ++++++++++++++++++++++++++---------------
 2 files changed, 30 insertions(+), 15 deletions(-)


[incubator-nuttx] 01/02: arch/sim: Use pthread_cond for signalling CPU initialisation done

Posted by xi...@apache.org.
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.git

commit 5beb32bf0b1a9373f6a26a797e495757a2422e31
Author: Sebastian Ene <nu...@fitbit.com>
AuthorDate: Fri Sep 4 11:54:57 2020 +0300

    arch/sim: Use pthread_cond for signalling CPU initialisation done
    
      ## Summary of changes
    
    On OSX with CONFIG_SMP=y the semaphore which notifies that the CPU is
    initialised, is not created and the up_cpu_start() returns with error
    from sem_init(). This patch fixes the problem by using pthread_cond_t
    signalling mechanism which is supported on Mac.
    
    Signed-off-by: Sebastian Ene <nu...@fitbit.com>
---
 arch/sim/src/sim/up_simsmp.c | 41 ++++++++++++++++++++++++++---------------
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/arch/sim/src/sim/up_simsmp.c b/arch/sim/src/sim/up_simsmp.c
index 243f89b..56f8ac6 100644
--- a/arch/sim/src/sim/up_simsmp.c
+++ b/arch/sim/src/sim/up_simsmp.c
@@ -39,7 +39,8 @@
 
 #include <stdint.h>
 #include <pthread.h>
-#include <semaphore.h>
+#include <stdlib.h>
+#include <stdbool.h>
 #include <signal.h>
 #include <sched.h>
 #include <errno.h>
@@ -52,8 +53,10 @@
 
 struct sim_cpuinfo_s
 {
-  int cpu;    /* CPU number */
-  sem_t done; /* For synchronization */
+  int cpu;                       /* CPU number */
+  pthread_cond_t cpu_init_done;  /* For synchronization */
+  pthread_mutex_t cpu_init_lock;
+  bool is_cpu_initialized;
 };
 
 /****************************************************************************
@@ -145,7 +148,12 @@ static void *sim_idle_trampoline(void *arg)
 
   /* Let up_cpu_start() continue */
 
-  sem_post(&cpuinfo->done);
+  pthread_mutex_lock(&cpuinfo->cpu_init_lock);
+
+  cpuinfo->is_cpu_initialized = true;
+  pthread_cond_signal(&cpuinfo->cpu_init_done);
+
+  pthread_mutex_unlock(&cpuinfo->cpu_init_lock);
 
   /* up_cpu_started() is logically a part of this function but needs to be
    * inserted in the path because in needs to access NuttX domain definition.
@@ -324,11 +332,10 @@ int up_cpu_start(int cpu)
   /* Initialize the CPU info */
 
   cpuinfo.cpu = cpu;
-  ret = sem_init(&cpuinfo.done, 0, 0);
-  if (ret != 0)
-    {
-      return -errno;  /* REVISIT:  That is a host errno value. */
-    }
+  cpuinfo.is_cpu_initialized = false;
+
+  pthread_mutex_init(&cpuinfo.cpu_init_lock, NULL);
+  pthread_cond_init(&cpuinfo.cpu_init_done, NULL);
 
   /* Start the CPU emulation thread.  This is analogous to starting the CPU
    * in a multi-CPU hardware model.
@@ -339,19 +346,23 @@ int up_cpu_start(int cpu)
   if (ret != 0)
     {
       ret = -ret;  /* REVISIT:  That is a host errno value. */
-      goto errout_with_sem;
+      goto errout_with_cond;
     }
 
   /* This will block until the pthread post the semaphore */
 
-  ret = sem_wait(&cpuinfo.done);
-  if (ret != 0)
+  pthread_mutex_lock(&cpuinfo.cpu_init_lock);
+
+  while (!cpuinfo.is_cpu_initialized)
     {
-      ret = -errno;  /* REVISIT:  That is a host errno value. */
+      pthread_cond_wait(&cpuinfo.cpu_init_done, &cpuinfo.cpu_init_lock);
     }
 
-errout_with_sem:
-  sem_destroy(&cpuinfo.done);
+  pthread_mutex_unlock(&cpuinfo.cpu_init_lock);
+
+errout_with_cond:
+  pthread_mutex_destroy(&cpuinfo.cpu_init_lock);
+  pthread_cond_destroy(&cpuinfo.cpu_init_done);
   return ret;
 }
 


[incubator-nuttx] 02/02: arch/sim: Add the pthread_cond_* API to the nuttx-names.in list

Posted by xi...@apache.org.
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.git

commit 18b47f966381555692a51984944921e31ee69b14
Author: Sebastian Ene <nu...@fitbit.com>
AuthorDate: Fri Sep 4 11:59:34 2020 +0300

    arch/sim: Add the pthread_cond_* API to the nuttx-names.in list
    
     ## Summary of changes
    
    The pthread_cond_* API is also present as part of libfs.a and we want
    to avoid colisions and link with the correct implementation.
    
    Signed-off-by: Sebastian Ene <nu...@fitbit.com>
---
 arch/sim/src/nuttx-names.in | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/sim/src/nuttx-names.in b/arch/sim/src/nuttx-names.in
index 165db84..82f0931 100644
--- a/arch/sim/src/nuttx-names.in
+++ b/arch/sim/src/nuttx-names.in
@@ -114,6 +114,10 @@ NXSYMBOLS(pipe)
 NXSYMBOLS(poll)
 NXSYMBOLS(printf)
 NXSYMBOLS(pthread_create)
+NXSYMBOLS(pthread_cond_destroy)
+NXSYMBOLS(pthread_cond_init)
+NXSYMBOLS(pthread_cond_signal)
+NXSYMBOLS(pthread_cond_wait)
 NXSYMBOLS(pthread_detach)
 NXSYMBOLS(pthread_exit)
 NXSYMBOLS(pthread_getspecific)