db_events.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Copyright (C) 2014 Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /*
  14. * db_event.c
  15. *
  16. * This file contains implementation of Drawbridge event synchronization APIs.
  17. */
  18. #include "api.h"
  19. #include "pal.h"
  20. #include "pal_defs.h"
  21. #include "pal_error.h"
  22. #include "pal_internal.h"
  23. PAL_HANDLE DkNotificationEventCreate(PAL_BOL initialState) {
  24. ENTER_PAL_CALL(DkNotificationEventCreate);
  25. PAL_HANDLE handle = NULL;
  26. int ret = _DkEventCreate(&handle, initialState, true);
  27. if (ret < 0) {
  28. _DkRaiseFailure(-ret);
  29. handle = NULL;
  30. }
  31. TRACE_HEAP(handle);
  32. LEAVE_PAL_CALL_RETURN(handle);
  33. }
  34. PAL_HANDLE DkSynchronizationEventCreate(PAL_BOL initialState) {
  35. ENTER_PAL_CALL(DkSynchronizationEventCreate);
  36. PAL_HANDLE handle = NULL;
  37. int ret = _DkEventCreate(&handle, initialState, false);
  38. if (ret < 0) {
  39. _DkRaiseFailure(-ret);
  40. handle = NULL;
  41. }
  42. TRACE_HEAP(handle);
  43. LEAVE_PAL_CALL_RETURN(handle);
  44. }
  45. /* DkEventDestroy deprecated, replaced by DkObjectClose */
  46. void DkEventSet(PAL_HANDLE handle) {
  47. ENTER_PAL_CALL(DkEventSet);
  48. if (!handle || !IS_HANDLE_TYPE(handle, event)) {
  49. _DkRaiseFailure(PAL_ERROR_INVAL);
  50. LEAVE_PAL_CALL();
  51. }
  52. int ret = _DkEventSet(handle, -1);
  53. if (ret < 0)
  54. _DkRaiseFailure(-ret);
  55. LEAVE_PAL_CALL();
  56. }
  57. void DkEventWait(PAL_HANDLE handle) {
  58. ENTER_PAL_CALL(DkEventWait);
  59. if (!handle || !IS_HANDLE_TYPE(handle, event)) {
  60. _DkRaiseFailure(PAL_ERROR_INVAL);
  61. LEAVE_PAL_CALL();
  62. }
  63. int ret = _DkEventWait(handle);
  64. if (ret < 0)
  65. _DkRaiseFailure(-ret);
  66. LEAVE_PAL_CALL();
  67. }
  68. void DkEventClear(PAL_HANDLE handle) {
  69. ENTER_PAL_CALL(DkEventClear);
  70. if (!handle || !IS_HANDLE_TYPE(handle, event)) {
  71. _DkRaiseFailure(PAL_ERROR_INVAL);
  72. LEAVE_PAL_CALL();
  73. }
  74. int ret = _DkEventClear(handle);
  75. if (ret < 0)
  76. _DkRaiseFailure(-ret);
  77. LEAVE_PAL_CALL();
  78. }