You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/02/14 15:02:03 UTC
[incubator-nuttx-apps] branch pr71 updated (66e7590 -> ef03bcc)
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a change to branch pr71
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git.
from 66e7590 examples/elf: Don't bother to honor CONFIG_PATH_INITIAL
new 782953f ntpclient: the 2nd arg of MKLVM should be version number
new 02a800c ntpclient: Initialize g_ntpc_daemon at the definition
new ef03bcc ntpclient: Use sem protect global variable instead sched_lock/unlock
The 3 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:
netutils/ntpclient/ntpclient.c | 48 ++++++++++++++++++++----------------------
1 file changed, 23 insertions(+), 25 deletions(-)
[incubator-nuttx-apps] 02/03: ntpclient: Initialize g_ntpc_daemon
at the definition
Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch pr71
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 02a800c93098d16fa06a8b2a2ea32c3f09a3da81
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Feb 14 17:25:33 2020 +0800
ntpclient: Initialize g_ntpc_daemon at the definition
Change-Id: I4dad2e246aca7d30092cf8a4bc8136e90668f134
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
netutils/ntpclient/ntpclient.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/netutils/ntpclient/ntpclient.c b/netutils/ntpclient/ntpclient.c
index dc8cb60..6be1362 100644
--- a/netutils/ntpclient/ntpclient.c
+++ b/netutils/ntpclient/ntpclient.c
@@ -117,7 +117,12 @@ struct ntpc_daemon_s
* limitation is due only to this global data structure.
*/
-static struct ntpc_daemon_s g_ntpc_daemon;
+static struct ntpc_daemon_s g_ntpc_daemon =
+{
+ NTP_NOT_RUNNING,
+ SEM_INITIALIZER(0),
+ -1
+};
/****************************************************************************
* Private Functions
@@ -531,15 +536,6 @@ int ntpc_start(void)
if (g_ntpc_daemon.state == NTP_NOT_RUNNING ||
g_ntpc_daemon.state == NTP_STOPPED)
{
- /* Is this the first time that the NTP daemon has been started? */
-
- if (g_ntpc_daemon.state == NTP_NOT_RUNNING)
- {
- /* Yes... then we will need to initialize the state structure */
-
- sem_init(&g_ntpc_daemon.interlock, 0, 0);
- }
-
/* Start the NTP daemon */
g_ntpc_daemon.state = NTP_STARTED;
[incubator-nuttx-apps] 01/03: ntpclient: the 2nd arg of MKLVM
should be version number
Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch pr71
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 782953ff05692659c9875ac6e88346852400508c
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Feb 14 17:22:46 2020 +0800
ntpclient: the 2nd arg of MKLVM should be version number
Change-Id: I742c3a5082f48fcc8e291100ff81c60093bc7538
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
netutils/ntpclient/ntpclient.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/netutils/ntpclient/ntpclient.c b/netutils/ntpclient/ntpclient.c
index 9e6b328..dc8cb60 100644
--- a/netutils/ntpclient/ntpclient.c
+++ b/netutils/ntpclient/ntpclient.c
@@ -409,7 +409,7 @@ static int ntpc_daemon(int argc, char **argv)
/* Format the transmit datagram */
memset(&pkt, 0, sizeof(pkt));
- pkt.lvm = MKLVM(0, 3, NTP_VERSION);
+ pkt.lvm = MKLVM(0, NTP_VERSION, 3);
sinfo("Sending a NTP packet\n");
[incubator-nuttx-apps] 03/03: ntpclient: Use sem protect global
variable instead sched_lock/unlock
Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch pr71
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit ef03bccab5294dc397ba64235595333c58a15a4e
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Feb 14 18:02:42 2020 +0800
ntpclient: Use sem protect global variable instead sched_lock/unlock
Change-Id: I67fae76eb8ff47789059de567922864e6ef2311f
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
netutils/ntpclient/ntpclient.c | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/netutils/ntpclient/ntpclient.c b/netutils/ntpclient/ntpclient.c
index 6be1362..3067c7c 100644
--- a/netutils/ntpclient/ntpclient.c
+++ b/netutils/ntpclient/ntpclient.c
@@ -103,9 +103,10 @@ enum ntpc_daemon_e
struct ntpc_daemon_s
{
- volatile uint8_t state; /* See enum ntpc_daemon_e */
- sem_t interlock; /* Used to synchronize start and stop events */
- pid_t pid; /* Task ID of the NTP daemon */
+ uint8_t state; /* See enum ntpc_daemon_e */
+ sem_t lock; /* Used to protect the whole structure */
+ sem_t sync; /* Used to synchronize start and stop events */
+ pid_t pid; /* Task ID of the NTP daemon */
};
/****************************************************************************
@@ -120,6 +121,7 @@ struct ntpc_daemon_s
static struct ntpc_daemon_s g_ntpc_daemon =
{
NTP_NOT_RUNNING,
+ SEM_INITIALIZER(1),
SEM_INITIALIZER(0),
-1
};
@@ -328,7 +330,7 @@ static int ntpc_daemon(int argc, char **argv)
/* Indicate that we have started */
g_ntpc_daemon.state = NTP_RUNNING;
- sem_post(&g_ntpc_daemon.interlock);
+ sem_post(&g_ntpc_daemon.sync);
/* Create a datagram socket */
@@ -338,7 +340,7 @@ static int ntpc_daemon(int argc, char **argv)
nerr("ERROR: socket failed: %d\n", errno);
g_ntpc_daemon.state = NTP_STOPPED;
- sem_post(&g_ntpc_daemon.interlock);
+ sem_post(&g_ntpc_daemon.sync);
return EXIT_FAILURE;
}
@@ -353,7 +355,7 @@ static int ntpc_daemon(int argc, char **argv)
nerr("ERROR: setsockopt failed: %d\n", errno);
g_ntpc_daemon.state = NTP_STOPPED;
- sem_post(&g_ntpc_daemon.interlock);
+ sem_post(&g_ntpc_daemon.sync);
return EXIT_FAILURE;
}
@@ -509,7 +511,7 @@ static int ntpc_daemon(int argc, char **argv)
sched_unlock();
g_ntpc_daemon.state = NTP_STOPPED;
- sem_post(&g_ntpc_daemon.interlock);
+ sem_post(&g_ntpc_daemon.sync);
return exitcode;
}
@@ -532,7 +534,7 @@ int ntpc_start(void)
{
/* Is the NTP in a non-running state? */
- sched_lock();
+ sem_wait(&g_ntpc_daemon.lock);
if (g_ntpc_daemon.state == NTP_NOT_RUNNING ||
g_ntpc_daemon.state == NTP_STOPPED)
{
@@ -553,7 +555,7 @@ int ntpc_start(void)
g_ntpc_daemon.state = NTP_STOPPED;
nerr("ERROR: Failed to start the NTP daemon\n", errval);
- sched_unlock();
+ sem_post(&g_ntpc_daemon.lock);
return -errval;
}
@@ -561,12 +563,12 @@ int ntpc_start(void)
do
{
- sem_wait(&g_ntpc_daemon.interlock);
+ sem_wait(&g_ntpc_daemon.sync);
}
while (g_ntpc_daemon.state == NTP_STARTED);
}
- sched_unlock();
+ sem_post(&g_ntpc_daemon.lock);
return g_ntpc_daemon.pid;
}
@@ -588,7 +590,7 @@ int ntpc_stop(void)
/* Is the NTP in a running state? */
- sched_lock();
+ sem_wait(&g_ntpc_daemon.lock);
if (g_ntpc_daemon.state == NTP_STARTED ||
g_ntpc_daemon.state == NTP_RUNNING)
{
@@ -614,11 +616,11 @@ int ntpc_stop(void)
/* Wait for the NTP client to respond to the stop request */
- sem_wait(&g_ntpc_daemon.interlock);
+ sem_wait(&g_ntpc_daemon.sync);
}
while (g_ntpc_daemon.state == NTP_STOP_REQUESTED);
}
- sched_unlock();
+ sem_post(&g_ntpc_daemon.lock);
return OK;
}