Squashed commit of the following:

This commit backs out most of commit b4747286b1.  That change was added because sem_wait() would sometimes cause cancellation points inappropriated.  But with these recent changes, nxsem_wait() is used instead and it is not a cancellation point.

    In the OS, all calls to sem_wait() changed to nxsem_wait().  nxsem_wait() does not return errors via errno so each place where nxsem_wait() is now called must not examine the errno variable.

    In all OS functions (not libraries), change sem_wait() to nxsem_wait().  This will prevent the OS from creating bogus cancellation points and from modifying the per-task errno variable.

    sched/semaphore:  Add the function nxsem_wait().  This is a new internal OS interface.  It is functionally equivalent to sem_wait() except that (1) it is not a cancellation point, and (2) it does not set the per-thread errno value on return.
This commit is contained in:
Gregory Nutt
2017-10-04 15:22:27 -06:00
parent 42a0796615
commit 9568600ab1
307 changed files with 3421 additions and 2423 deletions
+8 -19
View File
@@ -202,11 +202,7 @@ o Task/Scheduler (sched/)
For example, having cancellation points hidden inside of the For example, having cancellation points hidden inside of the
OS can cause non-cancellation point interfaces to behave OS can cause non-cancellation point interfaces to behave
strangely. There was a change recently in pthread_cond_wait() strangely.
and pthread_cond_timedwait() recently to effectively disable
the cancellation point behavior of sem_wait(). This was
accomplished with two functions: pthread_disable_cancel()
and pthread_enable_cancel()
Here is another issue:  Internal OS functions should not set Here is another issue:  Internal OS functions should not set
errno and should never have to look at the errno value to errno and should never have to look at the errno value to
@@ -217,7 +213,7 @@ o Task/Scheduler (sched/)
Both of these could be fixed if there were special internal Both of these could be fixed if there were special internal
versions these functions.  For example, there could be a an versions these functions.  For example, there could be a an
nx_sem_wait() that does all of the same things as sem_wait() nxsem_wait() that does all of the same things as sem_wait()
was does not create a cancellation point and does not set was does not create a cancellation point and does not set
the errno value on failures. the errno value on failures.
@@ -227,20 +223,13 @@ o Task/Scheduler (sched/)
and that sets the errno value on failures. and that sets the errno value on failures.
Changes like that could clean up some of this internal Changes like that could clean up some of this internal
craziness.  The condition variable change described above is craziness.
really a "bandaid" to handle the case that sem_wait() is a
cancellation point. Also will need to revisit previous changes
like:
commit b4747286b19d3b15193b2a5e8a0fe48fa0a8638c UPDATE:
Author: Juha Niskanen (Haltian) <juha.niskanen@haltian.com> 2017-1003: This change has been completed for the case of
Date: Tue Apr 11 11:03:25 2017 -0600 semaphores used int he OS. Still need to checkout signals
and messages queues that are also used in the OS. Also
Add logic to disable cancellation points within the OS. backed out commit b4747286b19d3b15193b2a5e8a0fe48fa0a8638c.
This is useful when an internal OS function that is NOT
a cancellation point calls an OS function which is a
cancellation point. In that case, irrecoverable states
may occur if the cancellation is within the OS.
Status: Open Status: Open
Priority: Low. Things are working OK the way they are. But the design Priority: Low. Things are working OK the way they are. But the design
+22 -7
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/efm32/efm32_dma.c * arch/arm/src/efm32/efm32_dma.c
* *
* Copyright (C) 2014 Gregory Nutt. All rights reserved. * Copyright (C) 2014, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -336,6 +336,7 @@ DMA_HANDLE efm32_dmachannel(void)
struct dma_channel_s *dmach; struct dma_channel_s *dmach;
unsigned int chndx; unsigned int chndx;
uint32_t bit; uint32_t bit;
int ret;
/* Take a count from from the channel counting semaphore. We may block /* Take a count from from the channel counting semaphore. We may block
* if there are no free channels. When we get the count, then we can * if there are no free channels. When we get the count, then we can
@@ -343,21 +344,35 @@ DMA_HANDLE efm32_dmachannel(void)
* reserved for us. * reserved for us.
*/ */
while (sem_wait(&g_dmac.chansem) < 0) do
{ {
/* sem_wait should fail only if it is awakened by a a signal */ /* Take the semaphore (perhaps waiting) */
DEBUGASSERT(errno == EINTR); ret = nxsem_wait(&g_dmac.chansem);
/* 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);
/* Get exclusive access to the DMA channel list */ /* Get exclusive access to the DMA channel list */
while (sem_wait(&g_dmac.exclsem) < 0) do
{ {
/* sem_wait should fail only if it is awakened by a a signal */ /* Take the semaphore (perhaps waiting) */
DEBUGASSERT(errno == EINTR); ret = nxsem_wait(&g_dmac.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);
/* Search for an available DMA channel */ /* Search for an available DMA channel */
+14 -3
View File
@@ -5,7 +5,7 @@
* Copyright (C) 2015 Pierre-noel Bouteville . All rights reserved. * Copyright (C) 2015 Pierre-noel Bouteville . All rights reserved.
* Authors: Pierre-noel Bouteville <pnb990@gmail.com> * Authors: Pierre-noel Bouteville <pnb990@gmail.com>
* *
* Copyright (C) 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -480,10 +480,21 @@ static const char *efm32_i2c_state_str(int i2c_state)
static inline void efm32_i2c_sem_wait(FAR struct efm32_i2c_priv_s *priv) static inline void efm32_i2c_sem_wait(FAR struct efm32_i2c_priv_s *priv)
{ {
while (sem_wait(&priv->sem_excl) != OK) int ret;
do
{ {
ASSERT(errno == EINTR); /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&priv->sem_excl);
/* 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);
} }
/**************************************************************************** /****************************************************************************
+24 -8
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arm/arm/src/efm32/efm32_spi.c * arm/arm/src/efm32/efm32_spi.c
* *
* Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2014, 2016-2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2014 Bouteville Pierre-Noel. All rights reserved. * Copyright (C) 2014 Bouteville Pierre-Noel. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org> * Authors: Gregory Nutt <gnutt@nuttx.org>
* Bouteville Pierre-Noel <pnb990@gmail.com> * Bouteville Pierre-Noel <pnb990@gmail.com>
@@ -437,18 +437,24 @@ static void spi_dma_timeout(int argc, uint32_t arg1, ...)
static void spi_dmarxwait(struct efm32_spidev_s *priv) static void spi_dmarxwait(struct efm32_spidev_s *priv)
{ {
irqstate_t flags; irqstate_t flags;
int ret;
/* Take the semaphore (perhaps waiting). */ /* Take the semaphore (perhaps waiting). */
flags = enter_critical_section(); flags = enter_critical_section();
while (sem_wait(&priv->rxdmasem) != 0) do
{ {
/* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&priv->rxdmasem);
/* The only case that an error should occur here is if the wait was /* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
DEBUGASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
/* Cancel the timeout only if both the RX and TX transfers have completed */ /* Cancel the timeout only if both the RX and TX transfers have completed */
@@ -474,18 +480,24 @@ static void spi_dmarxwait(struct efm32_spidev_s *priv)
static void spi_dmatxwait(struct efm32_spidev_s *priv) static void spi_dmatxwait(struct efm32_spidev_s *priv)
{ {
irqstate_t flags; irqstate_t flags;
int ret;
/* Take the semaphore (perhaps waiting). */ /* Take the semaphore (perhaps waiting). */
flags = enter_critical_section(); flags = enter_critical_section();
while (sem_wait(&priv->txdmasem) != 0) do
{ {
/* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&priv->txdmasem);
/* The only case that an error should occur here is if the wait was /* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
DEBUGASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
/* Cancel the timeout only if both the RX and TX transfers have completed */ /* Cancel the timeout only if both the RX and TX transfers have completed */
@@ -748,21 +760,25 @@ static int spi_lock(struct spi_dev_s *dev, bool lock)
{ {
/* Take the semaphore (perhaps waiting) */ /* Take the semaphore (perhaps waiting) */
while (sem_wait(&priv->exclsem) != 0) do
{ {
ret = nxsem_wait(&priv->exclsem);
/* The only case that an error should occur here is if the wait /* The only case that an error should occur here is if the wait
* was awakened by a signal. * was awakened by a signal.
*/ */
DEBUGASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
else else
{ {
(void)nxsem_post(&priv->exclsem); (void)nxsem_post(&priv->exclsem);
ret = OK;
} }
return OK; return ret;
} }
/**************************************************************************** /****************************************************************************
+13 -8
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/efm32/efm32_usbhost.c * arch/arm/src/efm32/efm32_usbhost.c
* *
* Copyright (C) 2014-2016 Gregory Nutt. All rights reserved. * Copyright (C) 2014-2017 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org> * Authors: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -718,16 +718,21 @@ static inline void efm32_modifyreg(uint32_t addr, uint32_t clrbits, uint32_t set
static void efm32_takesem(sem_t *sem) static void efm32_takesem(sem_t *sem)
{ {
/* Take the semaphore (perhaps waiting) */ int ret;
while (sem_wait(sem) != 0) do
{ {
/* The only case that an error should occr here is if the wait was /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(sem);
/* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
/**************************************************************************** /****************************************************************************
@@ -1181,13 +1186,13 @@ static int efm32_chan_wait(FAR struct efm32_usbhost_s *priv,
* wait here. * wait here.
*/ */
ret = sem_wait(&chan->waitsem); ret = nxsem_wait(&chan->waitsem);
/* sem_wait should succeed. But it is possible that we could be /* nxsem_wait should succeed. But it is possible that we could be
* awakened by a signal too. * awakened by a signal too.
*/ */
DEBUGASSERT(ret == OK || get_errno() == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (chan->waiter); while (chan->waiter);
+11 -11
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/imx1/imx_spi.c * arch/arm/src/imx1/imx_spi.c
* *
* Copyright (C) 2009-2010, 2013, 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2009-2010, 2013, 2016-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -562,9 +562,9 @@ static int spi_transfer(struct imx_spidev_s *priv, const void *txbuffer,
{ {
/* Wait to be signaled from the interrupt handler */ /* Wait to be signaled from the interrupt handler */
ret = sem_wait(&priv->waitsem); ret = nxsem_wait(&priv->waitsem);
} }
while (ret < 0 && errno == EINTR); while (ret < 0 && ret == -EINTR);
#else #else
/* Perform the transfer using polling logic. This will totally /* Perform the transfer using polling logic. This will totally
@@ -709,26 +709,26 @@ static int spi_interrupt(int irq, void *context, FAR void *arg, FAR void *arg)
static int spi_lock(FAR struct spi_dev_s *dev, bool lock) static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
{ {
struct imx_spidev_s *priv = (struct imx_spidev_s *)dev; struct imx_spidev_s *priv = (struct imx_spidev_s *)dev;
int ret;
if (lock) if (lock)
{ {
/* Take the semaphore (perhaps waiting) */ do
while (sem_wait(&priv->exclsem) != 0)
{ {
/* The only case that an error should occur here is if the wait /* Take the semaphore (perhaps waiting) */
* was awakened by a signal.
*/
DEBUGASSERT(errno == EINTR); ret = nxsem_wait(&priv->exclsem);
DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
else else
{ {
(void)nxsem_post(&priv->exclsem); (void)nxsem_post(&priv->exclsem);
ret = OK;
} }
return OK; return ret;
} }
/**************************************************************************** /****************************************************************************
+11 -11
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/imx6/imx_ecspi.c * arch/arm/src/imx6/imx_ecspi.c
* *
* Copyright (C) 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Derives from the i.MX1 CSPI driver: * Derives from the i.MX1 CSPI driver:
@@ -687,9 +687,9 @@ static int spi_transfer(struct imx_spidev_s *priv, const void *txbuffer,
{ {
/* Wait to be signaled from the interrupt handler */ /* Wait to be signaled from the interrupt handler */
ret = sem_wait(&priv->waitsem); ret = nxsem_wait(&priv->waitsem);
} }
while (ret < 0 && errno == EINTR); while (ret < 0 && ret == -EINTR);
#else #else
/* Perform the transfer using polling logic. This will totally /* Perform the transfer using polling logic. This will totally
@@ -794,26 +794,26 @@ static int spi_interrupt(int irq, void *context, FAR void *arg)
static int spi_lock(FAR struct spi_dev_s *dev, bool lock) static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
{ {
struct imx_spidev_s *priv = (struct imx_spidev_s *)dev; struct imx_spidev_s *priv = (struct imx_spidev_s *)dev;
int ret;
if (lock) if (lock)
{ {
/* Take the semaphore (perhaps waiting) */ do
while (sem_wait(&priv->exclsem) != 0)
{ {
/* The only case that an error should occur here is if the wait /* Take the semaphore (perhaps waiting) */
* was awakened by a signal.
*/
DEBUGASSERT(errno == EINTR); ret = nxsem_wait(&priv->exclsem);
DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
else else
{ {
(void)nxsem_post(&priv->exclsem); (void)nxsem_post(&priv->exclsem);
ret = OK;
} }
return OK; return ret;
} }
/**************************************************************************** /****************************************************************************
+3 -3
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/imx6/imx_serial.c * arch/arm/src/imx6/imx_serial.c
* *
* Copyright (C) 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -963,10 +963,10 @@ int up_putc(int ch)
if (!up_interrupt_context() && g_os_initstate >= OSINIT_HARDWARE) if (!up_interrupt_context() && g_os_initstate >= OSINIT_HARDWARE)
{ {
ret = sem_wait(&g_putc_lock); ret = nxsem_wait(&g_putc_lock);
if (ret < 0) if (ret < 0)
{ {
return ERROR; return ret;
} }
locked = true; locked = true;
+14 -3
View File
@@ -350,10 +350,21 @@ static inline void kinetis_i2c_sem_destroy(FAR struct kinetis_i2cdev_s *priv)
static inline void kinetis_i2c_sem_wait(FAR struct kinetis_i2cdev_s *priv) static inline void kinetis_i2c_sem_wait(FAR struct kinetis_i2cdev_s *priv)
{ {
while (sem_wait(&priv->mutex) != 0) int ret;
do
{ {
DEBUGASSERT(errno == EINTR); /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&priv->mutex);
/* 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);
} }
/************************************************************************************ /************************************************************************************
@@ -379,7 +390,7 @@ static inline void kinetis_i2c_sem_post(struct kinetis_i2cdev_s *priv)
static inline void kinetis_i2c_wait(struct kinetis_i2cdev_s *priv) static inline void kinetis_i2c_wait(struct kinetis_i2cdev_s *priv)
{ {
sem_wait(&priv->wait); (void)nxsem_wait(&priv->wait);
} }
/************************************************************************************ /************************************************************************************
+9 -4
View File
@@ -432,16 +432,21 @@ static struct kinetis_sdhcregs_s g_sampleregs[DEBUG_NSAMPLES];
static void kinetis_takesem(struct kinetis_dev_s *priv) static void kinetis_takesem(struct kinetis_dev_s *priv)
{ {
/* Take the semaphore (perhaps waiting) */ int ret;
while (sem_wait(&priv->waitsem) != 0) do
{ {
/* The only case that an error should occr here is if the wait was /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&priv->waitsem);
/* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
/**************************************************************************** /****************************************************************************
+10 -5
View File
@@ -583,26 +583,31 @@ void inline spi_run(FAR struct kinetis_spidev_s *priv, bool enable)
static int spi_lock(FAR struct spi_dev_s *dev, bool lock) static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
{ {
FAR struct kinetis_spidev_s *priv = (FAR struct kinetis_spidev_s *)dev; FAR struct kinetis_spidev_s *priv = (FAR struct kinetis_spidev_s *)dev;
int ret;
if (lock) if (lock)
{ {
/* Take the semaphore (perhaps waiting) */ /* Take the semaphore (perhaps waiting) */
while (sem_wait(&priv->exclsem) != 0) do
{ {
/* The only case that an error should occur here is if the wait was awakened ret = nxsem_wait(&priv->exclsem);
* by a signal.
/* The only case that an error should occur here is if the wait
* was awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
else else
{ {
(void)nxsem_post(&priv->exclsem); (void)nxsem_post(&priv->exclsem);
ret = OK;
} }
return OK; return ret;
} }
/************************************************************************************ /************************************************************************************
+12 -6
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/kl/kl_spi.c * arch/arm/src/kl/kl_spi.c
* *
* Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2013, 2016-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -235,25 +235,31 @@ static inline void spi_putreg(FAR struct kl_spidev_s *priv, uint8_t offset,
static int spi_lock(FAR struct spi_dev_s *dev, bool lock) static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
{ {
FAR struct kl_spidev_s *priv = (FAR struct kl_spidev_s *)dev; FAR struct kl_spidev_s *priv = (FAR struct kl_spidev_s *)dev;
int ret;
if (lock) if (lock)
{ {
/* Take the semaphore (perhaps waiting) */ /* Take the semaphore (perhaps waiting) */
while (sem_wait(&priv->exclsem) != 0) do
{ {
/* The only case that an error should occur here is if the wait was awakened ret = nxsem_wait(&priv->exclsem);
* by a signal.
/* The only case that an error should occur here is if the wait
* was awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
else else
{ {
(void)nxsem_post(&priv->exclsem); (void)nxsem_post(&priv->exclsem);
ret = OK;
} }
return OK;
return ret;
} }
/************************************************************************************ /************************************************************************************
+27 -5
View File
@@ -226,7 +226,9 @@ static void lc823450_adc_start(FAR struct lc823450_adc_inst_s *inst)
uint8_t i; uint8_t i;
uint32_t div; uint32_t div;
#ifdef CONFIG_ADC_POLLED #ifndef CONFIG_ADC_POLLED
int ret;
#else
irqstate_t flags; irqstate_t flags;
flags = enter_critical_section(); flags = enter_critical_section();
@@ -261,10 +263,19 @@ static void lc823450_adc_start(FAR struct lc823450_adc_inst_s *inst)
while ((getreg32(rADCSTS) & rADCSTS_fADCMPL) == 0) while ((getreg32(rADCSTS) & rADCSTS_fADCMPL) == 0)
; ;
#else #else
while (sem_wait(&inst->sem_isr) != 0) do
{ {
ASSERT(errno == EINTR); /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&inst->sem_isr);
/* 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);
#endif #endif
#ifdef CONFIG_ADC_POLLED #ifdef CONFIG_ADC_POLLED
@@ -282,10 +293,21 @@ static void lc823450_adc_start(FAR struct lc823450_adc_inst_s *inst)
static inline void lc823450_adc_sem_wait(FAR struct lc823450_adc_inst_s *inst) static inline void lc823450_adc_sem_wait(FAR struct lc823450_adc_inst_s *inst)
{ {
while (sem_wait(&inst->sem_excl) != 0) int ret;
do
{ {
ASSERT(errno == EINTR); /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&inst->sem_excl);
/* 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);
} }
/**************************************************************************** /****************************************************************************
+13 -2
View File
@@ -260,10 +260,21 @@ static struct lc823450_i2c_priv_s lc823450_i2c1_priv =
static inline void lc823450_i2c_sem_wait(FAR struct lc823450_i2c_priv_s *priv) static inline void lc823450_i2c_sem_wait(FAR struct lc823450_i2c_priv_s *priv)
{ {
while (sem_wait(&priv->sem_excl) != 0) int ret;
do
{ {
ASSERT(errno == EINTR); /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&priv->sem_excl);
/* 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);
} }
/**************************************************************************** /****************************************************************************
+13 -2
View File
@@ -142,10 +142,21 @@ static struct lc823450_partinfo_s partinfo[LC823450_NPARTS] =
static void mtd_semtake(FAR sem_t *sem) static void mtd_semtake(FAR sem_t *sem)
{ {
while (sem_wait(sem) != 0) int ret;
do
{ {
ASSERT(errno == EINTR); /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(sem);
/* 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);
} }
/**************************************************************************** /****************************************************************************
+13 -2
View File
@@ -138,10 +138,21 @@ extern SINT_T sddep_write(void *src, void *dst, UI_32 size, SINT_T type,
static void _sdc_semtake(FAR sem_t *sem) static void _sdc_semtake(FAR sem_t *sem)
{ {
while (sem_wait(sem) != 0) int ret;
do
{ {
ASSERT(errno == EINTR); /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(sem);
/* 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);
} }
/**************************************************************************** /****************************************************************************
+13 -2
View File
@@ -131,10 +131,21 @@ static void dma_callback(DMA_HANDLE hdma, void *arg, int result)
static void _sddep_semtake(FAR sem_t *sem) static void _sddep_semtake(FAR sem_t *sem)
{ {
while (sem_wait(sem) != 0) int ret;
do
{ {
ASSERT(errno == EINTR); /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(sem);
/* 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);
} }
/**************************************************************************** /****************************************************************************
+1 -1
View File
@@ -1204,7 +1204,7 @@ static int up_hs_send(struct uart_dev_s *dev, const char *buf, int buflen)
retry: retry:
sem_wait(&priv->txdma_wait); nxsem_wait(&priv->txdma_wait);
/* If buflen <= FIFO space, write it by PIO. */ /* If buflen <= FIFO space, write it by PIO. */
+11 -6
View File
@@ -149,26 +149,31 @@ static struct lc823450_spidev_s g_spidev =
static int spi_lock(FAR struct spi_dev_s *dev, bool lock) static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
{ {
FAR struct lc823450_spidev_s *priv = (FAR struct lc823450_spidev_s *)dev; FAR struct lc823450_spidev_s *priv = (FAR struct lc823450_spidev_s *)dev;
int ret;
if (lock) if (lock)
{ {
/* Take the semaphore (perhaps waiting) */ /* Take the semaphore (perhaps waiting) */
while (sem_wait(&priv->exclsem) != 0) do
{ {
/* The only case that an error should occur here is if the wait was awakened ret = nxsem_wait(&priv->exclsem);
* by a signal.
/* The only case that an error should occur here is if the wait was
* awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
else else
{ {
(void)nxsem_post(&priv->exclsem); (void)nxsem_post(&priv->exclsem);
ret = OK;
} }
return OK; return ret;
} }
#endif #endif
@@ -409,7 +414,7 @@ static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const void *buffer,
modifyreg32(LC823450_SPI_SMD, 0, SPI_SMD_WTR); modifyreg32(LC823450_SPI_SMD, 0, SPI_SMD_WTR);
while (sem_wait(&priv->dma_wait) != 0); while (nxsem_wait(&priv->dma_wait) < 0);
nwords -= len; nwords -= len;
buffer += len; buffer += len;
} }
+1 -1
View File
@@ -391,7 +391,7 @@ int up_hrttimer_usleep(unsigned int usec)
hrt.usec = usec; hrt.usec = usec;
hrt_usleep_add(&hrt); hrt_usleep_add(&hrt);
sem_wait(&hrt.sem); nxsem_wait(&hrt.sem);
return 0; return 0;
} }
+2 -2
View File
@@ -1780,7 +1780,7 @@ int usbdev_msc_epwrite(void *buf, int len)
USB_DMAC_START, USB_DMAC_START,
USB_DMAC1); USB_DMAC1);
(void)sem_wait(&dma_wait); (void)nxsem_wait(&dma_wait);
return 0; return 0;
} }
@@ -1884,7 +1884,7 @@ int usbdev_msc_epread(void *buf, int len)
CONFIG_USBMSC_EPBULKOUT << USB_DMAC_DMAEP_SHIFT | CONFIG_USBMSC_EPBULKOUT << USB_DMAC_DMAEP_SHIFT |
USB_DMAC_START, USB_DMAC_START,
USB_DMAC1); USB_DMAC1);
(void)sem_wait(&dma_wait); (void)nxsem_wait(&dma_wait);
return 0; return 0;
} }
+2 -2
View File
@@ -216,7 +216,7 @@ static int lpc11_i2c_start(struct lpc11_i2cdev_s *priv)
putreg32(I2C_CONSET_STA, priv->base + LPC11_I2C_CONSET_OFFSET); putreg32(I2C_CONSET_STA, priv->base + LPC11_I2C_CONSET_OFFSET);
wd_start(priv->timeout, I2C_TIMEOUT, lpc11_i2c_timeout, 1, (uint32_t)priv); wd_start(priv->timeout, I2C_TIMEOUT, lpc11_i2c_timeout, 1, (uint32_t)priv);
sem_wait(&priv->wait); nxsem_wait(&priv->wait);
wd_cancel(priv->timeout); wd_cancel(priv->timeout);
@@ -278,7 +278,7 @@ static int lpc11_i2c_transfer(FAR struct i2c_master_s *dev,
/* Get exclusive access to the I2C bus */ /* Get exclusive access to the I2C bus */
sem_wait(&priv->mutex); nxsem_wait(&priv->mutex);
/* Set up for the transfer */ /* Set up for the transfer */
+10 -4
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/lpc11xx/lpc11_spi.c * arch/arm/src/lpc11xx/lpc11_spi.c
* *
* Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. * Copyright (C) 2015-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -186,25 +186,31 @@ static struct lpc11_spidev_s g_spidev =
static int spi_lock(FAR struct spi_dev_s *dev, bool lock) static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
{ {
FAR struct lpc11_spidev_s *priv = (FAR struct lpc11_spidev_s *)dev; FAR struct lpc11_spidev_s *priv = (FAR struct lpc11_spidev_s *)dev;
int ret;
if (lock) if (lock)
{ {
/* Take the semaphore (perhaps waiting) */ /* Take the semaphore (perhaps waiting) */
while (sem_wait(&priv->exclsem) != 0) do
{ {
ret = nxsem_wait(&priv->exclsem);
/* The only case that an error should occur here is if the wait /* The only case that an error should occur here is if the wait
* was awakened by a signal. * was awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
else else
{ {
(void)nxsem_post(&priv->exclsem); (void)nxsem_post(&priv->exclsem);
ret = 0
} }
return OK;
return ret;
} }
/**************************************************************************** /****************************************************************************
+10 -4
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/lpc11xx/lpc11_ssp.c * arch/arm/src/lpc11xx/lpc11_ssp.c
* *
* Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. * Copyright (C) 2015-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -334,25 +334,31 @@ static inline void ssp_putreg(FAR struct lpc11_sspdev_s *priv,
static int ssp_lock(FAR struct spi_dev_s *dev, bool lock) static int ssp_lock(FAR struct spi_dev_s *dev, bool lock)
{ {
FAR struct lpc11_sspdev_s *priv = (FAR struct lpc11_sspdev_s *)dev; FAR struct lpc11_sspdev_s *priv = (FAR struct lpc11_sspdev_s *)dev;
int ret
if (lock) if (lock)
{ {
/* Take the semaphore (perhaps waiting) */ /* Take the semaphore (perhaps waiting) */
while (sem_wait(&priv->exclsem) != 0) do
{ {
ret = nxsem_wait(&priv->exclsem);
/* The only case that an error should occur here is if the wait /* The only case that an error should occur here is if the wait
* was awakened by a signal. * was awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
else else
{ {
(void)nxsem_post(&priv->exclsem); (void)nxsem_post(&priv->exclsem);
ret = OK;
} }
return OK;
return ret;
} }
/**************************************************************************** /****************************************************************************
+4 -4
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/lpc17xx/lpc17_gpdma.c * arch/arm/src/lpc17xx/lpc17_gpdma.c
* *
* Copyright (C) 2010, 2014, 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2010, 2014, 2016-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -395,10 +395,10 @@ DMA_HANDLE lpc17_dmachannel(void)
do do
{ {
ret = sem_wait(&g_gpdma.exclsem); ret = nxsem_wait(&g_gpdma.exclsem);
DEBUGASSERT(ret == 0 || errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret < 0); while (ret == -EINTR);
/* Find an available DMA channel */ /* Find an available DMA channel */
+2 -2
View File
@@ -216,7 +216,7 @@ static int lpc17_i2c_start(struct lpc17_i2cdev_s *priv)
putreg32(I2C_CONSET_STA, priv->base + LPC17_I2C_CONSET_OFFSET); putreg32(I2C_CONSET_STA, priv->base + LPC17_I2C_CONSET_OFFSET);
wd_start(priv->timeout, I2C_TIMEOUT, lpc17_i2c_timeout, 1, (uint32_t)priv); wd_start(priv->timeout, I2C_TIMEOUT, lpc17_i2c_timeout, 1, (uint32_t)priv);
sem_wait(&priv->wait); nxsem_wait(&priv->wait);
wd_cancel(priv->timeout); wd_cancel(priv->timeout);
@@ -278,7 +278,7 @@ static int lpc17_i2c_transfer(FAR struct i2c_master_s *dev,
/* Get exclusive access to the I2C bus */ /* Get exclusive access to the I2C bus */
sem_wait(&priv->mutex); nxsem_wait(&priv->mutex);
/* Set up for the transfer */ /* Set up for the transfer */
+9 -4
View File
@@ -485,16 +485,21 @@ static struct lpc17_sampleregs_s g_sampleregs[DEBUG_NSAMPLES];
static void lpc17_takesem(struct lpc17_dev_s *priv) static void lpc17_takesem(struct lpc17_dev_s *priv)
{ {
/* Take the semaphore (perhaps waiting) */ int ret;
while (sem_wait(&priv->waitsem) != 0) do
{ {
/* The only case that an error should occr here is if the wait was /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&priv->waitsem);
/* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
/**************************************************************************** /****************************************************************************
+13 -6
View File
@@ -1,7 +1,8 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/lpc17xx/lpc17_spi.c * arch/arm/src/lpc17xx/lpc17_spi.c
* *
* Copyright (C) 2010, 2012-2013, 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2010, 2012-2013, 2016-2017 Gregory Nutt. All rights
* reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -182,25 +183,31 @@ static struct lpc17_spidev_s g_spidev =
static int spi_lock(FAR struct spi_dev_s *dev, bool lock) static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
{ {
FAR struct lpc17_spidev_s *priv = (FAR struct lpc17_spidev_s *)dev; FAR struct lpc17_spidev_s *priv = (FAR struct lpc17_spidev_s *)dev;
int ret;
if (lock) if (lock)
{ {
/* Take the semaphore (perhaps waiting) */ /* Take the semaphore (perhaps waiting) */
while (sem_wait(&priv->exclsem) != 0) do
{ {
/* The only case that an error should occur here is if the wait was awakened ret = nxsem_wait(&priv->exclsem);
* by a signal.
/* The only case that an error should occur here is if the wait
* was awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
else else
{ {
(void)nxsem_post(&priv->exclsem); (void)nxsem_post(&priv->exclsem);
ret = OK;
} }
return OK;
return ret;
} }
/**************************************************************************** /****************************************************************************
+12 -6
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/lpc17xx/lpc17_ssp.c * arch/arm/src/lpc17xx/lpc17_ssp.c
* *
* Copyright (C) 2010-2013, 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2010-2013, 2016-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -330,25 +330,31 @@ static inline void ssp_putreg(FAR struct lpc17_sspdev_s *priv, uint8_t offset, u
static int ssp_lock(FAR struct spi_dev_s *dev, bool lock) static int ssp_lock(FAR struct spi_dev_s *dev, bool lock)
{ {
FAR struct lpc17_sspdev_s *priv = (FAR struct lpc17_sspdev_s *)dev; FAR struct lpc17_sspdev_s *priv = (FAR struct lpc17_sspdev_s *)dev;
int ret;
if (lock) if (lock)
{ {
/* Take the semaphore (perhaps waiting) */ /* Take the semaphore (perhaps waiting) */
while (sem_wait(&priv->exclsem) != 0) do
{ {
/* The only case that an error should occur here is if the wait was awakened ret = nxsem_wait(&priv->exclsem);
* by a signal.
/* The only case that an error should occur here is if the wait
* was awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
else else
{ {
(void)nxsem_post(&priv->exclsem); (void)nxsem_post(&priv->exclsem);
ret = OK;
} }
return OK;
return ret;
} }
/**************************************************************************** /****************************************************************************
+10 -5
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/lpc17xx/lpc17_usbhost.c * arch/arm/src/lpc17xx/lpc17_usbhost.c
* *
* Copyright (C) 2010-2012, 2014-2016 Gregory Nutt. All rights reserved. * Copyright (C) 2010-2012, 2014-2017 Gregory Nutt. All rights reserved.
* Authors: Rafael Noronha <rafael@pdsolucoes.com.br> * Authors: Rafael Noronha <rafael@pdsolucoes.com.br>
* Gregory Nutt <gnutt@nuttx.org> * Gregory Nutt <gnutt@nuttx.org>
* *
@@ -583,16 +583,21 @@ static void lpc17_putreg(uint32_t val, uint32_t addr)
static void lpc17_takesem(sem_t *sem) static void lpc17_takesem(sem_t *sem)
{ {
/* Take the semaphore (perhaps waiting) */ int ret;
while (sem_wait(sem) != 0) do
{ {
/* The only case that an error should occr here is if the wait was /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(sem);
/* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
/**************************************************************************** /****************************************************************************
+2 -2
View File
@@ -221,7 +221,7 @@ static int lpc2378_i2c_start(struct lpc2378_i2cdev_s *priv)
putreg32(I2C_CONSET_STA, priv->base + I2C_CONSET_OFFSET); putreg32(I2C_CONSET_STA, priv->base + I2C_CONSET_OFFSET);
wd_start(priv->timeout, I2C_TIMEOUT, lpc2378_i2c_timeout, 1, (uint32_t)priv); wd_start(priv->timeout, I2C_TIMEOUT, lpc2378_i2c_timeout, 1, (uint32_t)priv);
sem_wait(&priv->wait); nxsem_wait(&priv->wait);
wd_cancel(priv->timeout); wd_cancel(priv->timeout);
@@ -404,7 +404,7 @@ static int lpc2378_i2c_transfer(FAR struct i2c_master_s *dev,
/* Get exclusive access to the I2C bus */ /* Get exclusive access to the I2C bus */
sem_wait(&priv->mutex); nxsem_wait(&priv->mutex);
/* Set up for the transfer */ /* Set up for the transfer */
+11 -6
View File
@@ -6,7 +6,7 @@
* *
* Derived from arch/arm/src/lpc17xx/lpc17_spi.c * Derived from arch/arm/src/lpc17xx/lpc17_spi.c
* *
* Copyright (C) 2010, 2012, 2014, 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2010, 2012, 2014, 2016-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -189,26 +189,31 @@ static struct lpc23xx_spidev_s g_spidev =
static int spi_lock(FAR struct spi_dev_s *dev, bool lock) static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
{ {
FAR struct lpc23xx_spidev_s *priv = (FAR struct lpc23xx_spidev_s *)dev; FAR struct lpc23xx_spidev_s *priv = (FAR struct lpc23xx_spidev_s *)dev;
int ret;
if (lock) if (lock)
{ {
/* Take the semaphore (perhaps waiting) */ /* Take the semaphore (perhaps waiting) */
while (sem_wait(&priv->exclsem) != 0) do
{ {
/* The only case that an error should occur here is if the wait was awakened ret = nxsem_wait(&priv->exclsem);
* by a signal.
/* The only case that an error should occur here is if the wait
* was awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
else else
{ {
(void)nxsem_post(&priv->exclsem); (void)nxsem_post(&priv->exclsem);
ret = OK;
} }
return OK; return ret;
} }
/**************************************************************************** /****************************************************************************
+10 -5
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/lpc31xx/lpc31_ehci.c * arch/arm/src/lpc31xx/lpc31_ehci.c
* *
* Copyright (C) 2013-2016 Gregory Nutt. All rights reserved. * Copyright (C) 2013-2017 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org> * Authors: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -1013,16 +1013,21 @@ static int ehci_wait_usbsts(uint32_t maskbits, uint32_t donebits,
static void lpc31_takesem(sem_t *sem) static void lpc31_takesem(sem_t *sem)
{ {
/* Take the semaphore (perhaps waiting) */ int ret;
while (sem_wait(sem) != 0) do
{ {
/* The only case that an error should occr here is if the wait was /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(sem);
/* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
/**************************************************************************** /****************************************************************************
+2 -2
View File
@@ -467,7 +467,7 @@ static int i2c_transfer(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs
/* Get exclusive access to the I2C bus */ /* Get exclusive access to the I2C bus */
sem_wait(&priv->mutex); nxsem_wait(&priv->mutex);
flags = enter_critical_section(); flags = enter_critical_section();
/* Set up for the transfer */ /* Set up for the transfer */
@@ -496,7 +496,7 @@ static int i2c_transfer(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs
while (priv->state != I2C_STATE_DONE) while (priv->state != I2C_STATE_DONE)
{ {
sem_wait(&priv->wait); nxsem_wait(&priv->wait);
} }
wd_cancel(priv->timeout); wd_cancel(priv->timeout);
+12 -6
View File
@@ -1,7 +1,7 @@
/************************************************************************************ /************************************************************************************
* arm/arm/src/lpc31xx/lpc31_spi.c * arm/arm/src/lpc31xx/lpc31_spi.c
* *
* Copyright (C) 2009-2010, 2012, 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2009-2010, 2012, 2016-2017 Gregory Nutt. All rights reserved.
* Author: David Hewson, deriving in part from other SPI drivers originally by * Author: David Hewson, deriving in part from other SPI drivers originally by
* Gregory Nutt <gnutt@nuttx.org> * Gregory Nutt <gnutt@nuttx.org>
* *
@@ -443,25 +443,31 @@ static inline void spi_writeword(FAR struct lpc31_spidev_s *priv, uint16_t word)
static int spi_lock(FAR struct spi_dev_s *dev, bool lock) static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
{ {
FAR struct lpc31_spidev_s *priv = (FAR struct lpc31_spidev_s *)dev; FAR struct lpc31_spidev_s *priv = (FAR struct lpc31_spidev_s *)dev;
int ret;
if (lock) if (lock)
{ {
/* Take the semaphore (perhaps waiting) */ /* Take the semaphore (perhaps waiting) */
while (sem_wait(&priv->exclsem) != 0) do
{ {
/* The only case that an error should occur here is if the wait was awakened ret = nxsem_wait(&priv->exclsem);
* by a signal.
/* The only case that an error should occur here is if the wait
* was awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
else else
{ {
(void)nxsem_post(&priv->exclsem); (void)nxsem_post(&priv->exclsem);
ret = OK;
} }
return OK;
return ret;
} }
/**************************************************************************** /****************************************************************************
+10 -5
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/lpc43xx/lpc43_ehci.c * arch/arm/src/lpc43xx/lpc43_ehci.c
* *
* Copyright (C) 2013-2016 Gregory Nutt. All rights reserved. * Copyright (C) 2013-2017 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org> * Authors: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -1004,16 +1004,21 @@ static int ehci_wait_usbsts(uint32_t maskbits, uint32_t donebits,
static void lpc43_takesem(sem_t *sem) static void lpc43_takesem(sem_t *sem)
{ {
/* Take the semaphore (perhaps waiting) */ int ret;
while (sem_wait(sem) != 0) do
{ {
/* The only case that an error should occr here is if the wait was /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(sem);
/* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
/**************************************************************************** /****************************************************************************
+3 -3
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/lpc43xx/lpc43_gpdma.c * arch/arm/src/lpc43xx/lpc43_gpdma.c
* *
* Copyright (C) 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -396,8 +396,8 @@ DMA_HANDLE lpc43_dmachannel(void)
do do
{ {
ret = sem_wait(&g_gpdma.exclsem); ret = nxsem_wait(&g_gpdma.exclsem);
DEBUGASSERT(ret == 0 || errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret < 0); while (ret < 0);
+2 -2
View File
@@ -203,7 +203,7 @@ static int lpc43_i2c_start(struct lpc43_i2cdev_s *priv)
putreg32(I2C_CONSET_STA, priv->base + LPC43_I2C_CONSET_OFFSET); putreg32(I2C_CONSET_STA, priv->base + LPC43_I2C_CONSET_OFFSET);
wd_start(priv->timeout, I2C_TIMEOUT, lpc43_i2c_timeout, 1, (uint32_t)priv); wd_start(priv->timeout, I2C_TIMEOUT, lpc43_i2c_timeout, 1, (uint32_t)priv);
sem_wait(&priv->wait); nxsem_wait(&priv->wait);
wd_cancel(priv->timeout); wd_cancel(priv->timeout);
return priv->nmsg; return priv->nmsg;
@@ -385,7 +385,7 @@ static int lpc43_i2c_transfer(FAR struct i2c_master_s *dev,
/* Get exclusive access to the I2C bus */ /* Get exclusive access to the I2C bus */
sem_wait(&priv->mutex); nxsem_wait(&priv->mutex);
/* Set up for the transfer */ /* Set up for the transfer */
+12 -6
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/lpc43xx/lpc43_spi.c * arch/arm/src/lpc43xx/lpc43_spi.c
* *
* Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. * Copyright (C) 2015-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -176,25 +176,31 @@ static struct lpc43_spidev_s g_spidev =
static int spi_lock(FAR struct spi_dev_s *dev, bool lock) static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
{ {
FAR struct lpc43_spidev_s *priv = (FAR struct lpc43_spidev_s *)dev; FAR struct lpc43_spidev_s *priv = (FAR struct lpc43_spidev_s *)dev;
int ret;
if (lock) if (lock)
{ {
/* Take the semaphore (perhaps waiting) */ /* Take the semaphore (perhaps waiting) */
while (sem_wait(&priv->exclsem) != 0) do
{ {
/* The only case that an error should occur here is if the wait was awakened ret = nxsem_wait(&priv->exclsem);
* by a signal.
/* The only case that an error should occur here is if the wait
* was awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
else else
{ {
(void)nxsem_post(&priv->exclsem); (void)nxsem_post(&priv->exclsem);
ret = OK;
} }
return OK;
return ret;
} }
/**************************************************************************** /****************************************************************************
+11 -6
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/lpc43xx/lpc43_ssp.c * arch/arm/src/lpc43xx/lpc43_ssp.c
* *
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2012, 2016-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -272,26 +272,31 @@ static inline void ssp_putreg(FAR struct lpc43_sspdev_s *priv, uint8_t offset, u
static int ssp_lock(FAR struct spi_dev_s *dev, bool lock) static int ssp_lock(FAR struct spi_dev_s *dev, bool lock)
{ {
FAR struct lpc43_sspdev_s *priv = (FAR struct lpc43_sspdev_s *)dev; FAR struct lpc43_sspdev_s *priv = (FAR struct lpc43_sspdev_s *)dev;
int ret;
if (lock) if (lock)
{ {
/* Take the semaphore (perhaps waiting) */ /* Take the semaphore (perhaps waiting) */
while (sem_wait(&priv->exclsem) != 0) do
{ {
/* The only case that an error should occur here is if the wait was awakened ret = nxsem_wait(&priv->exclsem);
* by a signal.
/* The only case that an error should occur here is if the wait
* was awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
else else
{ {
(void)nxsem_post(&priv->exclsem); (void)nxsem_post(&priv->exclsem);
ret = OK;
} }
return OK; return ret;
} }
/**************************************************************************** /****************************************************************************
+10 -5
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/sam34/sam_tc.c * arch/arm/src/sam34/sam_tc.c
* *
* Copyright (C) 2013-2016 Gregory Nutt. All rights reserved. * Copyright (C) 2013-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* References: * References:
@@ -360,16 +360,21 @@ static const uint8_t g_regoffset[TC_NREGISTERS] =
static void sam_takesem(struct sam_chan_s *chan) static void sam_takesem(struct sam_chan_s *chan)
{ {
/* Take the semaphore (perhaps waiting) */ int ret;
while (sem_wait(&chan->exclsem) != 0) do
{ {
/* The only case that an error should occr here is if the wait was /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&chan->exclsem);
/* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
/**************************************************************************** /****************************************************************************
+1 -1
View File
@@ -88,7 +88,7 @@ static sem_t lock;
static void aes_lock(void) static void aes_lock(void)
{ {
sem_wait(&lock); nxsem_wait(&lock);
} }
static void aes_unlock(void) static void aes_unlock(void)
+18 -7
View File
@@ -1,7 +1,8 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/sam34/sam_dmac.c * arch/arm/src/sam34/sam_dmac.c
* *
* Copyright (C) 2010, 2013-2014, 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2010, 2013-2014, 2016-2017 Gregory Nutt. All rights
* reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -274,16 +275,21 @@ static struct sam_dma_s g_dma[SAM34_NDMACHAN] =
static void sam_takechsem(void) static void sam_takechsem(void)
{ {
/* Take the semaphore (perhaps waiting) */ int ret;
while (sem_wait(&g_chsem) != 0) do
{ {
/* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&g_chsem);
/* The only case that an error should occur here is if the wait was /* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
static inline void sam_givechsem(void) static inline void sam_givechsem(void)
@@ -301,16 +307,21 @@ static inline void sam_givechsem(void)
static void sam_takedsem(void) static void sam_takedsem(void)
{ {
/* Take the semaphore (perhaps waiting) */ int ret;
while (sem_wait(&g_dsem) != 0) do
{ {
/* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&g_dsem);
/* The only case that an error should occur here is if the wait was /* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
static inline void sam_givedsem(void) static inline void sam_givedsem(void)
+9 -4
View File
@@ -591,16 +591,21 @@ static bool g_cmdinitialized;
static void sam_takesem(struct sam_dev_s *priv) static void sam_takesem(struct sam_dev_s *priv)
{ {
/* Take the semaphore (perhaps waiting) */ int ret;
while (sem_wait(&priv->waitsem) != 0) do
{ {
/* The only case that an error should occr here is if the wait was /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&priv->waitsem);
/* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
/**************************************************************************** /****************************************************************************
+21 -19
View File
@@ -1,7 +1,8 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/sam34/sam_spi.c * arch/arm/src/sam34/sam_spi.c
* *
* Copyright (C) 2011, 2013-2014, 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2011, 2013-2014, 2016-2017 Gregory Nutt. All rights
* reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org> * Authors: Gregory Nutt <gnutt@nuttx.org>
* Diego Sanchez <dsanchez@nx-engineering.com> * Diego Sanchez <dsanchez@nx-engineering.com>
* *
@@ -876,27 +877,34 @@ static int spi_lock(struct spi_dev_s *dev, bool lock)
{ {
struct sam_spics_s *spics = (struct sam_spics_s *)dev; struct sam_spics_s *spics = (struct sam_spics_s *)dev;
struct sam_spidev_s *spi = spi_device(spics); struct sam_spidev_s *spi = spi_device(spics);
int ret;
spiinfo("lock=%d\n", lock); spiinfo("lock=%d\n", lock);
if (lock) if (lock)
{ {
/* Take the semaphore (perhaps waiting) */ /* Take the semaphore (perhaps waiting) */
while (sem_wait(&spi->spisem) != 0) do
{ {
/* The only case that an error should occur here is if the wait was awakened /* Take the semaphore (perhaps waiting) */
* by a signal.
ret = nxsem_wait(&spi->spisem);
/* The only case that an error should occur here is if the wait was
* awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
else else
{ {
(void)nxsem_post(&spi->spisem); (void)nxsem_post(&spi->spisem);
ret = OK;
} }
return OK; return ret;
} }
/**************************************************************************** /****************************************************************************
@@ -1589,26 +1597,20 @@ static void spi_exchange(struct spi_dev_s *dev, const void *txbuffer,
/* Wait for the DMA complete */ /* Wait for the DMA complete */
ret = sem_wait(&spics->dmawait); ret = nxsem_wait(&spics->dmawait);
/* Cancel the watchdog timeout */ /* Cancel the watchdog timeout */
(void)wd_cancel(spics->dmadog); (void)wd_cancel(spics->dmadog);
/* Check if we were awakened by an error of some kind */ /* Check if we were awakened by an error of some kind. EINTR is not a
* failure. It simply means that the wait was awakened by a signal.
*/
if (ret < 0) if (ret < 0 && ret != -EINTR)
{ {
/* EINTR is not a failure. That simply means that the wait DEBUGPANIC();
* was awakened by a signal. return;
*/
int errorcode = errno;
if (errorcode != EINTR)
{
DEBUGPANIC();
return;
}
} }
/* Not that we might be awakened before the wait is over due to /* Not that we might be awakened before the wait is over due to
+10 -5
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/sam34/sam_twi.c * arch/arm/src/sam34/sam_twi.c
* *
* Copyright (C) 2013, 2015-2016 Gregory Nutt. All rights reserved. * Copyright (C) 2013, 2015-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* References: * References:
@@ -225,16 +225,21 @@ static const struct i2c_ops_s g_twiops =
static void twi_takesem(sem_t *sem) static void twi_takesem(sem_t *sem)
{ {
/* Take the semaphore (perhaps waiting) */ int ret;
while (sem_wait(sem) != 0) do
{ {
/* The only case that an error should occr here is if the wait was /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(sem);
/* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
/**************************************************************************** /****************************************************************************
+3 -3
View File
@@ -2152,15 +2152,15 @@ void sam_adc_lock(FAR struct sam_adc_s *priv)
do do
{ {
ret = sem_wait(&priv->exclsem); ret = nxsem_wait(&priv->exclsem);
/* This should only fail if the wait was canceled by an signal /* This should only fail if the wait was canceled by an signal
* (and the worker thread will receive a lot of signals). * (and the worker thread will receive a lot of signals).
*/ */
DEBUGASSERT(ret == OK || errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret < 0); while (ret == -EINTR);
} }
/**************************************************************************** /****************************************************************************
+4 -4
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/sama5/sam_can.c * arch/arm/src/sama5/sam_can.c
* *
* Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. * Copyright (C) 2013-2014, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* References: * References:
@@ -567,10 +567,10 @@ static void can_semtake(FAR struct sam_can_s *priv)
do do
{ {
ret = sem_wait(&priv->exclsem); ret = nxsem_wait(&priv->exclsem);
DEBUGASSERT(ret == 0 || errno == EINTR); DEBUGASSERT(ret == 0 || ret == -EINTR);
} }
while (ret < 0); while (ret == -EINTR);
} }
/**************************************************************************** /****************************************************************************
+17 -7
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/sama5/sam3u_dmac.c * arch/arm/src/sama5/sam3u_dmac.c
* *
* Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2013, 2016-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -487,16 +487,21 @@ static struct sam_dmac_s g_dmac1 =
static void sam_takechsem(struct sam_dmac_s *dmac) static void sam_takechsem(struct sam_dmac_s *dmac)
{ {
/* Take the semaphore (perhaps waiting) */ int ret;
while (sem_wait(&dmac->chsem) != 0) do
{ {
/* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&dmac->chsem);
/* The only case that an error should occur here is if the wait was /* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
static inline void sam_givechsem(struct sam_dmac_s *dmac) static inline void sam_givechsem(struct sam_dmac_s *dmac)
@@ -514,16 +519,21 @@ static inline void sam_givechsem(struct sam_dmac_s *dmac)
static void sam_takedsem(struct sam_dmac_s *dmac) static void sam_takedsem(struct sam_dmac_s *dmac)
{ {
/* Take the semaphore (perhaps waiting) */ int ret;
while (sem_wait(&dmac->dsem) != 0) do
{ {
/* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&dmac->dsem);
/* The only case that an error should occur here is if the wait was /* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
static inline void sam_givedsem(struct sam_dmac_s *dmac) static inline void sam_givedsem(struct sam_dmac_s *dmac)
+10 -5
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/sama5/sam_ehci.c * arch/arm/src/sama5/sam_ehci.c
* *
* Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2013, 2016-2017 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org> * Authors: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -815,16 +815,21 @@ static int ehci_wait_usbsts(uint32_t maskbits, uint32_t donebits,
static void sam_takesem(sem_t *sem) static void sam_takesem(sem_t *sem)
{ {
/* Take the semaphore (perhaps waiting) */ int ret;
while (sem_wait(sem) != 0) do
{ {
/* The only case that an error should occr here is if the wait was /* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(sem);
/* The only case that an error should occur here is if the wait was
* awakened by a signal. * awakened by a signal.
*/ */
ASSERT(errno == EINTR); DEBUGASSERT(ret == OK || ret == -EINTR);
} }
while (ret == -EINTR);
} }
/**************************************************************************** /****************************************************************************

Some files were not shown because too many files have changed in this diff Show More