db_events.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /* Copyright (C) 2014 OSCAR lab, Stony Brook University
  4. This file is part of Graphene Library OS.
  5. Graphene Library OS is free software: you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation, either version 3 of the
  8. License, or (at your option) any later version.
  9. Graphene Library OS is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. /*
  16. * db_event.c
  17. *
  18. * This file contains implementation of Drawbridge event synchronization APIs.
  19. */
  20. #include "pal_defs.h"
  21. #include "pal.h"
  22. #include "pal_internal.h"
  23. #include "pal_error.h"
  24. #include "api.h"
  25. PAL_HANDLE DkNotificationEventCreate (PAL_BOL initialState)
  26. {
  27. ENTER_PAL_CALL(DkNotificationEventCreate);
  28. PAL_HANDLE handle = NULL;
  29. int ret = _DkEventCreate(&handle, initialState, true);
  30. if (ret < 0) {
  31. _DkRaiseFailure(-ret);
  32. handle = NULL;
  33. }
  34. LEAVE_PAL_CALL_RETURN(handle);
  35. }
  36. PAL_HANDLE DkSynchronizationEventCreate (PAL_BOL initialState)
  37. {
  38. ENTER_PAL_CALL(DkSynchronizationEventCreate);
  39. PAL_HANDLE handle = NULL;
  40. int ret = _DkEventCreate(&handle, initialState, false);
  41. if (ret < 0) {
  42. _DkRaiseFailure(-ret);
  43. handle = NULL;
  44. }
  45. LEAVE_PAL_CALL_RETURN(handle);
  46. }
  47. void DkEventDestroy (PAL_HANDLE handle)
  48. {
  49. ENTER_PAL_CALL(DkEventDestroy);
  50. if (!handle || !IS_HANDLE_TYPE(handle, event)) {
  51. _DkRaiseFailure(PAL_ERROR_INVAL);
  52. LEAVE_PAL_CALL();
  53. }
  54. _DkEventDestroy(handle);
  55. LEAVE_PAL_CALL();
  56. }
  57. void DkEventSet (PAL_HANDLE handle)
  58. {
  59. ENTER_PAL_CALL(DkEventSet);
  60. if (!handle || !IS_HANDLE_TYPE(handle, event)) {
  61. _DkRaiseFailure(PAL_ERROR_INVAL);
  62. LEAVE_PAL_CALL();
  63. }
  64. int ret = _DkEventSet(handle, -1);
  65. if (ret < 0)
  66. _DkRaiseFailure(-ret);
  67. LEAVE_PAL_CALL();
  68. }
  69. void DkEventWait (PAL_HANDLE handle)
  70. {
  71. ENTER_PAL_CALL(DkEventWait);
  72. if (!handle || !IS_HANDLE_TYPE(handle, event)) {
  73. _DkRaiseFailure(PAL_ERROR_INVAL);
  74. LEAVE_PAL_CALL();
  75. }
  76. int ret = _DkEventWait(handle);
  77. if (ret < 0)
  78. _DkRaiseFailure(-ret);
  79. LEAVE_PAL_CALL();
  80. }
  81. void DkEventClear (PAL_HANDLE handle)
  82. {
  83. ENTER_PAL_CALL(DkEventClear);
  84. if (!handle || !IS_HANDLE_TYPE(handle, event)) {
  85. _DkRaiseFailure(PAL_ERROR_INVAL);
  86. LEAVE_PAL_CALL();
  87. }
  88. int ret = _DkEventClear(handle);
  89. if (ret < 0)
  90. _DkRaiseFailure(-ret);
  91. LEAVE_PAL_CALL();
  92. }
  93. static int event_close (PAL_HANDLE handle)
  94. {
  95. return _DkEventClear(handle);
  96. }
  97. static int event_wait (PAL_HANDLE handle, int timeout)
  98. {
  99. return timeout >=0 ? _DkEventWaitTimeout(handle, timeout) :
  100. _DkEventWait(handle);
  101. }
  102. struct handle_ops event_ops = {
  103. .close = &event_close,
  104. .wait = &event_wait,
  105. };