db_events.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. store_frame(NotificationEventCreate);
  28. PAL_HANDLE handle = NULL;
  29. int ret = _DkEventCreate(&handle, initialState, true);
  30. if (ret < 0) {
  31. notify_failure(-ret);
  32. return NULL;
  33. }
  34. return handle;
  35. }
  36. PAL_HANDLE DkSynchronizationEventCreate (PAL_BOL initialState)
  37. {
  38. store_frame(SynchronizationEventCreate);
  39. PAL_HANDLE handle = NULL;
  40. int ret = _DkEventCreate(&handle, initialState, false);
  41. if (ret < 0) {
  42. notify_failure(-ret);
  43. return NULL;
  44. }
  45. return handle;
  46. }
  47. void DkEventDestroy (PAL_HANDLE handle)
  48. {
  49. store_frame(EventDestroy);
  50. if (!handle || !IS_HANDLE_TYPE(handle, event)) {
  51. notify_failure(PAL_ERROR_INVAL);
  52. return;
  53. }
  54. _DkEventDestroy(handle);
  55. }
  56. void DkEventSet (PAL_HANDLE handle)
  57. {
  58. store_frame(EventSet);
  59. if (!handle || !IS_HANDLE_TYPE(handle, event)) {
  60. notify_failure(PAL_ERROR_INVAL);
  61. return;
  62. }
  63. int ret = _DkEventSet (handle);
  64. if (ret < 0)
  65. notify_failure(-ret);
  66. }
  67. void DkEventWait (PAL_HANDLE handle)
  68. {
  69. store_frame(EventWait);
  70. if (!handle || !IS_HANDLE_TYPE(handle, event)) {
  71. notify_failure(PAL_ERROR_INVAL);
  72. return;
  73. }
  74. int ret = _DkEventWait(handle);
  75. if (ret < 0)
  76. notify_failure(-ret);
  77. }
  78. void DkEventClear (PAL_HANDLE handle)
  79. {
  80. store_frame(EventClear);
  81. if (!handle || !IS_HANDLE_TYPE(handle, event)) {
  82. notify_failure(PAL_ERROR_INVAL);
  83. return;
  84. }
  85. int ret = _DkEventClear(handle);
  86. if (ret < 0)
  87. notify_failure(-ret);
  88. }
  89. static int event_close (PAL_HANDLE handle)
  90. {
  91. return _DkEventClear(handle);
  92. }
  93. static int event_wait (PAL_HANDLE handle, int timeout)
  94. {
  95. return timeout >=0 ? _DkEventWaitTimeout(handle, timeout) :
  96. _DkEventWait(handle);
  97. }
  98. struct handle_ops event_ops = {
  99. .close = &event_close,
  100. .wait = &event_wait,
  101. };