semaphore.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (C) 2000-2004 by ETH Zurich
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the copyright holders nor the names of
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY ETH ZURICH AND CONTRIBUTORS
  18. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  20. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ETH ZURICH
  21. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  24. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  25. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  27. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. *
  30. * For additional information see http://www.ethernut.de/
  31. *
  32. */
  33. /* sempahore.h - a nut/os implementation of semaphore functions
  34. *
  35. * 2004.05.06 Matthias Ringwald <matthias.ringwald@inf.ethz.ch>
  36. *
  37. */
  38. /*
  39. * $Log$
  40. * Revision 1.5 2007/08/29 07:43:54 haraldkipp
  41. * Documentation updated and corrected.
  42. *
  43. * Revision 1.4 2005/08/02 17:46:49 haraldkipp
  44. * Major API documentation update.
  45. *
  46. * Revision 1.3 2004/06/02 16:43:36 olereinhardt
  47. * fixed bug (integer overflow) in semaphore implementation
  48. *
  49. * Revision 1.2 2004/05/18 18:38:14 drsung
  50. * Added $Log keyword for CVS and avoid multiple inclusion of header file.
  51. *
  52. */
  53. #ifndef _SYS_SEMAPHORE_H
  54. #define _SYS_SEMAPHORE_H
  55. #include <compiler.h>
  56. #include <sys/types.h>
  57. #include <sys/thread.h>
  58. /*!
  59. * \addtogroup xgSemaphore
  60. */
  61. /*@{*/
  62. /*!
  63. * \brief Sempahore type.
  64. */
  65. typedef struct _SEM SEM;
  66. /*!
  67. * \struct _SEM semaphore.h sys/semaphore.h
  68. * \brief Semaphore.
  69. *
  70. */
  71. struct _SEM {
  72. HANDLE qhp; /*!< \brief Queue to wait, if semaphore is zero. */
  73. short value; /*!< \brief semaphore value . */
  74. };
  75. extern void NutSemInit(SEM * sem, short value);
  76. extern void NutSemWait(SEM * sem);
  77. extern int NutSemTryWait(SEM * sem);
  78. extern void NutSemPost(SEM * sem);
  79. extern int NutSemDestroy(SEM * sem);
  80. /*@}*/
  81. #endif /* #ifndef _SYS_SEMAPHORE_H */