|
62 | 62 | #include <nuttx/lib/lib.h> |
63 | 63 |
|
64 | 64 | #include "fs_heap.h" |
| 65 | +#include "sched/sched.h" |
65 | 66 |
|
66 | 67 | #if !defined(CONFIG_SCHED_CPULOAD_NONE) || defined(CONFIG_SCHED_CRITMONITOR) |
67 | 68 | # include <nuttx/clock.h> |
@@ -1462,7 +1463,6 @@ static int proc_open(FAR struct file *filep, FAR const char *relpath, |
1462 | 1463 | { |
1463 | 1464 | FAR struct proc_file_s *procfile; |
1464 | 1465 | FAR const struct proc_node_s *node; |
1465 | | - FAR struct tcb_s *tcb; |
1466 | 1466 | FAR char *ptr; |
1467 | 1467 | unsigned long tmp; |
1468 | 1468 | pid_t pid; |
@@ -1508,9 +1508,7 @@ static int proc_open(FAR struct file *filep, FAR const char *relpath, |
1508 | 1508 | /* Now verify that a task with this task/thread ID exists */ |
1509 | 1509 |
|
1510 | 1510 | pid = (pid_t)tmp; |
1511 | | - |
1512 | | - tcb = nxsched_get_tcb(pid); |
1513 | | - if (tcb == NULL) |
| 1511 | + if (!nxsched_verify_pid(pid)) |
1514 | 1512 | { |
1515 | 1513 | ferr("ERROR: PID %d is no longer valid\n", pid); |
1516 | 1514 | return -ENOENT; |
@@ -1663,6 +1661,8 @@ static ssize_t proc_read(FAR struct file *filep, FAR char *buffer, |
1663 | 1661 |
|
1664 | 1662 | leave_critical_section(flags); |
1665 | 1663 |
|
| 1664 | + nxsched_put_tcb(tcb); |
| 1665 | + |
1666 | 1666 | /* Update the file offset */ |
1667 | 1667 |
|
1668 | 1668 | if (ret > 0) |
@@ -1714,6 +1714,7 @@ static ssize_t proc_write(FAR struct file *filep, FAR const char *buffer, |
1714 | 1714 | break; |
1715 | 1715 | } |
1716 | 1716 |
|
| 1717 | + nxsched_put_tcb(tcb); |
1717 | 1718 | return ret; |
1718 | 1719 | } |
1719 | 1720 |
|
@@ -1769,7 +1770,6 @@ static int proc_opendir(FAR const char *relpath, |
1769 | 1770 | { |
1770 | 1771 | FAR struct proc_dir_s *procdir; |
1771 | 1772 | FAR const struct proc_node_s *node; |
1772 | | - FAR struct tcb_s *tcb; |
1773 | 1773 | unsigned long tmp; |
1774 | 1774 | FAR char *ptr; |
1775 | 1775 | pid_t pid; |
@@ -1819,9 +1819,7 @@ static int proc_opendir(FAR const char *relpath, |
1819 | 1819 | /* Now verify that a task with this task/thread ID exists */ |
1820 | 1820 |
|
1821 | 1821 | pid = (pid_t)tmp; |
1822 | | - |
1823 | | - tcb = nxsched_get_tcb(pid); |
1824 | | - if (tcb == NULL) |
| 1822 | + if (!nxsched_verify_pid(pid)) |
1825 | 1823 | { |
1826 | 1824 | ferr("ERROR: PID %d is not valid\n", pid); |
1827 | 1825 | return -ENOENT; |
@@ -1911,7 +1909,6 @@ static int proc_readdir(FAR struct fs_dirent_s *dir, |
1911 | 1909 | { |
1912 | 1910 | FAR struct proc_dir_s *procdir; |
1913 | 1911 | FAR const struct proc_node_s *node = NULL; |
1914 | | - FAR struct tcb_s *tcb; |
1915 | 1912 | unsigned int index; |
1916 | 1913 | pid_t pid; |
1917 | 1914 | int ret; |
@@ -1939,9 +1936,7 @@ static int proc_readdir(FAR struct fs_dirent_s *dir, |
1939 | 1936 | /* Verify that the pid still refers to an active task/thread */ |
1940 | 1937 |
|
1941 | 1938 | pid = procdir->pid; |
1942 | | - |
1943 | | - tcb = nxsched_get_tcb(pid); |
1944 | | - if (tcb == NULL) |
| 1939 | + if (!nxsched_verify_pid(pid)) |
1945 | 1940 | { |
1946 | 1941 | ferr("ERROR: PID %d is no longer valid\n", pid); |
1947 | 1942 | return -ENOENT; |
@@ -2013,7 +2008,6 @@ static int proc_rewinddir(struct fs_dirent_s *dir) |
2013 | 2008 | static int proc_stat(const char *relpath, struct stat *buf) |
2014 | 2009 | { |
2015 | 2010 | FAR const struct proc_node_s *node; |
2016 | | - FAR struct tcb_s *tcb; |
2017 | 2011 | unsigned long tmp; |
2018 | 2012 | FAR char *ptr; |
2019 | 2013 | pid_t pid; |
@@ -2057,9 +2051,7 @@ static int proc_stat(const char *relpath, struct stat *buf) |
2057 | 2051 | /* Now verify that a task with this task/thread ID exists */ |
2058 | 2052 |
|
2059 | 2053 | pid = (pid_t)tmp; |
2060 | | - |
2061 | | - tcb = nxsched_get_tcb(pid); |
2062 | | - if (tcb == NULL) |
| 2054 | + if (!nxsched_verify_pid(pid)) |
2063 | 2055 | { |
2064 | 2056 | ferr("ERROR: PID %d is no longer valid\n", pid); |
2065 | 2057 | return -ENOENT; |
|
0 commit comments