libc: Replace all [nx]sem_xxx with _SEM_XXX
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Change-Id: I34f407ccd52391588ac1b720fce59d24458fe218
This commit is contained in:
parent
8db91a7974
commit
a7a81b5126
@ -69,7 +69,7 @@ void lib_sem_initialize(FAR struct file_struct *stream)
|
||||
* to private data sets.
|
||||
*/
|
||||
|
||||
nxsem_init(&stream->fs_sem, 0, 1);
|
||||
_SEM_INIT(&stream->fs_sem, 0, 1);
|
||||
|
||||
stream->fs_holder = -1;
|
||||
stream->fs_counts = 0;
|
||||
@ -106,7 +106,8 @@ void lib_take_semaphore(FAR struct file_struct *stream)
|
||||
* was awakened by a signal.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(_SEM_ERRNO(ret) == EINTR || _SEM_ERRNO(ret) == ECANCELED);
|
||||
DEBUGASSERT(_SEM_ERRNO(ret) == EINTR ||
|
||||
_SEM_ERRNO(ret) == ECANCELED);
|
||||
UNUSED(ret);
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ void lib_stream_initialize(FAR struct task_group_s *group)
|
||||
|
||||
/* Initialize the list access mutex */
|
||||
|
||||
nxsem_init(&list->sl_sem, 0, 1);
|
||||
_SEM_INIT(&list->sl_sem, 0, 1);
|
||||
|
||||
/* Initialize each FILE structure */
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/stdio/lib_fclose.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011, 2013, 2017 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2011, 2013, 2017 Gregory Nutt.
|
||||
* All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -92,7 +93,7 @@ int fclose(FAR FILE *stream)
|
||||
errcode = get_errno();
|
||||
}
|
||||
|
||||
/* Close the underlying file descriptor and save the return status */
|
||||
/* Close the file descriptor and save the return status */
|
||||
|
||||
status = close(stream->fs_fd);
|
||||
|
||||
@ -110,7 +111,7 @@ int fclose(FAR FILE *stream)
|
||||
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
|
||||
/* Destroy the semaphore */
|
||||
|
||||
sem_destroy(&stream->fs_sem);
|
||||
_SEM_DESTROY(&stream->fs_sem);
|
||||
|
||||
/* Release the buffer */
|
||||
|
||||
@ -135,7 +136,7 @@ int fclose(FAR FILE *stream)
|
||||
stream->fs_oflags = 0;
|
||||
#endif
|
||||
|
||||
/* Setting the file descriptor to -1 makes the stream available for reuse */
|
||||
/* Set file descriptor to -1 makes the stream available for reuse */
|
||||
|
||||
stream->fs_fd = -1;
|
||||
}
|
||||
|
@ -73,19 +73,20 @@ int work_lock(void)
|
||||
int ret;
|
||||
|
||||
#ifdef CONFIG_BUILD_PROTECTED
|
||||
ret = sem_wait(&g_usrsem);
|
||||
ret = _SEM_WAIT(&g_usrsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
DEBUGASSERT(errno == EINTR || errno == ECANCELED);
|
||||
DEBUGASSERT(_SEM_ERRNO(ret) == EINTR ||
|
||||
_SEM_ERRNO(ret) == ECANCELED);
|
||||
return -EINTR;
|
||||
}
|
||||
#else
|
||||
ret = pthread_mutex_lock(&g_usrmutex);
|
||||
if (ret != 0)
|
||||
{
|
||||
DEBUGASSERT(ret == EINTR);
|
||||
return -EINTR;
|
||||
}
|
||||
ret = pthread_mutex_lock(&g_usrmutex);
|
||||
if (ret != 0)
|
||||
{
|
||||
DEBUGASSERT(ret == EINTR);
|
||||
return -EINTR;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
@ -108,7 +109,7 @@ int work_lock(void)
|
||||
void work_unlock(void)
|
||||
{
|
||||
#ifdef CONFIG_BUILD_PROTECTED
|
||||
sem_post(&g_usrsem);
|
||||
_SEM_POST(&g_usrsem);
|
||||
#else
|
||||
pthread_mutex_unlock(&g_usrmutex);
|
||||
#endif
|
||||
|
@ -191,7 +191,7 @@ void work_process(FAR struct usr_wqueue_s *wqueue)
|
||||
|
||||
if (worker != NULL)
|
||||
{
|
||||
/* Extract the work argument (before unlocking the work queue) */
|
||||
/* Extract the work argument before unlocking the work queue */
|
||||
|
||||
arg = work->arg;
|
||||
|
||||
@ -206,9 +206,9 @@ void work_process(FAR struct usr_wqueue_s *wqueue)
|
||||
work_unlock();
|
||||
worker(arg);
|
||||
|
||||
/* Now, unfortunately, since we unlocked the work queue we don't
|
||||
* know the state of the work list and we will have to start
|
||||
* back at the head of the list.
|
||||
/* Now, unfortunately, since we unlocked the work queue we
|
||||
* don't know the state of the work list and we will have to
|
||||
* start back at the head of the list.
|
||||
*/
|
||||
|
||||
ret = work_lock();
|
||||
@ -362,79 +362,73 @@ static pthread_addr_t work_usrthread(pthread_addr_t arg)
|
||||
|
||||
int work_usrstart(void)
|
||||
{
|
||||
/* Initialize work queue data structures */
|
||||
|
||||
#ifdef CONFIG_BUILD_PROTECTED
|
||||
{
|
||||
/* Set up the work queue lock */
|
||||
/* Set up the work queue lock */
|
||||
|
||||
nxsem_init(&g_usrsem, 0, 1);
|
||||
_SEM_INIT(&g_usrsem, 0, 1);
|
||||
|
||||
/* Start a user-mode worker thread for use by applications. */
|
||||
/* Start a user-mode worker thread for use by applications. */
|
||||
|
||||
g_usrwork.pid = task_create("uwork",
|
||||
CONFIG_LIB_USRWORKPRIORITY,
|
||||
CONFIG_LIB_USRWORKSTACKSIZE,
|
||||
(main_t)work_usrthread,
|
||||
(FAR char * const *)NULL);
|
||||
g_usrwork.pid = task_create("uwork",
|
||||
CONFIG_LIB_USRWORKPRIORITY,
|
||||
CONFIG_LIB_USRWORKSTACKSIZE,
|
||||
(main_t)work_usrthread,
|
||||
(FAR char * const *)NULL);
|
||||
|
||||
DEBUGASSERT(g_usrwork.pid > 0);
|
||||
if (g_usrwork.pid < 0)
|
||||
{
|
||||
int errcode = get_errno();
|
||||
DEBUGASSERT(errcode > 0);
|
||||
return -errcode;
|
||||
}
|
||||
DEBUGASSERT(g_usrwork.pid > 0);
|
||||
if (g_usrwork.pid < 0)
|
||||
{
|
||||
int errcode = get_errno();
|
||||
DEBUGASSERT(errcode > 0);
|
||||
return -errcode;
|
||||
}
|
||||
|
||||
return g_usrwork.pid;
|
||||
}
|
||||
return g_usrwork.pid;
|
||||
#else
|
||||
{
|
||||
pthread_t usrwork;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param param;
|
||||
int ret;
|
||||
pthread_t usrwork;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param param;
|
||||
int ret;
|
||||
|
||||
/* Set up the work queue lock */
|
||||
/* Set up the work queue lock */
|
||||
|
||||
pthread_mutex_init(&g_usrmutex, NULL);
|
||||
pthread_mutex_init(&g_usrmutex, NULL);
|
||||
|
||||
/* Start a user-mode worker thread for use by applications. */
|
||||
/* Start a user-mode worker thread for use by applications. */
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, CONFIG_LIB_USRWORKSTACKSIZE);
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, CONFIG_LIB_USRWORKSTACKSIZE);
|
||||
|
||||
#ifdef CONFIG_SCHED_SPORADIC
|
||||
/* Get the current sporadic scheduling parameters. Those will not be
|
||||
* modified.
|
||||
*/
|
||||
/* Get the current sporadic scheduling parameters. Those will not be
|
||||
* modified.
|
||||
*/
|
||||
|
||||
ret = set_getparam(pid, ¶m);
|
||||
if (ret < 0)
|
||||
{
|
||||
int erroode = get_errno();
|
||||
return -errcode;
|
||||
}
|
||||
ret = set_getparam(pid, ¶m);
|
||||
if (ret < 0)
|
||||
{
|
||||
int errcode = get_errno();
|
||||
return -errcode;
|
||||
}
|
||||
#endif
|
||||
|
||||
param.sched_priority = CONFIG_LIB_USRWORKPRIORITY;
|
||||
pthread_attr_setschedparam(&attr, ¶m);
|
||||
param.sched_priority = CONFIG_LIB_USRWORKPRIORITY;
|
||||
pthread_attr_setschedparam(&attr, ¶m);
|
||||
|
||||
ret = pthread_create(&usrwork, &attr, work_usrthread, NULL);
|
||||
if (ret != 0)
|
||||
{
|
||||
return -ret;
|
||||
}
|
||||
ret = pthread_create(&usrwork, &attr, work_usrthread, NULL);
|
||||
if (ret != 0)
|
||||
{
|
||||
return -ret;
|
||||
}
|
||||
|
||||
/* Detach because the return value and completion status will not be
|
||||
* requested.
|
||||
*/
|
||||
/* Detach because the return value and completion status will not be
|
||||
* requested.
|
||||
*/
|
||||
|
||||
pthread_detach(usrwork);
|
||||
pthread_detach(usrwork);
|
||||
|
||||
g_usrwork.pid = (pid_t)usrwork;
|
||||
return g_usrwork.pid;
|
||||
}
|
||||
g_usrwork.pid = (pid_t)usrwork;
|
||||
return g_usrwork.pid;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user