Add a simple named semaphore test to the OS test

This commit is contained in:
Gregory Nutt
2014-09-28 13:02:36 -06:00
parent 8a6a202c6d
commit aed3fe045e
2 changed files with 32 additions and 21 deletions
+21 -19
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* include/nuttx/fs/fs.h * include/nuttx/fs/fs.h
* *
* Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2011-2013 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,7 +48,9 @@
#include <stdbool.h> #include <stdbool.h>
#include <semaphore.h> #include <semaphore.h>
#include <nuttx/semaphore.h> #ifdef CONFIG_FS_NAMED_SEMAPHORES
# include <nuttx/semaphore.h>
#endif
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
@@ -203,28 +205,25 @@ struct mountpt_operations
/* Named OS resources are also maintained by the VFS. This includes: /* Named OS resources are also maintained by the VFS. This includes:
* *
* - Named semaphores: sem_open(), sem_close(), and sem_unlink() * - Named semaphores: sem_open(), sem_close(), and sem_unlink()
* - POSIX Message Queues: mq_open(), mq_close(), and mq_unlink() * - POSIX Message Queues: mq_open() and mq_close()
* - Shared memory: shm_open() and shm_unlink(); * - Shared memory: shm_open() and shm_unlink();
* *
* These are a special case in that they do not follow the same pattern * These are a special case in that they do not follow quite the same
* as the other inode system types: * pattern as the other file system types in that they have no read or
* write methods.
* *
* - All of these resources have their own open() and unlink() interfaces. * Each inode type carries a payload specific to the OS resource;
* All require special, additional operations at open() and unlink() * Only the contents of struct special_operations is visible to the VFS.
* time
* - None of the standard VFS operations can be used with semaphores
* or named messages queues. These OS resources have their own
* own open() and close methods that do not use file descriptors.
* - Only ftruncate() and close() make sense with the file descriptor
* returned by shm_open()
*
* Inode types are not defined here, but rather in:
*
* - include/nuttx/semaphore.h
* - include/nuttx/mqueue.h, and
* - include/nuttx/shm.h
*/ */
struct inode;
struct special_operations
{
int (*open)(FAR struct inode *inode);
int (*close)(FAR struct inode *inode);
int (*unlink)(FAR struct inode *inode, FAR const char *relpath);
};
/* These are the various kinds of operations that can be associated with /* These are the various kinds of operations that can be associated with
* an inode. * an inode.
*/ */
@@ -236,7 +235,10 @@ union inode_ops_u
FAR const struct block_operations *i_bops; /* Block driver operations */ FAR const struct block_operations *i_bops; /* Block driver operations */
FAR const struct mountpt_operations *i_mops; /* Operations on a mountpoint */ FAR const struct mountpt_operations *i_mops; /* Operations on a mountpoint */
#endif #endif
FAR const struct special_operations *i_xops; /* Generic operations on OS resources */
#ifdef CONFIG_FS_NAMED_SEMAPHORES
FAR const struct semaphore_operations *i_sops; /* Operations for named semaphores */ FAR const struct semaphore_operations *i_sops; /* Operations for named semaphores */
#endif
}; };
/* This structure represents one inode in the Nuttx pseudo-file system */ /* This structure represents one inode in the Nuttx pseudo-file system */
+11 -2
View File
@@ -54,15 +54,24 @@
* Public Data * Public Data
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_FS_NAMED_SEMAPHORES
/* This is the named semaphore inode */ /* This is the named semaphore inode */
struct inode; /* Forward reference */
struct semaphore_operations struct semaphore_operations
{ {
/* Common inode operations */
int (*open)(FAR struct inode *inode);
int (*close)(FAR struct inode *inode);
int (*unlink)(FAR struct inode *inode, FAR const char *relpath);
/* Payload unique to named semaphores */ /* Payload unique to named semaphores */
uint16_t ns_refs; /* Number of open references to the semaphore */ uint16_t ns_refs; /* Number of open references semaphore */
sem_t ns_sem; /* The semaphore itself */ sem_t ns_sem; /* The semaphore itself */
}; };
#endif
/**************************************************************************** /****************************************************************************
* Public Data * Public Data