From 794d3623353575476fe11f775d75d2b5714cc5e3 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Fri, 11 Oct 2024 14:49:59 +0800 Subject: [PATCH] sched/pthread: There is no need to use sched_[un]lock Signed-off-by: hujun5 --- sched/pthread/pthread_create.c | 4 ---- sched/pthread/pthread_mutex.c | 12 ------------ sched/pthread/pthread_mutexconsistent.c | 6 ------ sched/pthread/pthread_mutexdestroy.c | 8 -------- sched/pthread/pthread_mutextrylock.c | 8 -------- 5 files changed, 38 deletions(-) diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c index 5ca05f4648..e9ff4ef88c 100644 --- a/sched/pthread/pthread_create.c +++ b/sched/pthread/pthread_create.c @@ -442,8 +442,6 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread, #endif } - sched_lock(); - /* Return the thread information to the caller */ if (thread != NULL) @@ -455,8 +453,6 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread, nxtask_activate((FAR struct tcb_s *)ptcb); - sched_unlock(); - return OK; errout_with_tcb: diff --git a/sched/pthread/pthread_mutex.c b/sched/pthread/pthread_mutex.c index 79223d88a4..36eae29a08 100644 --- a/sched/pthread/pthread_mutex.c +++ b/sched/pthread/pthread_mutex.c @@ -150,10 +150,6 @@ int pthread_mutex_take(FAR struct pthread_mutex_s *mutex, DEBUGASSERT(mutex != NULL); if (mutex != NULL) { - /* Make sure that no unexpected context switches occur */ - - sched_lock(); - /* Error out if the mutex is already in an inconsistent state. */ if ((mutex->flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0) @@ -201,8 +197,6 @@ int pthread_mutex_take(FAR struct pthread_mutex_s *mutex, } } } - - sched_unlock(); } return ret; @@ -234,10 +228,6 @@ int pthread_mutex_trytake(FAR struct pthread_mutex_s *mutex) DEBUGASSERT(mutex != NULL); if (mutex != NULL) { - /* Make sure that no unexpected context switches occur */ - - sched_lock(); - /* Error out if the mutex is already in an inconsistent state. */ if ((mutex->flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0) @@ -269,8 +259,6 @@ int pthread_mutex_trytake(FAR struct pthread_mutex_s *mutex) pthread_mutex_add(mutex); } } - - sched_unlock(); } return ret; diff --git a/sched/pthread/pthread_mutexconsistent.c b/sched/pthread/pthread_mutexconsistent.c index 8e653b7ac0..f5b6d0f162 100644 --- a/sched/pthread/pthread_mutexconsistent.c +++ b/sched/pthread/pthread_mutexconsistent.c @@ -84,10 +84,6 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex) { pid_t pid; - /* Make sure the mutex is stable while we make the following checks. */ - - sched_lock(); - pid = mutex_get_holder(&mutex->mutex); /* Is the mutex available? */ @@ -133,8 +129,6 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex) mutex->flags &= _PTHREAD_MFLAGS_ROBUST; ret = OK; } - - sched_unlock(); } sinfo("Returning %d\n", ret); diff --git a/sched/pthread/pthread_mutexdestroy.c b/sched/pthread/pthread_mutexdestroy.c index bd0841f118..a5c74018e1 100644 --- a/sched/pthread/pthread_mutexdestroy.c +++ b/sched/pthread/pthread_mutexdestroy.c @@ -69,12 +69,6 @@ int pthread_mutex_destroy(FAR pthread_mutex_t *mutex) { pid_t pid; - /* Make sure the semaphore is stable while we make the following - * checks. - */ - - sched_lock(); - pid = mutex_get_holder(&mutex->mutex); /* Is the mutex available? */ @@ -141,8 +135,6 @@ int pthread_mutex_destroy(FAR pthread_mutex_t *mutex) status = mutex_destroy(&mutex->mutex); ret = ((status < 0) ? -status : OK); } - - sched_unlock(); } sinfo("Returning %d\n", ret); diff --git a/sched/pthread/pthread_mutextrylock.c b/sched/pthread/pthread_mutextrylock.c index 75b37afd7b..ecf791e3cb 100644 --- a/sched/pthread/pthread_mutextrylock.c +++ b/sched/pthread/pthread_mutextrylock.c @@ -82,12 +82,6 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex) pid_t pid = mutex_get_holder(&mutex->mutex); #endif - /* Make sure the semaphore is stable while we make the following - * checks. This all needs to be one atomic action. - */ - - sched_lock(); - /* Try to get the semaphore. */ status = pthread_mutex_trytake(mutex); @@ -163,8 +157,6 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex) { ret = status; } - - sched_unlock(); } sinfo("Returning %d\n", ret);