Skip to content

Commit

Permalink
sched/pthread: There is no need to use sched_[un]lock
Browse files Browse the repository at this point in the history
Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 committed Oct 11, 2024
1 parent 5e96e72 commit 4fbbb8e
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 38 deletions.
5 changes: 1 addition & 4 deletions sched/pthread/pthread_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
FAR struct pthread_tcb_s *ptcb;
struct sched_param param;
FAR struct tcb_s *parent;
irqstate_t flags;
int policy;
int errcode;
int ret;
Expand Down Expand Up @@ -442,8 +443,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)
Expand All @@ -455,8 +454,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:
Expand Down
12 changes: 0 additions & 12 deletions sched/pthread/pthread_mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -201,8 +197,6 @@ int pthread_mutex_take(FAR struct pthread_mutex_s *mutex,
}
}
}

sched_unlock();
}

return ret;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -269,8 +259,6 @@ int pthread_mutex_trytake(FAR struct pthread_mutex_s *mutex)
pthread_mutex_add(mutex);
}
}

sched_unlock();
}

return ret;
Expand Down
6 changes: 0 additions & 6 deletions sched/pthread/pthread_mutexconsistent.c
Original file line number Diff line number Diff line change
Expand Up @@ -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? */
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions sched/pthread/pthread_mutexdestroy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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? */
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions sched/pthread/pthread_mutextrylock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -163,8 +157,6 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex)
{
ret = status;
}

sched_unlock();
}

sinfo("Returning %d\n", ret);
Expand Down

0 comments on commit 4fbbb8e

Please sign in to comment.