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 2022/11/17 09:58:51 UTC
[incubator-nuttx-apps] branch master updated: apps: getpid should return process id not thread id
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
The following commit(s) were added to refs/heads/master by this push:
new c86509be4 apps: getpid should return process id not thread id
c86509be4 is described below
commit c86509be4cacb767510ad144b27fef7c1da37065
Author: qinwei1 <qi...@xiaomi.com>
AuthorDate: Fri Nov 11 14:20:43 2022 +0800
apps: getpid should return process id not thread id
Summary:
following the change in the nuttx kernel, implement the right semantics:
1. getpid should return the main thread id
2. gettid should return the current thread id
Refer:
https://github.com/apache/incubator-nuttx/issues/2499
https://github.com/apache/incubator-nuttx/pull/2518
Nuttx Kernel PR:
https://github.com/apache/incubator-nuttx/pull/7597
update apps code
Testing PASSED with qemu( 32/64 )
Signed-off-by: qinwei1 <qi...@xiaomi.com>
---
graphics/pdcurs34/nuttx/pdcthread.c | 12 ++++++------
netutils/netlib/netlib_getarptab.c | 2 +-
netutils/netlib/netlib_getdevs.c | 2 +-
netutils/netlib/netlib_getnbtab.c | 2 +-
netutils/netlib/netlib_getroute.c | 2 +-
netutils/thttpd/libhttpd.c | 6 +++---
system/taskset/taskset.c | 2 +-
testing/ostest/prioinherit.c | 4 ++--
testing/ostest/timedwait.c | 2 +-
9 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/graphics/pdcurs34/nuttx/pdcthread.c b/graphics/pdcurs34/nuttx/pdcthread.c
index 4568e886d..e1295f04a 100644
--- a/graphics/pdcurs34/nuttx/pdcthread.c
+++ b/graphics/pdcurs34/nuttx/pdcthread.c
@@ -116,9 +116,9 @@ static FAR struct pdc_context_s *PDC_ctx_new(void)
ctx->panel_ctx = pdc_alloc_panel_ctx();
ctx->term_ctx = pdc_alloc_term_ctx();
- /* Get our PID */
+ /* Get our TID */
- pid = getpid();
+ pid = gettid();
#ifdef CONFIG_PDCURSES_MULTITHREAD_HASH
@@ -177,9 +177,9 @@ FAR struct pdc_context_s * PDC_ctx(void)
PDC_ctx_initialize();
}
- /* Get our PID */
+ /* Get our TID */
- pid = getpid();
+ pid = gettid();
#ifdef CONFIG_PDCURSES_MULTITHREAD_HASH
@@ -262,9 +262,9 @@ void PDC_ctx_free(void)
#ifdef CONFIG_PDCURSES_MULTITHREAD_HASH
int pid;
- /* Get a unique hash key from the PID */
+ /* Get a unique hash key from the TID */
- pid = PIDHASH(getpid());
+ pid = PIDHASH(gettid());
ctx = g_pdc_ctx_per_pid[pid];
/* Free the context memory */
diff --git a/netutils/netlib/netlib_getarptab.c b/netutils/netlib/netlib_getarptab.c
index 477f1b487..801e250aa 100644
--- a/netutils/netlib/netlib_getarptab.c
+++ b/netutils/netlib/netlib_getarptab.c
@@ -122,7 +122,7 @@ ssize_t netlib_get_arptable(FAR struct arp_entry_s *arptab,
/* Bind the socket so that we can use send() and receive() */
- pid = getpid();
+ pid = gettid();
addr.nl_family = AF_NETLINK;
addr.nl_pad = 0;
addr.nl_pid = pid;
diff --git a/netutils/netlib/netlib_getdevs.c b/netutils/netlib/netlib_getdevs.c
index 4a0248522..08ce0723c 100644
--- a/netutils/netlib/netlib_getdevs.c
+++ b/netutils/netlib/netlib_getdevs.c
@@ -110,7 +110,7 @@ ssize_t netlib_get_devices(FAR struct netlib_device_s *devlist,
/* Bind the socket so that we can use send() and receive() */
- pid = getpid();
+ pid = gettid();
addr.nl_family = AF_NETLINK;
addr.nl_pad = 0;
addr.nl_pid = pid;
diff --git a/netutils/netlib/netlib_getnbtab.c b/netutils/netlib/netlib_getnbtab.c
index c5c249d95..519f89fbd 100644
--- a/netutils/netlib/netlib_getnbtab.c
+++ b/netutils/netlib/netlib_getnbtab.c
@@ -123,7 +123,7 @@ ssize_t netlib_get_nbtable(FAR struct neighbor_entry_s *nbtab,
/* Bind the socket so that we can use send() and receive() */
- pid = getpid();
+ pid = gettid();
addr.nl_family = AF_NETLINK;
addr.nl_pad = 0;
addr.nl_pid = pid;
diff --git a/netutils/netlib/netlib_getroute.c b/netutils/netlib/netlib_getroute.c
index 55e9dfe4f..84c670b2e 100644
--- a/netutils/netlib/netlib_getroute.c
+++ b/netutils/netlib/netlib_getroute.c
@@ -140,7 +140,7 @@ ssize_t netlib_get_route(FAR struct rtentry *rtelist,
/* Bind the socket so that we can use send() and receive() */
- pid = getpid();
+ pid = gettid();
addr.nl_family = AF_NETLINK;
addr.nl_pad = 0;
addr.nl_pid = pid;
diff --git a/netutils/thttpd/libhttpd.c b/netutils/thttpd/libhttpd.c
index 7e31d2cbf..555817177 100644
--- a/netutils/thttpd/libhttpd.c
+++ b/netutils/thttpd/libhttpd.c
@@ -2135,9 +2135,9 @@ FAR httpd_server *httpd_initialize(FAR httpd_sockaddr *sa)
{
FAR httpd_server *hs;
- /* Save the PID of the main thread */
+ /* Save the TID of the main thread */
- main_thread = getpid();
+ main_thread = gettid();
/* Allocate the server structure */
@@ -2203,7 +2203,7 @@ void httpd_write_response(httpd_conn *hc)
{
/* If we are in a sub-task, turn off no-delay mode. */
- if (main_thread != getpid())
+ if (main_thread != gettid())
{
httpd_clear_ndelay(hc->conn_fd);
}
diff --git a/system/taskset/taskset.c b/system/taskset/taskset.c
index ea6d5ec0c..53f85375f 100644
--- a/system/taskset/taskset.c
+++ b/system/taskset/taskset.c
@@ -160,7 +160,7 @@ int main(int argc, FAR char *argv[])
strcat(command, " ");
}
- sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
+ sched_setaffinity(gettid(), sizeof(cpu_set_t), &cpuset);
system(command);
}
}
diff --git a/testing/ostest/prioinherit.c b/testing/ostest/prioinherit.c
index 8db384c63..e9502855b 100644
--- a/testing/ostest/prioinherit.c
+++ b/testing/ostest/prioinherit.c
@@ -100,7 +100,7 @@ static void sleep_and_display(int n, int us)
do
{
- int status = sched_getparam(getpid(), &sparam);
+ int status = sched_getparam(gettid(), &sparam);
if (status != 0)
{
@@ -503,7 +503,7 @@ void priority_inheritance(void)
for (i = 0; i < NHIGHPRI_THREADS; i++) g_highstate[i] = NOTSTARTED;
for (i = 0; i < NLOWPRI_THREADS; i++) g_lowstate[i] = NOTSTARTED;
- status = sched_getparam(getpid(), &sparam);
+ status = sched_getparam(gettid(), &sparam);
if (status != 0)
{
printf("priority_inheritance: ERROR sched_getparam failed\n");
diff --git a/testing/ostest/timedwait.c b/testing/ostest/timedwait.c
index e04b91b16..3018dcbc9 100644
--- a/testing/ostest/timedwait.c
+++ b/testing/ostest/timedwait.c
@@ -158,7 +158,7 @@ void timedwait_test(void)
}
prio_max = sched_get_priority_max(SCHED_FIFO);
- status = sched_getparam (getpid(), &sparam);
+ status = sched_getparam (gettid(), &sparam);
if (status != 0)
{
printf("timedwait_test: sched_getparam failed\n");