mutex.h 2.9 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: mutex.h,v $
  40. * Revision 1.4 2005/12/22 09:36:25 freckle
  41. * added missing prototype for NutMutexDestroy
  42. *
  43. * Revision 1.3 2005/08/02 17:46:49 haraldkipp
  44. * Major API documentation update.
  45. *
  46. * Revision 1.2 2004/05/18 18:38:14 drsung
  47. * Added $Log keyword for CVS and avoid multiple inclusion of header file.
  48. *
  49. */
  50. #ifndef _SYS_MUTEX_H
  51. #define _SYS_MUTEX_H
  52. #include <sys/types.h>
  53. #include <sys/thread.h>
  54. /*!
  55. * \addtogroup xgMutex
  56. */
  57. /*@{*/
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. /*!
  62. * \brief Recursive mutex type.
  63. */
  64. typedef struct _MUTEX MUTEX;
  65. /*!
  66. * \struct _mutex mutex.h sys/mutex.h
  67. * \brief Recursive mutex.
  68. *
  69. */
  70. struct _MUTEX {
  71. HANDLE qhp; /*!< \brief Queue to wait, if mutex is not free. */
  72. NUTTHREADINFO *thread; /*!< \brief Thread who owns the mutex */
  73. u_short count; /*!< \brief Lock counter. */
  74. };
  75. extern void NutMutexInit(MUTEX * mutex);
  76. extern void NutMutexLock(MUTEX * mutex);
  77. extern int NutMutexUnlock(MUTEX * mutex);
  78. extern int NutMutexTrylock(MUTEX * mutex);
  79. extern int NutMutexDestroy(MUTEX * mutex);
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. /*@}*/
  84. #endif /* #ifndef _SYS_MUTEX_H */