More cancellation points.

This commit is contained in:
Gregory Nutt
2016-12-09 13:49:36 -06:00
parent d20265164e
commit 3eba0acb1c
10 changed files with 151 additions and 77 deletions
+14 -2
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* fs/vfs/fs_close.c * fs/vfs/fs_close.c
* *
* Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2012, 2016 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
@@ -42,6 +42,8 @@
#include <unistd.h> #include <unistd.h>
#include <sched.h> #include <sched.h>
#include <errno.h> #include <errno.h>
#include <nuttx/pthread.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 #if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
@@ -82,7 +84,13 @@ int close(int fd)
int errcode; int errcode;
#if CONFIG_NFILE_DESCRIPTORS > 0 #if CONFIG_NFILE_DESCRIPTORS > 0
int ret; int ret;
#endif
/* close() is a cancellation point */
enter_cancellation_point();
#if CONFIG_NFILE_DESCRIPTORS > 0
/* Did we get a valid file descriptor? */ /* Did we get a valid file descriptor? */
if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS) if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS)
@@ -93,7 +101,9 @@ int close(int fd)
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 #if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS)) if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS))
{ {
return net_close(fd); ret = net_close(fd);
leave_cancellation_point();
return ret;
} }
else else
#endif #endif
@@ -123,11 +133,13 @@ int close(int fd)
goto errout; goto errout;
} }
leave_cancellation_point();
return OK; return OK;
#endif #endif
errout: errout:
set_errno(errcode); set_errno(errcode);
leave_cancellation_point();
return ERROR; return ERROR;
} }
+10 -10
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* fs/vfs/fs_fcntl.c * fs/vfs/fs_fcntl.c
* *
* Copyright (C) 2009, 2012-2014 Gregory Nutt. All rights reserved. * Copyright (C) 2009, 2012-2014, 2016 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
@@ -44,20 +44,13 @@
#include <errno.h> #include <errno.h>
#include <assert.h> #include <assert.h>
#include <nuttx/sched.h>
#include <nuttx/pthread.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
#include <nuttx/net/net.h> #include <nuttx/net/net.h>
#include <nuttx/sched.h>
#include "inode/inode.h" #include "inode/inode.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@@ -228,6 +221,10 @@ int fcntl(int fd, int cmd, ...)
va_list ap; va_list ap;
int ret; int ret;
/* fcntl() is a cancellation point */
enter_cancellation_point();
/* Setup to access the variable argument list */ /* Setup to access the variable argument list */
va_start(ap, cmd); va_start(ap, cmd);
@@ -244,6 +241,8 @@ int fcntl(int fd, int cmd, ...)
{ {
/* The errno value has already been set */ /* The errno value has already been set */
va_end(ap);
leave_cancellation_point();
return ERROR; return ERROR;
} }
@@ -273,5 +272,6 @@ int fcntl(int fd, int cmd, ...)
} }
va_end(ap); va_end(ap);
leave_cancellation_point();
return ret; return ret;
} }
+12 -3
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* fs/vfs/fs_fsync.c * fs/vfs/fs_fsync.c
* *
* Copyright (C) 2007-2009, 2013-2014 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2013-2014, 2016 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
@@ -44,8 +44,9 @@
#include <errno.h> #include <errno.h>
#include <assert.h> #include <assert.h>
#include <nuttx/fs/fs.h>
#include <nuttx/sched.h> #include <nuttx/sched.h>
#include <nuttx/pthread.h>
#include <nuttx/fs/fs.h>
#include "inode/inode.h" #include "inode/inode.h"
@@ -117,6 +118,11 @@ errout:
int fsync(int fd) int fsync(int fd)
{ {
FAR struct file *filep; FAR struct file *filep;
int ret;
/* fsync() is a cancellation point */
enter_cancellation_point();
/* Get the file structure corresponding to the file descriptor. */ /* Get the file structure corresponding to the file descriptor. */
@@ -125,12 +131,15 @@ int fsync(int fd)
{ {
/* The errno value has already been set */ /* The errno value has already been set */
leave_cancellation_point();
return ERROR; return ERROR;
} }
/* Perform the fsync operation */ /* Perform the fsync operation */
return file_fsync(filep); ret = file_fsync(filep);
leave_cancellation_point();
return ret;
} }
#endif /* !CONFIG_DISABLE_MOUNTPOINT */ #endif /* !CONFIG_DISABLE_MOUNTPOINT */
+10 -5
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* fs/vfs/fs_open.c * fs/vfs/fs_open.c
* *
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2011-2012, 2016 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
@@ -48,15 +48,12 @@
#include <stdarg.h> #include <stdarg.h>
#endif #endif
#include <nuttx/pthread.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
#include "inode/inode.h" #include "inode/inode.h"
#include "driver/driver.h" #include "driver/driver.h"
/****************************************************************************
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@@ -106,6 +103,10 @@ int open(const char *path, int oflags, ...)
# warning "File creation not implemented" # warning "File creation not implemented"
# endif # endif
/* open() is a cancellation point */
enter_cancellation_point();
/* If the file is opened for creation, then get the mode bits */ /* If the file is opened for creation, then get the mode bits */
if ((oflags & (O_WRONLY | O_CREAT)) != 0) if ((oflags & (O_WRONLY | O_CREAT)) != 0)
@@ -159,6 +160,7 @@ int open(const char *path, int oflags, ...)
/* Return the file descriptor */ /* Return the file descriptor */
leave_cancellation_point();
return fd; return fd;
} }
else else
@@ -204,6 +206,7 @@ int open(const char *path, int oflags, ...)
{ {
/* The errno value has already been set */ /* The errno value has already been set */
leave_cancellation_point();
return ERROR; return ERROR;
} }
@@ -264,6 +267,7 @@ int open(const char *path, int oflags, ...)
} }
#endif #endif
leave_cancellation_point();
return fd; return fd;
errout_with_fd: errout_with_fd:
@@ -272,5 +276,6 @@ errout_with_inode:
inode_release(inode); inode_release(inode);
errout: errout:
set_errno(ret); set_errno(ret);
leave_cancellation_point();
return ERROR; return ERROR;
} }
+16 -9
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* fs/vfs/fs_pread.c * fs/vfs/fs_pread.c
* *
* Copyright (C) 2014 Gregory Nutt. All rights reserved. * Copyright (C) 2014, 2016 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
@@ -43,12 +43,9 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <nuttx/pthread.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
/****************************************************************************
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@@ -144,6 +141,11 @@ ssize_t file_pread(FAR struct file *filep, FAR void *buf, size_t nbytes,
ssize_t pread(int fd, FAR void *buf, size_t nbytes, off_t offset) ssize_t pread(int fd, FAR void *buf, size_t nbytes, off_t offset)
{ {
FAR struct file *filep; FAR struct file *filep;
ssize_t ret;
/* pread() is a cancellation point */
enter_cancellation_point();
/* Get the file structure corresponding to the file descriptor. */ /* Get the file structure corresponding to the file descriptor. */
@@ -152,10 +154,15 @@ ssize_t pread(int fd, FAR void *buf, size_t nbytes, off_t offset)
{ {
/* The errno value has already been set */ /* The errno value has already been set */
return (ssize_t)ERROR; ret = (ssize_t)ERROR;
}
else
{
/* Let file_pread do the real work */
ret = file_pread(filep, buf, nbytes, offset);
} }
/* Let file_pread do the real work */ leave_cancellation_point();
return ret;
return file_pread(filep, buf, nbytes, offset);
} }
+16 -9
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* fs/vfs/fs_pwrite.c * fs/vfs/fs_pwrite.c
* *
* Copyright (C) 2014 Gregory Nutt. All rights reserved. * Copyright (C) 2014, 2016 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
@@ -43,12 +43,9 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <nuttx/pthread.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
/****************************************************************************
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@@ -142,6 +139,11 @@ ssize_t file_pwrite(FAR struct file *filep, FAR const void *buf,
ssize_t pwrite(int fd, FAR const void *buf, size_t nbytes, off_t offset) ssize_t pwrite(int fd, FAR const void *buf, size_t nbytes, off_t offset)
{ {
FAR struct file *filep; FAR struct file *filep;
ssize_t ret;
/* pread() is a cancellation point */
enter_cancellation_point();
/* Get the file structure corresponding to the file descriptor. */ /* Get the file structure corresponding to the file descriptor. */
@@ -150,10 +152,15 @@ ssize_t pwrite(int fd, FAR const void *buf, size_t nbytes, off_t offset)
{ {
/* The errno value has already been set */ /* The errno value has already been set */
return (ssize_t)ERROR; ret = (ssize_t)ERROR;
}
else
{
/* Let file_pread do the real work */
ret = file_pwrite(filep, buf, nbytes, offset);
} }
/* Let file_pread do the real work */ enter_cancellation_point();
return ret;
return file_pwrite(filep, buf, nbytes, offset);
} }
+29 -16
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* fs/vfs/fs_read.c * fs/vfs/fs_read.c
* *
* Copyright (C) 2007-2009, 2012-2014 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2012-2014, 2016 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
@@ -38,19 +38,17 @@
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <sched.h> #include <sched.h>
#include <errno.h> #include <errno.h>
#include "inode/inode.h" #include <nuttx/pthread.h>
/**************************************************************************** #include "inode/inode.h"
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
@@ -136,23 +134,30 @@ ssize_t file_read(FAR struct file *filep, FAR void *buf, size_t nbytes)
ssize_t read(int fd, FAR void *buf, size_t nbytes) ssize_t read(int fd, FAR void *buf, size_t nbytes)
{ {
ssize_t ret;
/* read() is a cancellation point */
enter_cancellation_point();
/* Did we get a valid file descriptor? */ /* Did we get a valid file descriptor? */
#if CONFIG_NFILE_DESCRIPTORS > 0 #if CONFIG_NFILE_DESCRIPTORS > 0
if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS) if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS)
#endif #endif
{ {
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
/* No.. If networking is enabled, read() is the same as recv() with /* No.. If networking is enabled, read() is the same as recv() with
* the flags parameter set to zero. * the flags parameter set to zero. Note that recv() sets
* the errno variable.
*/ */
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 ret = recv(fd, buf, nbytes, 0);
return recv(fd, buf, nbytes, 0);
#else #else
/* No networking... it is a bad descriptor in any event */ /* No networking... it is a bad descriptor in any event */
set_errno(EBADF); set_errno(EBADF);
return ERROR; ret = ERROR;
#endif #endif
} }
@@ -162,20 +167,28 @@ ssize_t read(int fd, FAR void *buf, size_t nbytes)
FAR struct file *filep; FAR struct file *filep;
/* The descriptor is in a valid range to file descriptor... do the /* The descriptor is in a valid range to file descriptor... do the
* read. First, get the file structure. * read. First, get the file structure. Note that on failure,
* fs_getfilep() will set the errno variable.
*/ */
filep = fs_getfilep(fd); filep = fs_getfilep(fd);
if (!filep) if (filep == NULL)
{ {
/* The errno value has already been set */ /* The errno value has already been set */
return ERROR; ret = ERROR;
} }
else
{
/* Then let file_read do all of the work. Note that file_read()
* sets the errno variable.
*/
/* Then let file_read do all of the work */ ret = file_read(filep, buf, nbytes);
}
return file_read(filep, buf, nbytes);
} }
#endif #endif
leave_cancellation_point();
return ret;
} }
+39 -22
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* fs/vfs/fs_write.c * fs/vfs/fs_write.c
* *
* Copyright (C) 2007-2009, 2012-2014 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2012-2014, 2016 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
@@ -38,6 +38,7 @@
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
@@ -49,11 +50,9 @@
# include <sys/socket.h> # include <sys/socket.h>
#endif #endif
#include "inode/inode.h" #include <nuttx/pthread.h>
/**************************************************************************** #include "inode/inode.h"
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
@@ -72,7 +71,7 @@
ssize_t file_write(FAR struct file *filep, FAR const void *buf, size_t nbytes) ssize_t file_write(FAR struct file *filep, FAR const void *buf, size_t nbytes)
{ {
FAR struct inode *inode; FAR struct inode *inode;
int ret; ssize_t ret;
int errcode; int errcode;
/* Was this file opened for write access? */ /* Was this file opened for write access? */
@@ -163,6 +162,11 @@ ssize_t write(int fd, FAR const void *buf, size_t nbytes)
#if CONFIG_NFILE_DESCRIPTORS > 0 #if CONFIG_NFILE_DESCRIPTORS > 0
FAR struct file *filep; FAR struct file *filep;
#endif #endif
ssize_t ret;
/* write() is a cancellation point */
enter_cancellation_point();
/* Did we get a valid file descriptor? */ /* Did we get a valid file descriptor? */
@@ -170,31 +174,44 @@ ssize_t write(int fd, FAR const void *buf, size_t nbytes)
if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS) if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS)
#endif #endif
{ {
/* Write to a socket descriptor is equivalent to send with flags == 0 */
#if defined(CONFIG_NET_TCP) && CONFIG_NSOCKET_DESCRIPTORS > 0 #if defined(CONFIG_NET_TCP) && CONFIG_NSOCKET_DESCRIPTORS > 0
return send(fd, buf, nbytes, 0); /* Write to a socket descriptor is equivalent to send with flags == 0.
* Note that send() will set the errno on failure.
*/
ret = send(fd, buf, nbytes, 0);
#else #else
set_errno(EBADF); set_errno(EBADF);
return ERROR; ret = ERROR ERROR;
#endif #endif
} }
#if CONFIG_NFILE_DESCRIPTORS > 0 #if CONFIG_NFILE_DESCRIPTORS > 0
/* The descriptor is in the right range to be a file descriptor... write else
* to the file.
*/
filep = fs_getfilep(fd);
if (!filep)
{ {
/* The errno value has already been set */ /* The descriptor is in the right range to be a file descriptor..
* write to the file. Note that fs_getfilep() will set the errno on
* failure.
*/
return ERROR; filep = fs_getfilep(fd);
if (filep == NULL)
{
/* The errno value has already been set */
ret = ERROR;
}
else
{
/* Perform the write operation using the file descriptor as an
* index. Note that file_write() will set the errno on failure.
*/
ret = file_write(filep, buf, nbytes);
}
#endif
} }
/* Perform the write operation using the file descriptor as an index */ leave_cancellation_point();
return ret;
return file_write(filep, buf, nbytes);
#endif
} }
+4
View File
@@ -81,6 +81,10 @@
pid_t wait(FAR int *stat_loc) pid_t wait(FAR int *stat_loc)
{ {
/* wait() is a cancellation point, but nothings needs to be done for this
* trivial case.
*/
return waitpid((pid_t)-1, stat_loc, 0); return waitpid((pid_t)-1, stat_loc, 0);
} }
+1 -1
View File
@@ -146,7 +146,7 @@ static inline void task_onexit(FAR struct tcb_s *tcb, int status)
* We must not call the registered function in supervisor mode! See also * We must not call the registered function in supervisor mode! See also
* atexit() and pthread_cleanup_pop() callbacks. * atexit() and pthread_cleanup_pop() callbacks.
* *
* REVISIT: In the case of task_delete(), the callback would execute in * REVISIT: In the case of task_delete(), the callback would execute in
* he context the caller of task_delete() cancel, not in the context of * he context the caller of task_delete() cancel, not in the context of
* the exiting task (or process). * the exiting task (or process).
*/ */