mutex.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. /* mutex.c - a nut/os implementation of recursive mutex functions
  34. *
  35. * 2004.05.06 Matthias Ringwald <matthias.ringwald@inf.ethz.ch>
  36. *
  37. */
  38. /*
  39. * $Log$
  40. * Revision 1.6 2008/08/11 07:00:26 haraldkipp
  41. * BSD types replaced by stdint types (feature request #1282721).
  42. *
  43. * Revision 1.5 2007/08/29 07:43:54 haraldkipp
  44. * Documentation updated and corrected.
  45. *
  46. * Revision 1.4 2005/12/22 09:36:25 freckle
  47. * added missing prototype for NutMutexDestroy
  48. *
  49. * Revision 1.3 2005/08/02 17:46:49 haraldkipp
  50. * Major API documentation update.
  51. *
  52. * Revision 1.2 2004/05/18 18:38:14 drsung
  53. * Added $Log keyword for CVS and avoid multiple inclusion of header file.
  54. *
  55. */
  56. #ifndef _SYS_MUTEX_H
  57. #define _SYS_MUTEX_H
  58. #include <compiler.h>
  59. #include <sys/types.h>
  60. #include <sys/thread.h>
  61. /*!
  62. * \addtogroup xgMutex
  63. */
  64. /*@{*/
  65. /*!
  66. * \brief Recursive mutex type.
  67. */
  68. typedef struct _MUTEX MUTEX;
  69. /*!
  70. * \struct _MUTEX mutex.h sys/mutex.h
  71. * \brief Recursive mutex.
  72. *
  73. */
  74. struct _MUTEX {
  75. HANDLE qhp; /*!< \brief Queue to wait, if mutex is not free. */
  76. NUTTHREADINFO *thread; /*!< \brief Thread who owns the mutex */
  77. uint16_t count; /*!< \brief Lock counter. */
  78. };
  79. extern void NutMutexInit(MUTEX * mutex);
  80. extern void NutMutexLock(MUTEX * mutex);
  81. extern int NutMutexUnlock(MUTEX * mutex);
  82. extern int NutMutexTrylock(MUTEX * mutex);
  83. extern int NutMutexDestroy(MUTEX * mutex);
  84. /*@}*/
  85. #endif /* #ifndef _SYS_MUTEX_H */