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
+21 -11
View File
@@ -229,16 +229,21 @@ static const struct file_operations g_tun_file_ops =
static void tundev_lock(FAR struct tun_driver_s *tun)
{
/* Take the semaphore (perhaps waiting) */
int ret;
while (sem_wait(&tun->waitsem) != 0)
do
{
/* The only case that an error should occur here is if
* the wait was awakened by a signal.
/* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(&tun->waitsem);
/* 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);
}
/****************************************************************************
@@ -256,16 +261,21 @@ static void tundev_unlock(FAR struct tun_driver_s *tun)
static void tun_lock(FAR struct tun_device_s *priv)
{
/* Take the semaphore (perhaps waiting) */
int ret;
while (sem_wait(&priv->waitsem) != 0)
do
{
/* The only case that an error should occur here is if
* the wait was awakened by a signal.
/* 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.
*/
ASSERT(errno == EINTR);
DEBUGASSERT(ret == OK || ret == -EINTR);
}
while (ret == -EINTR);
}
/****************************************************************************
@@ -1076,7 +1086,7 @@ static ssize_t tun_read(FAR struct file *filep, FAR char *buffer,
priv->read_wait = true;
tun_unlock(priv);
sem_wait(&priv->read_wait_sem);
(void)nxsem_wait(&priv->read_wait_sem);
tun_lock(priv);
}