db_events.c 3.0 KB

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