mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 09:49:21 +08:00
Seems to work okay now, but needs more testing
This commit is contained in:
parent
650a0d0615
commit
999cc5ef8b
2 changed files with 89 additions and 11 deletions
|
@ -44,6 +44,7 @@
|
|||
#include <sched.h>
|
||||
#include <queue.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
|
||||
|
@ -138,20 +139,19 @@ int sem_unlink(FAR const char *name)
|
|||
goto errout_with_semaphore;
|
||||
}
|
||||
|
||||
/* Mark the inode as deleted */
|
||||
|
||||
inode->i_flags |= FSNODEFLAG_DELETED;
|
||||
|
||||
/* Remove the old inode from the tree. Because we hold a reference count
|
||||
* on the inode, it will not be deleted now.
|
||||
* on the inode, it will not be deleted now. This will set the
|
||||
* FSNODEFLAG_DELETED bit in the inode flags.
|
||||
*/
|
||||
|
||||
ret = inode_remove(fullpath);
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = -ret;
|
||||
goto errout_with_semaphore;
|
||||
}
|
||||
|
||||
/* inode_remove() should always fail with -EBUSY because we hae a reference
|
||||
* on the inode. -EBUSY means taht the inode was, indeed, unlinked but
|
||||
* thatis could not be freed because there are refrences.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(ret >= 0 || ret == -EBUSY);
|
||||
|
||||
/* Now we do not release the reference count in the normal way (by calling
|
||||
* inode release. Rather, we call sem_close(). sem_close will decrement
|
||||
|
@ -160,7 +160,8 @@ int sem_unlink(FAR const char *name)
|
|||
* that can only occur if the semaphore is not in-use.
|
||||
*/
|
||||
|
||||
return sem_close((FAR sem_t *)&inode->u.i_nsem);
|
||||
inode_semgive();
|
||||
return sem_close((FAR sem_t *)inode->u.i_nsem);
|
||||
|
||||
errout_with_semaphore:
|
||||
inode_semgive();
|
||||
|
|
77
fs/semaphore/semaphore.h
Normal file
77
fs/semaphore/semaphore.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
/****************************************************************************
|
||||
* fs/semaphore/semaphore.h
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __FS_SEMAPHORE_SEMAPHORE_H
|
||||
#define __FS_SEMAPHORE_SEMAPHORE_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define MAX_SEMPATH 64
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __FS_SEMAPHORE_SEMAPHORE_H */
|
||||
|
Loading…
Reference in a new issue