Commit Graph

39 Commits

Author SHA1 Message Date
Alin Jerpelea eb9030c891 sched: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-09-12 01:10:14 +08:00
Yanfeng Liu 7ec304e6a8 pthread/join: catch null pexit_value case
This adds handling for null pointer in errout route as it crashes my
ostest sometimes.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-05-10 19:42:13 +08:00
chao an 09e5dca965 sched/pthread: detached thread should destroy the join info
In order to ensure the detached thread obtain the correct return
value from pthread_join()/pthread_cancel(), the detached thread
will create joininfo to save the detached status after thread
destroyed.  If there are too many of detached threads in the
process group, the joininfo will consume too much memory.
This is not friendly to embedded MCU devices.
This commit keep the semantics as #11898 was introduced,
will no longer save joininfo for detached threads to avoid wasting memory.

Signed-off-by: chao an <anchao@lixiang.com>
2024-04-09 13:46:51 +08:00
chao an df30a1f8d3 sched/pthread/join: refactor pthread join to support join task
1. add support to join main task

| static pthread_t self;
|
| static void *join_task(void *arg)
| {
|   int ret;
|   ret = pthread_join(self, NULL);          <---  /* Fix Task could not be joined */
|   return NULL;
| }
|
| int main(int argc, char *argv[])
| {
|   pthread_t thread;
|
|   self = pthread_self();
|
|   pthread_create(&thread, NULL, join_task, NULL);
|   sleep(1);
|
|   pthread_exit(NULL);
|   return 0;
| }

2. Detach active thread will not alloc for additional join, just update the task flag.
3. Remove the return value waiting lock logic (data_sem),
   the return value will be stored in the waiting tcb.
4. Revise the return value of pthread_join(), consistent with linux
   e.g:
       Joining a detached and canceled thread should return EINVAL, not ESRCH

   https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_join.html

   [EINVAL]
      The value specified by thread does not refer to a joinable thread.

NOTE:

This PR will not increase stack usage, but struct tcb_s will increase 32 bytes.

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-13 18:06:56 +09:00
chao an be482cd830 sched/pthread: replace pthread_sem_give() to nxsem_post() to unify the post method
replace pthread_sem_give() to nxsem_post() to unify the post method

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-11 22:57:26 +08:00
Petro Karashchenko 3fe371f60f nuttx: replace getpid() with nxsched_getpid() in kernel code
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-07-07 17:39:39 -03:00
zhangyuan21 fc9f87824c sched/pthread: Return ESRCH when the task is in the process of exit.
Resolving the issue with the ltp_interfaces_pthread_join_6_2 test case.

In SMP mode, the pthread may still be in the process of exiting when
pthread_join returns, and calling pthread_join again at this time will
result in an error. The error code returned should be ESRCH.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-06-15 10:12:25 -03:00
zhangyuan21 a20bc77010 sched/pthread: change the wrong type cast
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-02-13 23:17:29 +08:00
zhangyuan21 9017f70561 sched/pthread: check pthread group after find joininfo
Need check tcb or group info after find joininfo,
otherwise the wrong value will be returned.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-02-12 16:47:28 +08:00
zhangyuan21 9fd30c7f63 sched/pthread: check pthread group and flags before join
Prevent users from using the wrong pid and causing system crash.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-01-18 11:57:40 +08:00
qinwei1 8021dfece6 sched/task/task_getpid: getpid should return process id not thread id
Summary:
   implement the right semantics:
1. getpid should return the main thread id
2. gettid should return the current thread id

Refer to:
 https://github.com/apache/incubator-nuttx/issues/2499
 https://github.com/apache/incubator-nuttx/pull/2518

Signed-off-by: qinwei1 <qinwei1@xiaomi.com>
2022-11-17 17:58:08 +08:00
anjiahao d1d46335df Replace nxsem API when used as a lock with nxmutex API
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-17 15:59:46 +09:00
Gustavo Henrique Nihei 1416afc6b6 sched: Remove "0x" prefix preceding "%p" specifier on format string
The "p" format specifier already prepends the pointer address with
"0x" when printing.

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2022-06-30 22:08:58 +03:00
Xiang Xiao 08002a0a38 sched: Replace pthread_sem_take with nxsem_wait_uninterruptible
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-14 20:47:34 +03:00
anjiahao 47304e7254 sched/pthread:need check pthread is DETACHED
pthread_join need check thread is DETACHED,
Whether to wait according to the result.And,
if a thread is DETACHED,it will not set a new
attr.
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-04-08 01:41:06 +08:00
Xiang Xiao 2e54df0f35 Don't include assert.h from public header file
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-03 08:36:03 -07:00
Masayuki Ishikawa f0bf2143f6 sched: pthread: Fix pthread_join() for SMP
Summary:
- I noticed 'pthread_rwlock test' in ostest sometimes stops
- This issue happened with spresense:wifi_smp (NCPUS=4) and sim:smp
- Finally, I found an issue in pthread_join()
- In pthread_join(), sched_lock() is used to avoid pre-emption
- However, this is not enough for SMP
- Because another CPU would continue the pthread and exit sequences
- So we need to protect it with a critical section

Impact:
- Affect SMP only

Testing:
- Tested with ostest with the following configurations
- spresnese:smp
- spresense:wifi_smp (NCPUS=2, NCPUS=4)
- sabre-6quad:smp (QEMU)
- esp32-core:smp (QEMU)
- maix-bit:smp (QEMU)
- sim:smp
- lc823450-xgevk:rndis

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-11-10 19:41:46 -08:00
Gregory Nutt 4b44b628ea Run nxstyle against all .c and .h files modified by this PR.
All complaints fixed except for those that were not possible to fix:

- Used of Mixed case identifier in ESP32 files.  These are references to Expressif ROM functions which are outside of the scope of NuttX.
2020-05-09 14:19:08 -03:00
Gregory Nutt a4218e2144 include/nuttx/sched.h: Make naming of all internal names consistent:
1. Add internal scheduler functions should begin with nxsched_, not sched_
2. Follow the consistent naming patter of https://cwiki.apache.org/confluence/display/NUTTX/Naming+of+OS+Internal+Functions
2020-05-09 14:19:08 -03:00
Xiang Xiao 6a3c2aded6 Fix wait loop and void cast (#24)
* Simplify EINTR/ECANCEL error handling

1. Add semaphore uninterruptible wait function
2 .Replace semaphore wait loop with a single uninterruptible wait
3. Replace all sem_xxx to nxsem_xxx

* Unify the void cast usage

1. Remove void cast for function because many place ignore the returned value witout cast
2. Replace void cast for variable with UNUSED macro
2020-01-02 10:54:43 -06:00
Leif Jakob 58e387fc6f Merged in leif_jakob/nuttx/pthread_mutex_timedlock (pull request #830)
support for pthread_mutex_timedlock

Approved-by: Gregory Nutt <gnutt@nuttx.org>
2019-02-24 20:04:24 +00:00
Gregory Nutt b54ffe858a Standardization of some function headers. 2018-03-13 09:52:27 -06:00
Gregory Nutt 7cf88d7dbd Make sure that labeling is used consistently in all function headers. 2018-02-01 10:00:02 -06:00
Gregory Nutt fca07be1df Squashed commit of the following:
Change all calls to mq_send() and mq_timedsend() in the OS to calls to nxmq_send() and nxmq_timedsend(), making appropriate changes for differences in return values.

    sched/mqueue:  Add internal function nxmq_send() and nxmq_timedsend() that are equivalent to mq_send() and mq_timedsend() except that they do not create cancellation points and do to not modify the errno variable.
2017-10-10 08:44:12 -06:00
Arjun Hary b274a97840 Miscellaneous fixes from astyle tool. 2017-08-14 17:19:27 -06:00
Gregory Nutt a8708424c2 pthread_trylock: Fixes a problem in pthread_trylock() noted by initialkjc@yahoo.com. When CONFIG_PTHREAD_MUTEX_UNSAFE=y, the special return value EAGAIN was not being detected due to differences in reporting of returned values. 2017-05-29 07:05:06 -06:00
Gregory Nutt 2c37d369ab pthread: Fix return value of pthread_give/takesemaphore(). Add option to pthread_takesemaphore to ignore EINTR or not. 2017-03-26 11:22:17 -06:00
Gregory Nutt b52e4e5ecd Move cancellation point definitions to their own header file. 2016-12-10 09:08:26 -06:00
Gregory Nutt bc3ca25cc7 Cancellation points: Close up some logic to eliminte some race conditions. 2016-12-10 08:36:58 -06:00
Gregory Nutt 7fce8022c6 Finishes all cancellation point logic 2016-12-09 16:50:34 -06:00
Gregory Nutt 18ce4ff57b sched/: Review and correct some stylistic inconsistencies 2016-08-07 08:25:30 -06:00
Gregory Nutt 13cac3b592 sched/: Change some *err() message to *info() messages if what was a *dbg() message does not indicate and error condition. 2016-06-11 16:42:42 -06:00
Gregory Nutt a1469a3e95 Add CONFIG_DEBUG_ERROR. Change names of *dbg() * *err() 2016-06-11 15:50:49 -06:00
Gregory Nutt 3994b094c5 Remove some empty C file section comments; Update some text in TODO file 2016-02-19 10:01:15 -06:00
Gregory Nutt 74db48202e sched/: Replace explict references to g_readytorun with indirect references via the this_task() macro 2016-02-06 17:44:41 -06:00
Gregory Nutt cb9e27c3b0 Standardize naming used for public data and function groupings 2015-10-02 16:30:35 -06:00
Gregory Nutt d798dd37a7 Replace os_internal.h with sched/sched.h in files that actually reference something in sched.h 2014-08-08 17:53:55 -06:00
Gregory Nutt 4ff17b3904 Move group logic from sched/ to sched/group 2014-08-08 14:06:42 -06:00
Gregory Nutt cb79407ced Move all pthread files from sched/ to sched/pthread 2014-08-08 12:55:02 -06:00