diff --git a/arch/arm/src/cxd56xx/cxd56_farapi.c b/arch/arm/src/cxd56xx/cxd56_farapi.c index 8e791caa23..ebc2ae20de 100644 --- a/arch/arm/src/cxd56xx/cxd56_farapi.c +++ b/arch/arm/src/cxd56xx/cxd56_farapi.c @@ -192,14 +192,14 @@ void farapi_main(int id, void *arg, struct modulelist_s *mlist) { /* Save the current cpuset */ - sched_getaffinity(gettid(), sizeof(cpu_set_t), &cpuset0); + sched_getaffinity(nxsched_gettid(), sizeof(cpu_set_t), &cpuset0); /* Assign the current task to cpu0 */ cpu_set_t cpuset1; CPU_ZERO(&cpuset1); CPU_SET(0, &cpuset1); - sched_setaffinity(gettid(), sizeof(cpu_set_t), &cpuset1); + sched_setaffinity(nxsched_gettid(), sizeof(cpu_set_t), &cpuset1); /* NOTE: a workaround to finish rescheduling */ @@ -267,7 +267,7 @@ err: { /* Restore the cpu affinity */ - sched_setaffinity(gettid(), sizeof(cpu_set_t), &cpuset0); + sched_setaffinity(nxsched_gettid(), sizeof(cpu_set_t), &cpuset0); /* NOTE: a workaround to finish rescheduling */ diff --git a/arch/arm/src/cxd56xx/cxd56_gnss.c b/arch/arm/src/cxd56xx/cxd56_gnss.c index 1cbef74c09..ee44942318 100644 --- a/arch/arm/src/cxd56xx/cxd56_gnss.c +++ b/arch/arm/src/cxd56xx/cxd56_gnss.c @@ -1577,7 +1577,7 @@ static int cxd56_gnss_set_signal(struct file *filep, unsigned long arg) } sig = NULL; - pid = getpid(); + pid = nxsched_getpid(); for (i = 0; i < CONFIG_CXD56_GNSS_NSIGNALRECEIVERS; i++) { checksig = &priv->sigs[i]; diff --git a/arch/arm/src/cxd56xx/cxd56_icc.c b/arch/arm/src/cxd56xx/cxd56_icc.c index 7b7624b983..c41e99d736 100644 --- a/arch/arm/src/cxd56xx/cxd56_icc.c +++ b/arch/arm/src/cxd56xx/cxd56_icc.c @@ -519,7 +519,7 @@ int cxd56_iccnotify(int cpuid, int signo, void *sigdata) return -ESRCH; } - priv->pid = getpid(); + priv->pid = nxsched_getpid(); priv->signo = signo; priv->sigdata = sigdata; diff --git a/arch/arm/src/cxd56xx/cxd56_scu.c b/arch/arm/src/cxd56xx/cxd56_scu.c index 38c0588758..c7eec8158f 100644 --- a/arch/arm/src/cxd56xx/cxd56_scu.c +++ b/arch/arm/src/cxd56xx/cxd56_scu.c @@ -2237,7 +2237,7 @@ static int seq_seteventnotifier(struct scufifo_s *fifo, flags = enter_critical_section(); priv->event[mid].signo = ev->signo; - priv->event[mid].pid = getpid(); + priv->event[mid].pid = nxsched_getpid(); priv->event[mid].arg = ev->arg; priv->event[mid].fifo = fifo; leave_critical_section(flags); @@ -2320,7 +2320,7 @@ static int seq_setwatermark(struct seq_s *seq, int fifoid, flags = enter_critical_section(); notify->signo = wm->signo; - notify->pid = getpid(); + notify->pid = nxsched_getpid(); notify->ts = wm->ts; notify->fifo = fifo; diff --git a/arch/arm/src/cxd56xx/cxd56_usbdev.c b/arch/arm/src/cxd56xx/cxd56_usbdev.c index 08858425ea..d2763964ce 100644 --- a/arch/arm/src/cxd56xx/cxd56_usbdev.c +++ b/arch/arm/src/cxd56xx/cxd56_usbdev.c @@ -3342,7 +3342,7 @@ int cxd56_usbdev_setsigno(int signo) uinfo("signo = %d\n", signo); priv->signo = signo; - priv->pid = getpid(); + priv->pid = nxsched_getpid(); return OK; } diff --git a/arch/arm/src/lc823450/lc823450_i2s.c b/arch/arm/src/lc823450/lc823450_i2s.c index 03f701f61f..61638c9eb8 100644 --- a/arch/arm/src/lc823450/lc823450_i2s.c +++ b/arch/arm/src/lc823450/lc823450_i2s.c @@ -1045,11 +1045,11 @@ struct i2s_dev_s *lc823450_i2sdev_initialize(void) /* Backup the current affinity */ - nxsched_get_affinity(gettid(), sizeof(cpuset0), &cpuset0); + nxsched_get_affinity(nxsched_gettid(), sizeof(cpuset0), &cpuset0); /* Set the new affinity which assigns to CPU0 */ - nxsched_set_affinity(gettid(), sizeof(cpuset1), &cpuset1); + nxsched_set_affinity(nxsched_gettid(), sizeof(cpuset1), &cpuset1); nxsig_usleep(10 * 1000); #endif @@ -1062,7 +1062,7 @@ struct i2s_dev_s *lc823450_i2sdev_initialize(void) #ifdef CONFIG_SMP /* Restore the original affinity */ - nxsched_set_affinity(gettid(), sizeof(cpuset0), &cpuset0); + nxsched_set_affinity(nxsched_gettid(), sizeof(cpuset0), &cpuset0); nxsig_usleep(10 * 1000); #endif diff --git a/arch/risc-v/src/bl602/bl602_os_hal.c b/arch/risc-v/src/bl602/bl602_os_hal.c index 011dd1bd8b..ee2314664b 100644 --- a/arch/risc-v/src/bl602/bl602_os_hal.c +++ b/arch/risc-v/src/bl602/bl602_os_hal.c @@ -359,7 +359,7 @@ void bl_os_task_delete(void *task_handle) void *bl_os_task_get_current_task(void) { - pid_t pid = getpid(); + pid_t pid = nxsched_getpid(); return (void *)((uintptr_t)pid); } diff --git a/arch/risc-v/src/esp32c3/esp32c3_libc_stubs.c b/arch/risc-v/src/esp32c3/esp32c3_libc_stubs.c index 3e03f4145f..688c535f9d 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_libc_stubs.c +++ b/arch/risc-v/src/esp32c3/esp32c3_libc_stubs.c @@ -69,7 +69,7 @@ int _fstat_r(struct _reent *r, int fd, struct stat *statbuf) int _getpid_r(struct _reent *r) { - return getpid(); + return nxsched_getpid(); } int _kill_r(struct _reent *r, int pid, int sig) diff --git a/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c b/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c index 459ee6bf0e..9b7bd06858 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c +++ b/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c @@ -2095,7 +2095,7 @@ static int32_t esp_task_ms_to_tick(uint32_t ms) static void *esp_task_get_current_task(void) { - pid_t pid = getpid(); + pid_t pid = nxsched_getpid(); return (void *)((uintptr_t)pid); } @@ -4961,7 +4961,7 @@ int esp_wifi_notify_subscribe(pid_t pid, struct sigevent *event) { if (pid == 0) { - pid = getpid(); + pid = nxsched_getpid(); wlinfo("Actual PID=%d\n", pid); } diff --git a/arch/sim/src/sim/sim_heap.c b/arch/sim/src/sim/sim_heap.c index d233fdded4..c897ac86bb 100644 --- a/arch/sim/src/sim/sim_heap.c +++ b/arch/sim/src/sim/sim_heap.c @@ -217,10 +217,10 @@ void mm_free(struct mm_heap_s *heap, void *mem) else #endif - if (gettid() < 0) + if (nxsched_gettid() < 0) { - /* gettid() return -ESRCH, means we are in situations - * during context switching(See gettid's comment). + /* nxsched_gettid() return -ESRCH, means we are in situations + * during context switching(See nxsched_gettid's comment). * Then add to the delay list. */ diff --git a/arch/xtensa/src/esp32/esp32_wifi_adapter.c b/arch/xtensa/src/esp32/esp32_wifi_adapter.c index 96220b6ec5..f003863f8e 100644 --- a/arch/xtensa/src/esp32/esp32_wifi_adapter.c +++ b/arch/xtensa/src/esp32/esp32_wifi_adapter.c @@ -2025,7 +2025,7 @@ static int32_t esp_task_ms_to_tick(uint32_t ms) static void *esp_task_get_current_task(void) { - pid_t pid = getpid(); + pid_t pid = nxsched_getpid(); return (void *)((uintptr_t)pid); } @@ -4680,7 +4680,7 @@ int esp_wifi_notify_subscribe(pid_t pid, struct sigevent *event) { if (pid == 0) { - pid = getpid(); + pid = nxsched_getpid(); wlinfo("Actual PID=%d\n", pid); } diff --git a/drivers/input/ajoystick.c b/drivers/input/ajoystick.c index 78fc1feafe..ae078f511e 100644 --- a/drivers/input/ajoystick.c +++ b/drivers/input/ajoystick.c @@ -557,7 +557,7 @@ static int ajoy_ioctl(FAR struct file *filep, int cmd, unsigned long arg) opriv->ao_notify.an_press = notify->an_press; opriv->ao_notify.an_release = notify->an_release; opriv->ao_notify.an_event = notify->an_event; - opriv->ao_pid = getpid(); + opriv->ao_pid = nxsched_getpid(); /* Enable/disable interrupt handling */ diff --git a/drivers/input/button_upper.c b/drivers/input/button_upper.c index ebdf134f9e..d137211f59 100644 --- a/drivers/input/button_upper.c +++ b/drivers/input/button_upper.c @@ -607,7 +607,7 @@ static int btn_ioctl(FAR struct file *filep, int cmd, unsigned long arg) opriv->bo_notify.bn_press = notify->bn_press; opriv->bo_notify.bn_release = notify->bn_release; opriv->bo_notify.bn_event = notify->bn_event; - opriv->bo_pid = getpid(); + opriv->bo_pid = nxsched_getpid(); /* Enable/disable interrupt handling */ diff --git a/drivers/input/djoystick.c b/drivers/input/djoystick.c index fcff04fb6c..39b48a1686 100644 --- a/drivers/input/djoystick.c +++ b/drivers/input/djoystick.c @@ -553,7 +553,7 @@ static int djoy_ioctl(FAR struct file *filep, int cmd, unsigned long arg) opriv->do_notify.dn_press = notify->dn_press; opriv->do_notify.dn_release = notify->dn_release; opriv->do_notify.dn_event = notify->dn_event; - opriv->do_pid = getpid(); + opriv->do_pid = nxsched_getpid(); /* Enable/disable interrupt handling */ diff --git a/drivers/ioexpander/gpio.c b/drivers/ioexpander/gpio.c index 260e554924..7d6547d86f 100644 --- a/drivers/ioexpander/gpio.c +++ b/drivers/ioexpander/gpio.c @@ -350,7 +350,7 @@ static int gpio_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case GPIOC_REGISTER: if (arg && dev->gp_pintype >= GPIO_INTERRUPT_PIN) { - pid = getpid(); + pid = nxsched_getpid(); flags = spin_lock_irqsave(NULL); for (i = 0; i < CONFIG_DEV_GPIO_NSIGNALS; i++) { @@ -402,7 +402,7 @@ static int gpio_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case GPIOC_UNREGISTER: if (dev->gp_pintype >= GPIO_INTERRUPT_PIN) { - pid = getpid(); + pid = nxsched_getpid(); flags = spin_lock_irqsave(NULL); for (i = 0; i < CONFIG_DEV_GPIO_NSIGNALS; i++) { diff --git a/drivers/net/phy_notify.c b/drivers/net/phy_notify.c index f7538a75f5..2965589968 100644 --- a/drivers/net/phy_notify.c +++ b/drivers/net/phy_notify.c @@ -275,7 +275,7 @@ int phy_notify_subscribe(FAR const char *intf, pid_t pid, if (pid == 0) { - pid = getpid(); + pid = nxsched_getpid(); phyinfo("Actual PID=%d\n", pid); } diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c index 5d913da60a..e9240216e9 100644 --- a/drivers/rptun/rptun.c +++ b/drivers/rptun/rptun.c @@ -255,7 +255,7 @@ static void rptun_wakeup_rx(FAR struct rptun_priv_s *priv) static void rptun_in_recursive(int tid, FAR void *arg) { - *((FAR bool *)arg) = (gettid() == tid); + *((FAR bool *)arg) = (nxsched_gettid() == tid); } static bool rptun_is_recursive(FAR struct rptun_priv_s *priv) @@ -271,7 +271,7 @@ static int rptun_thread(int argc, FAR char *argv[]) FAR struct rptun_priv_s *priv; priv = (FAR struct rptun_priv_s *)((uintptr_t)strtoul(argv[2], NULL, 0)); - priv->tid = gettid(); + priv->tid = nxsched_gettid(); while (1) { @@ -295,7 +295,7 @@ static void rptun_wakeup_rx(FAR struct rptun_priv_s *priv) static bool rptun_is_recursive(FAR struct rptun_priv_s *priv) { - return gettid() == priv->tid; + return nxsched_gettid() == priv->tid; } #endif diff --git a/drivers/sensors/zerocross.c b/drivers/sensors/zerocross.c index 6ff67b670c..04640ee552 100644 --- a/drivers/sensors/zerocross.c +++ b/drivers/sensors/zerocross.c @@ -424,7 +424,7 @@ static int zc_ioctl(FAR struct file *filep, int cmd, unsigned long arg) /* Save the notification events */ opriv->do_event = *event; - opriv->do_pid = getpid(); + opriv->do_pid = nxsched_getpid(); /* Enable/disable interrupt handling */ diff --git a/drivers/syslog/vsyslog.c b/drivers/syslog/vsyslog.c index fb380e0840..b5bac0d227 100644 --- a/drivers/syslog/vsyslog.c +++ b/drivers/syslog/vsyslog.c @@ -83,7 +83,7 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) struct lib_syslogstream_s stream; int ret; #if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_SYSLOG_PROCESS_NAME) - FAR struct tcb_s *tcb = nxsched_get_tcb(gettid()); + FAR struct tcb_s *tcb = nxsched_get_tcb(nxsched_gettid()); #endif #ifdef CONFIG_SYSLOG_TIMESTAMP struct timespec ts; @@ -218,7 +218,7 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) #if defined(CONFIG_SYSLOG_PROCESSID) /* Prepend the Thread ID */ - , (int)gettid() + , (int)nxsched_gettid() #endif #if defined(CONFIG_SYSLOG_COLOR_OUTPUT) diff --git a/drivers/timers/oneshot.c b/drivers/timers/oneshot.c index 2a0f4b25ae..3c47d771ca 100644 --- a/drivers/timers/oneshot.c +++ b/drivers/timers/oneshot.c @@ -209,7 +209,7 @@ static int oneshot_ioctl(FAR struct file *filep, int cmd, unsigned long arg) pid = start->pid; if (pid == 0) { - pid = getpid(); + pid = nxsched_getpid(); } priv->od_pid = pid; diff --git a/drivers/timers/rtc.c b/drivers/timers/rtc.c index 14abf542ab..2f71afa299 100644 --- a/drivers/timers/rtc.c +++ b/drivers/timers/rtc.c @@ -470,7 +470,7 @@ static int rtc_ioctl(FAR struct file *filep, int cmd, unsigned long arg) pid = alarminfo->pid; if (pid == 0) { - pid = getpid(); + pid = nxsched_getpid(); } /* Save the signal info to be used to notify the caller when the @@ -541,7 +541,7 @@ static int rtc_ioctl(FAR struct file *filep, int cmd, unsigned long arg) pid = alarminfo->pid; if (pid == 0) { - pid = getpid(); + pid = nxsched_getpid(); } /* Save the signal info to be used to notify the caller when the @@ -675,7 +675,7 @@ static int rtc_ioctl(FAR struct file *filep, int cmd, unsigned long arg) pid = alarminfo->pid; if (pid == 0) { - pid = getpid(); + pid = nxsched_getpid(); } /* Save the signal info to be used to notify the caller when the diff --git a/drivers/wireless/ieee802154/xbee/xbee_netdev.c b/drivers/wireless/ieee802154/xbee/xbee_netdev.c index 2105b63187..b6106d0c5f 100644 --- a/drivers/wireless/ieee802154/xbee/xbee_netdev.c +++ b/drivers/wireless/ieee802154/xbee/xbee_netdev.c @@ -939,7 +939,7 @@ static int xbeenet_ioctl(FAR struct net_driver_s *dev, int cmd, /* Save the notification events */ priv->xd_notify_event = netmac->u.event; - priv->xd_notify_pid = getpid(); + priv->xd_notify_pid = nxsched_getpid(); priv->xd_notify_registered = true; ret = OK; } diff --git a/fs/aio/aioc_contain.c b/fs/aio/aioc_contain.c index fee268d444..d0a420dc60 100644 --- a/fs/aio/aioc_contain.c +++ b/fs/aio/aioc_contain.c @@ -89,7 +89,7 @@ FAR struct aio_container_s *aio_contain(FAR struct aiocb *aiocbp) memset(aioc, 0, sizeof(struct aio_container_s)); aioc->aioc_aiocbp = aiocbp; aioc->aioc_filep = filep; - aioc->aioc_pid = getpid(); + aioc->aioc_pid = nxsched_getpid(); #ifdef CONFIG_PRIORITY_INHERITANCE DEBUGVERIFY(nxsched_get_param (aioc->aioc_pid, ¶m)); diff --git a/fs/mount/fs_automount.c b/fs/mount/fs_automount.c index 0f22f46cc4..997c8e1a9e 100644 --- a/fs/mount/fs_automount.c +++ b/fs/mount/fs_automount.c @@ -358,7 +358,7 @@ static int automount_ioctl(FAR struct file *filep, int cmd, opriv->ao_notify.an_mount = notify->an_mount; opriv->ao_notify.an_umount = notify->an_umount; opriv->ao_notify.an_event = notify->an_event; - opriv->ao_pid = getpid(); + opriv->ao_pid = nxsched_getpid(); ret = OK; } } diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 16c4ccceb9..99de8b7002 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -1484,7 +1484,7 @@ static int proc_open(FAR struct file *filep, FAR const char *relpath, if (strncmp(relpath, "self", 4) == 0) { - tmp = gettid(); /* Get the TID of the calling task */ + tmp = nxsched_gettid(); /* Get the TID of the calling task */ ptr = (FAR char *)relpath + 4; /* Discard const */ } else @@ -1792,7 +1792,7 @@ static int proc_opendir(FAR const char *relpath, if (strncmp(relpath, "self", 4) == 0) { - tmp = gettid(); /* Get the TID of the calling task */ + tmp = nxsched_gettid(); /* Get the TID of the calling task */ ptr = (FAR char *)relpath + 4; /* Discard const */ } else @@ -2032,7 +2032,7 @@ static int proc_stat(const char *relpath, struct stat *buf) if (strncmp(relpath, "self", 4) == 0) { - tmp = gettid(); /* Get the TID of the calling task */ + tmp = nxsched_gettid(); /* Get the TID of the calling task */ ptr = (FAR char *)relpath + 4; /* Discard const */ } else diff --git a/include/execinfo.h b/include/execinfo.h index 30e56cdc7b..5c8dbfe8f1 100644 --- a/include/execinfo.h +++ b/include/execinfo.h @@ -38,8 +38,9 @@ * ARRAY and return the exact number of values stored. */ -# define backtrace(buffer, size) sched_backtrace(gettid(), buffer, size, 0) -# define dump_stack() sched_dumpstack(gettid()) +# define backtrace(buffer, size) sched_backtrace(_SCHED_GETTID(), \ + buffer, size, 0) +# define dump_stack() sched_dumpstack(_SCHED_GETTID()) #else # define backtrace(buffer, size) 0 diff --git a/include/threads.h b/include/threads.h index 712fd1b7e2..2449dc62e3 100644 --- a/include/threads.h +++ b/include/threads.h @@ -120,7 +120,7 @@ typedef CODE void (*tss_dtor_t)(FAR void *); * thrd_t thrd_current(void); */ -#define thrd_current() ((thrd_t)gettid()) +#define thrd_current() ((thrd_t)_SCHED_GETTID()) /* thrd_sleep: suspends execution of the calling thread for the given * period of time diff --git a/libs/libc/aio/lio_listio.c b/libs/libc/aio/lio_listio.c index 35a8d7a988..ae1b2f4d13 100644 --- a/libs/libc/aio/lio_listio.c +++ b/libs/libc/aio/lio_listio.c @@ -32,6 +32,7 @@ #include #include +#include #include "libc.h" #include "aio/aio.h" @@ -234,7 +235,7 @@ static int lio_sigsetup(FAR struct aiocb * const *list, int nent, sighand->list = list; sighand->sig = *sig; sighand->nent = nent; - sighand->pid = getpid(); + sighand->pid = _SCHED_GETPID(); /* Save this structure as the private data attached to each aiocb */ @@ -664,7 +665,7 @@ int lio_listio(int mode, FAR struct aiocb * const list[], int nent, } else { - status = nxsig_notification(getpid(), sig, + status = nxsig_notification(_SCHED_GETPID(), sig, SI_ASYNCIO, &aiocbp->aio_sigwork); if (status < 0 && ret == OK) { diff --git a/libs/libc/misc/lib_err.c b/libs/libc/misc/lib_err.c index 3134496b17..7fc8497bd2 100644 --- a/libs/libc/misc/lib_err.c +++ b/libs/libc/misc/lib_err.c @@ -27,6 +27,8 @@ #include #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -66,9 +68,10 @@ void vwarn(FAR const char *fmt, va_list ap) #endif #ifdef CONFIG_FILE_STREAM - fprintf(stderr, "%d: %pV: %s\n", gettid(), &vaf, strerror(error)); + fprintf(stderr, "%d: %pV: %s\n", _SCHED_GETTID(), &vaf, strerror(error)); #else - dprintf(STDERR_FILENO, "%d: %pV: %s\n", gettid(), &vaf, strerror(error)); + dprintf(STDERR_FILENO, "%d: %pV: %s\n", _SCHED_GETTID(), + &vaf, strerror(error)); #endif #ifdef va_copy @@ -97,9 +100,9 @@ void vwarnx(FAR const char *fmt, va_list ap) #endif #ifdef CONFIG_FILE_STREAM - fprintf(stderr, "%d: %pV\n", gettid(), &vaf); + fprintf(stderr, "%d: %pV\n", _SCHED_GETTID(), &vaf); #else - dprintf(STDERR_FILENO, "%d: %pV\n", gettid(), &vaf); + dprintf(STDERR_FILENO, "%d: %pV\n", _SCHED_GETTID(), &vaf); #endif #ifdef va_copy diff --git a/libs/libc/sched/sched_backtrace.c b/libs/libc/sched/sched_backtrace.c index 2c57eaf7f1..ab0fb86a1b 100644 --- a/libs/libc/sched/sched_backtrace.c +++ b/libs/libc/sched/sched_backtrace.c @@ -31,6 +31,8 @@ #include #include +#include + /**************************************************************************** * Private Data Types ****************************************************************************/ @@ -110,7 +112,7 @@ int sched_backtrace(pid_t tid, FAR void **buffer, int size, int skip) { struct trace_arg arg; - if (tid != gettid()) + if (tid != _SCHED_GETTID()) { return 0; } diff --git a/libs/libc/signal/sig_raise.c b/libs/libc/signal/sig_raise.c index 9359aea02a..17bbbcc02b 100644 --- a/libs/libc/signal/sig_raise.c +++ b/libs/libc/signal/sig_raise.c @@ -25,6 +25,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -41,5 +43,5 @@ int raise(int signo) { - return tkill(gettid(), signo); + return tkill(_SCHED_GETTID(), signo); } diff --git a/libs/libc/unistd/lib_getpriority.c b/libs/libc/unistd/lib_getpriority.c index a9fead58e7..9f3f4a15e5 100644 --- a/libs/libc/unistd/lib_getpriority.c +++ b/libs/libc/unistd/lib_getpriority.c @@ -29,6 +29,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -73,7 +75,7 @@ int getpriority(int which, id_t who) if (who == 0) { - who = gettid(); + who = _SCHED_GETTID(); } ret = sched_getparam(who, ¶m); diff --git a/libs/libc/unistd/lib_setpriority.c b/libs/libc/unistd/lib_setpriority.c index 968ff78118..501973d0b1 100644 --- a/libs/libc/unistd/lib_setpriority.c +++ b/libs/libc/unistd/lib_setpriority.c @@ -28,6 +28,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -62,7 +64,7 @@ int setpriority(int which, id_t who, int value) if (who == 0) { - who = gettid(); + who = _SCHED_GETTID(); } ret = sched_getparam(who, ¶m); diff --git a/mm/mempool/mempool.c b/mm/mempool/mempool.c index 7a1ea154ff..22641fe28f 100644 --- a/mm/mempool/mempool.c +++ b/mm/mempool/mempool.c @@ -102,7 +102,7 @@ static inline void mempool_add_backtrace(FAR struct mempool_s *pool, FAR struct mempool_backtrace_s *buf) { list_add_head(&pool->alist, &buf->node); - buf->pid = gettid(); + buf->pid = _SCHED_GETTID(); # if CONFIG_MM_BACKTRACE > 0 if (pool->procfs.backtrace) { diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h index 4892f6f686..05c3db4bf8 100644 --- a/mm/mm_heap/mm.h +++ b/mm/mm_heap/mm.h @@ -75,7 +75,7 @@ do \ { \ FAR struct mm_allocnode_s *tmp = (FAR struct mm_allocnode_s *)(ptr); \ - tmp->pid = gettid(); \ + tmp->pid = _SCHED_GETTID(); \ } \ while (0) #elif CONFIG_MM_BACKTRACE > 0 @@ -84,7 +84,7 @@ { \ FAR struct mm_allocnode_s *tmp = (FAR struct mm_allocnode_s *)(ptr); \ FAR struct tcb_s *tcb; \ - tmp->pid = gettid(); \ + tmp->pid = _SCHED_GETTID(); \ tcb = nxsched_get_tcb(tmp->pid); \ if ((heap)->mm_procfs.backtrace || (tcb && tcb->flags & TCB_FLAG_HEAP_DUMP)) \ { \ diff --git a/mm/mm_heap/mm_lock.c b/mm/mm_heap/mm_lock.c index b5b45a4f81..1207e198d9 100644 --- a/mm/mm_heap/mm_lock.c +++ b/mm/mm_heap/mm_lock.c @@ -77,17 +77,17 @@ int mm_lock(FAR struct mm_heap_s *heap) else #endif - /* gettid() returns the task ID of the task at the head of the ready-to- - * run task list. mm_lock() may be called during context + /* _SCHED_GETTID() returns the task ID of the task at the head of the + * ready-to-run task list. mm_lock() may be called during context * switches. There are certain situations during context switching when * the OS data structures are in flux and then can't be freed immediately * (e.g. the running thread stack). * - * This is handled by gettid() to return the special value -ESRCH to - * indicate this special situation. + * This is handled by _SCHED_GETTID() to return the special value -ESRCH + * to indicate this special situation. */ - if (gettid() < 0) + if (_SCHED_GETTID() < 0) { return -ESRCH; } diff --git a/mm/shm/shmctl.c b/mm/shm/shmctl.c index 0bb14b7da2..8f12888353 100644 --- a/mm/shm/shmctl.c +++ b/mm/shm/shmctl.c @@ -33,6 +33,7 @@ #include #include +#include #include #include "shm/shm.h" @@ -184,7 +185,7 @@ int shmctl(int shmid, int cmd, struct shmid_ds *buf) /* Save the process ID of the last operation */ region = &g_shminfo.si_region[shmid]; - region->sr_ds.shm_lpid = getpid(); + region->sr_ds.shm_lpid = _SCHED_GETPID(); /* Save the time of the last shmctl() */ diff --git a/mm/shm/shmget.c b/mm/shm/shmget.c index c8b71047b2..0623e0c2a3 100644 --- a/mm/shm/shmget.c +++ b/mm/shm/shmget.c @@ -32,6 +32,7 @@ #include #include +#include #include "shm/shm.h" @@ -268,7 +269,7 @@ static int shm_create(key_t key, size_t size, int shmflg) /* Save the process ID of the creator */ region = &g_shminfo.si_region[shmid]; - region->sr_ds.shm_cpid = getpid(); + region->sr_ds.shm_cpid = _SCHED_GETPID(); /* Return the shared memory ID */ diff --git a/mm/tlsf/mm_tlsf.c b/mm/tlsf/mm_tlsf.c index c7476a1c77..7954d5a10c 100644 --- a/mm/tlsf/mm_tlsf.c +++ b/mm/tlsf/mm_tlsf.c @@ -144,7 +144,7 @@ static void memdump_backtrace(FAR struct mm_heap_s *heap, FAR struct tcb_s *tcb; # endif - dump->pid = getpid(); + dump->pid = _SCHED_GETPID(); # if CONFIG_MM_BACKTRACE > 0 tcb = nxsched_get_tcb(dump->pid); if (heap->mm_procfs.backtrace || @@ -319,17 +319,17 @@ static int mm_lock(FAR struct mm_heap_s *heap) else #endif - /* gettid() returns the task ID of the task at the head of the ready-to- - * run task list. mm_lock() may be called during context + /* _SCHED_GETTID() returns the task ID of the task at the head of the + * ready-to-run task list. mm_lock() may be called during context * switches. There are certain situations during context switching when * the OS data structures are in flux and then can't be freed immediately * (e.g. the running thread stack). * - * This is handled by gettid() to return the special value -ESRCH to - * indicate this special situation. + * This is handled by _SCHED_GETTID() to return the special value + * -ESRCH to indicate this special situation. */ - if (gettid() < 0) + if (_SCHED_GETTID() < 0) { return -ESRCH; } diff --git a/net/local/local_conn.c b/net/local/local_conn.c index efaac03a7d..142d9a7323 100644 --- a/net/local/local_conn.c +++ b/net/local/local_conn.c @@ -131,7 +131,7 @@ FAR struct local_conn_s *local_alloc(void) nxmutex_init(&conn->lc_sendlock); #ifdef CONFIG_NET_LOCAL_SCM - conn->lc_cred.pid = getpid(); + conn->lc_cred.pid = nxsched_getpid(); conn->lc_cred.uid = getuid(); conn->lc_cred.gid = getgid(); #endif diff --git a/net/netlink/netlink_sockif.c b/net/netlink/netlink_sockif.c index 88b3648906..88dd30a9af 100644 --- a/net/netlink/netlink_sockif.c +++ b/net/netlink/netlink_sockif.c @@ -262,7 +262,7 @@ static int netlink_bind(FAR struct socket *psock, nladdr = (FAR struct sockaddr_nl *)addr; conn = (FAR struct netlink_conn_s *)psock->s_conn; - conn->pid = nladdr->nl_pid ? nladdr->nl_pid : gettid(); + conn->pid = nladdr->nl_pid ? nladdr->nl_pid : nxsched_gettid(); conn->groups = nladdr->nl_groups; return OK; diff --git a/net/tcp/tcp_sendfile.c b/net/tcp/tcp_sendfile.c index b572fbd23d..cce1bebbec 100644 --- a/net/tcp/tcp_sendfile.c +++ b/net/tcp/tcp_sendfile.c @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -367,7 +368,7 @@ static uint16_t sendfile_eventhandler(FAR struct net_driver_s *dev, pstate->snd_sent += sndlen; ninfo("pid: %d SEND: acked=%" PRId32 " sent=%zd flen=%zu\n", - getpid(), + nxsched_getpid(), pstate->snd_acked, pstate->snd_sent, pstate->snd_flen); } else diff --git a/sched/mqueue/mq_timedreceive.c b/sched/mqueue/mq_timedreceive.c index ed372b3c35..f8b3153a7d 100644 --- a/sched/mqueue/mq_timedreceive.c +++ b/sched/mqueue/mq_timedreceive.c @@ -202,7 +202,8 @@ ssize_t file_mq_timedreceive(FAR struct file *mq, FAR char *msg, /* Start the watchdog */ - wd_start(&rtcb->waitdog, ticks, nxmq_rcvtimeout, gettid()); + wd_start(&rtcb->waitdog, ticks, + nxmq_rcvtimeout, nxsched_gettid()); } /* Get the message from the message queue */ diff --git a/sched/mqueue/mq_timedsend.c b/sched/mqueue/mq_timedsend.c index 1858808a72..28422425a8 100644 --- a/sched/mqueue/mq_timedsend.c +++ b/sched/mqueue/mq_timedsend.c @@ -245,7 +245,7 @@ int file_mq_timedsend(FAR struct file *mq, FAR const char *msg, /* Start the watchdog and begin the wait for MQ not full */ - wd_start(&rtcb->waitdog, ticks, nxmq_sndtimeout, gettid()); + wd_start(&rtcb->waitdog, ticks, nxmq_sndtimeout, nxsched_gettid()); /* And wait for the message queue to be non-empty */ diff --git a/sched/pthread/pthread_condclockwait.c b/sched/pthread/pthread_condclockwait.c index 0619770399..f91097b1a3 100644 --- a/sched/pthread/pthread_condclockwait.c +++ b/sched/pthread/pthread_condclockwait.c @@ -74,7 +74,7 @@ int pthread_cond_clockwait(FAR pthread_cond_t *cond, FAR const struct timespec *abstime) { irqstate_t flags; - int mypid = gettid(); + int mypid = nxsched_gettid(); int ret = OK; int status; diff --git a/sched/pthread/pthread_condwait.c b/sched/pthread/pthread_condwait.c index 9252ac0bd8..09cf75844a 100644 --- a/sched/pthread/pthread_condwait.c +++ b/sched/pthread/pthread_condwait.c @@ -74,7 +74,7 @@ int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex) /* Make sure that the caller holds the mutex */ - else if (mutex->pid != gettid()) + else if (mutex->pid != nxsched_gettid()) { ret = EPERM; } @@ -140,7 +140,7 @@ int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex) { /* Yes.. Then initialize it properly */ - mutex->pid = gettid(); + mutex->pid = nxsched_gettid(); #ifndef CONFIG_PTHREAD_MUTEX_UNSAFE mutex->flags = mflags; #endif diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c index 783ca52797..dd3b072c0c 100644 --- a/sched/pthread/pthread_exit.c +++ b/sched/pthread/pthread_exit.c @@ -79,7 +79,7 @@ void nx_pthread_exit(FAR void *exit_value) /* Complete pending join operations */ - status = pthread_completejoin(gettid(), exit_value); + status = pthread_completejoin(nxsched_gettid(), exit_value); if (status != OK) { /* Assume that the join completion failured because this diff --git a/sched/pthread/pthread_mutextimedlock.c b/sched/pthread/pthread_mutextimedlock.c index 73ba069920..e8c0195273 100644 --- a/sched/pthread/pthread_mutextimedlock.c +++ b/sched/pthread/pthread_mutextimedlock.c @@ -78,7 +78,7 @@ int pthread_mutex_timedlock(FAR pthread_mutex_t *mutex, FAR const struct timespec *abs_timeout) { - pid_t mypid = gettid(); + pid_t mypid = nxsched_gettid(); int ret = EINVAL; sinfo("mutex=%p\n", mutex); diff --git a/sched/pthread/pthread_mutextrylock.c b/sched/pthread/pthread_mutextrylock.c index d433689f75..ace0656843 100644 --- a/sched/pthread/pthread_mutextrylock.c +++ b/sched/pthread/pthread_mutextrylock.c @@ -76,7 +76,7 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex) if (mutex != NULL) { - pid_t mypid = gettid(); + pid_t mypid = nxsched_gettid(); /* Make sure the semaphore is stable while we make the following * checks. This all needs to be one atomic action. diff --git a/sched/pthread/pthread_mutexunlock.c b/sched/pthread/pthread_mutexunlock.c index 97f7a42c0f..cef1487ef8 100644 --- a/sched/pthread/pthread_mutexunlock.c +++ b/sched/pthread/pthread_mutexunlock.c @@ -142,7 +142,7 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex) * thread owns the semaphore. */ - if (mutex->pid != gettid()) + if (mutex->pid != nxsched_gettid()) #elif defined(CONFIG_PTHREAD_MUTEX_UNSAFE) && defined(CONFIG_PTHREAD_MUTEX_TYPES) /* If mutex types are not supported, then all mutexes are NORMAL (or @@ -150,7 +150,8 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex) * non-robust NORMAL mutex type. */ - if (mutex->type != PTHREAD_MUTEX_NORMAL && mutex->pid != gettid()) + if (mutex->type != PTHREAD_MUTEX_NORMAL && + mutex->pid != nxsched_gettid()) #else /* CONFIG_PTHREAD_MUTEX_BOTH */ /* Skip the error check if this is a non-robust NORMAL mutex */ @@ -164,7 +165,7 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex) * the EPERM error? */ - if (errcheck && mutex->pid != gettid()) + if (errcheck && mutex->pid != nxsched_gettid()) #endif { /* No... return an EPERM error. diff --git a/sched/sched/sched_setscheduler.c b/sched/sched/sched_setscheduler.c index 77f73c1c67..b20433dcca 100644 --- a/sched/sched/sched_setscheduler.c +++ b/sched/sched/sched_setscheduler.c @@ -109,7 +109,7 @@ int nxsched_set_scheduler(pid_t pid, int policy, if (pid == 0) { - pid = gettid(); + pid = nxsched_gettid(); } /* Verify that the pid corresponds to a real task */ diff --git a/sched/semaphore/sem_clockwait.c b/sched/semaphore/sem_clockwait.c index 3f11f31841..913014b0a6 100644 --- a/sched/semaphore/sem_clockwait.c +++ b/sched/semaphore/sem_clockwait.c @@ -159,7 +159,7 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid, /* Start the watchdog */ - wd_start(&rtcb->waitdog, ticks, nxsem_timeout, gettid()); + wd_start(&rtcb->waitdog, ticks, nxsem_timeout, nxsched_gettid()); /* Now perform the blocking wait. If nxsem_wait() fails, the * negated errno value will be returned below. diff --git a/sched/semaphore/sem_tickwait.c b/sched/semaphore/sem_tickwait.c index 0715caf8ae..c5cc43c1ce 100644 --- a/sched/semaphore/sem_tickwait.c +++ b/sched/semaphore/sem_tickwait.c @@ -105,7 +105,7 @@ int nxsem_tickwait(FAR sem_t *sem, uint32_t delay) /* Start the watchdog with interrupts still disabled */ - wd_start(&rtcb->waitdog, delay, nxsem_timeout, gettid()); + wd_start(&rtcb->waitdog, delay, nxsem_timeout, nxsched_gettid()); /* Now perform the blocking wait */ diff --git a/sched/task/task_exithook.c b/sched/task/task_exithook.c index e0a5063d5d..375487f76e 100644 --- a/sched/task/task_exithook.c +++ b/sched/task/task_exithook.c @@ -66,7 +66,7 @@ static inline void nxtask_exitstatus(FAR struct task_group_s *group, { /* No.. Find the exit status entry for this task in the parent TCB */ - child = group_find_child(group, gettid()); + child = group_find_child(group, nxsched_gettid()); if (child) { /* Save the exit status.. For the case of HAVE_GROUP_MEMBERS, @@ -105,7 +105,7 @@ static inline void nxtask_groupexit(FAR struct task_group_s *group) { /* No.. Find the exit status entry for this task in the parent TCB */ - child = group_find_child(group, gettid()); + child = group_find_child(group, nxsched_gettid()); if (child) { /* Mark that all members of the child task group has exited */ diff --git a/sched/timer/timer_create.c b/sched/timer/timer_create.c index a499b44d92..e9bd4dcf4b 100644 --- a/sched/timer/timer_create.c +++ b/sched/timer/timer_create.c @@ -178,7 +178,7 @@ int timer_create(clockid_t clockid, FAR struct sigevent *evp, ret->pt_clock = clockid; ret->pt_crefs = 1; - ret->pt_owner = getpid(); + ret->pt_owner = nxsched_getpid(); ret->pt_delay = 0; /* Was a struct sigevent provided? */ diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 78322dbc31..5c0f405e56 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -583,7 +583,7 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, /* Save the notification events */ dev->md_notify_event = macarg->event; - dev->md_notify_pid = getpid(); + dev->md_notify_pid = nxsched_getpid(); dev->md_notify_registered = true; ret = OK; diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index 92031de31c..494ba49ad8 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -939,7 +939,7 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, /* Save the notification events */ priv->md_notify_event = netmac->u.event; - priv->md_notify_pid = getpid(); + priv->md_notify_pid = nxsched_getpid(); priv->md_notify_registered = true; ret = OK; }