mirror of
https://github.com/apache/nuttx.git
synced 2026-05-29 04:19:37 +08:00
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
This commit is contained in:
+3
-3
@@ -144,14 +144,14 @@ int aio_cancel(int fildes, FAR struct aiocb *aiocbp)
|
||||
/* Remove the container from the list of pending transfers */
|
||||
|
||||
pid = aioc->aioc_pid;
|
||||
(void)aioc_decant(aioc);
|
||||
aioc_decant(aioc);
|
||||
|
||||
aiocbp->aio_result = -ECANCELED;
|
||||
ret = AIO_CANCELED;
|
||||
|
||||
/* Signal the client */
|
||||
|
||||
(void)aio_signal(pid, aiocbp);
|
||||
aio_signal(pid, aiocbp);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -211,7 +211,7 @@ int aio_cancel(int fildes, FAR struct aiocb *aiocbp)
|
||||
|
||||
/* Signal the client */
|
||||
|
||||
(void)aio_signal(pid, aiocbp);
|
||||
aio_signal(pid, aiocbp);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ static void aio_fsync_worker(FAR void *arg)
|
||||
|
||||
/* Signal the client */
|
||||
|
||||
(void)aio_signal(pid, aiocbp);
|
||||
aio_signal(pid, aiocbp);
|
||||
|
||||
#ifdef CONFIG_PRIORITY_INHERITANCE
|
||||
/* Restore the low priority worker thread default priority */
|
||||
|
||||
+5
-32
@@ -109,9 +109,9 @@ void aio_initialize(void)
|
||||
|
||||
/* Initialize counting semaphores */
|
||||
|
||||
(void)nxsem_init(&g_aioc_freesem, 0, CONFIG_FS_NAIOC);
|
||||
(void)nxsem_setprotocol(&g_aioc_freesem, SEM_PRIO_NONE);
|
||||
(void)nxsem_init(&g_aio_exclsem, 0, 1);
|
||||
nxsem_init(&g_aioc_freesem, 0, CONFIG_FS_NAIOC);
|
||||
nxsem_setprotocol(&g_aioc_freesem, SEM_PRIO_NONE);
|
||||
nxsem_init(&g_aio_exclsem, 0, 1);
|
||||
|
||||
g_aio_holder = INVALID_PROCESS_ID;
|
||||
|
||||
@@ -159,21 +159,7 @@ void aio_lock(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* No.. take the semaphore */
|
||||
|
||||
do
|
||||
{
|
||||
ret = nxsem_wait(&g_aio_exclsem);
|
||||
|
||||
/* The only case that an error should occur here is if the wait
|
||||
* was awakened by a signal.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(ret == OK || ret == -EINTR);
|
||||
}
|
||||
while (ret == -EINTR);
|
||||
nxsem_wait_uninterruptible(&g_aio_exclsem);
|
||||
|
||||
/* And mark it as ours */
|
||||
|
||||
@@ -226,25 +212,12 @@ void aio_unlock(void)
|
||||
FAR struct aio_container_s *aioc_alloc(void)
|
||||
{
|
||||
FAR struct aio_container_s *aioc;
|
||||
int ret;
|
||||
|
||||
/* Take a count from semaphore, thus guaranteeing that we have an AIO
|
||||
* container set aside for us.
|
||||
*/
|
||||
|
||||
do
|
||||
{
|
||||
/* Take the semaphore (perhaps waiting) */
|
||||
|
||||
ret = nxsem_wait(&g_aioc_freesem);
|
||||
|
||||
/* The only case that an error should occur here is if the wait was
|
||||
* awakened by a signal.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(ret == OK || ret == -EINTR);
|
||||
}
|
||||
while (ret == -EINTR);
|
||||
nxsem_wait_uninterruptible(&g_aioc_freesem);
|
||||
|
||||
/* Get our AIO container */
|
||||
|
||||
|
||||
+1
-1
@@ -137,7 +137,7 @@ static void aio_read_worker(FAR void *arg)
|
||||
|
||||
/* Signal the client */
|
||||
|
||||
(void)aio_signal(pid, aiocbp);
|
||||
aio_signal(pid, aiocbp);
|
||||
|
||||
#ifdef CONFIG_PRIORITY_INHERITANCE
|
||||
/* Restore the low priority worker thread default priority */
|
||||
|
||||
+1
-1
@@ -164,7 +164,7 @@ errout:
|
||||
|
||||
/* Signal the client */
|
||||
|
||||
(void)aio_signal(pid, aiocbp);
|
||||
aio_signal(pid, aiocbp);
|
||||
|
||||
#ifdef CONFIG_PRIORITY_INHERITANCE
|
||||
/* Restore the low priority worker thread default priority */
|
||||
|
||||
Reference in New Issue
Block a user