xrp_sync_queue.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2016 - 2018 Cadence Design Systems Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included
  13. * in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <stdio.h>
  24. #include "xrp_host_common.h"
  25. #include "xrp_sync_queue.h"
  26. void xrp_queue_init(struct xrp_request_queue *queue, int priority,
  27. void *context,
  28. void (*fn)(struct xrp_queue_item *rq, void *context))
  29. {
  30. (void)priority;
  31. queue->context = context;
  32. queue->fn = fn;
  33. }
  34. void xrp_queue_destroy(struct xrp_request_queue *queue)
  35. {
  36. (void)queue;
  37. }
  38. void xrp_queue_push(struct xrp_request_queue *queue,
  39. struct xrp_queue_item *rq)
  40. {
  41. queue->fn(rq, queue->context);
  42. }
  43. struct xrp_event *xrp_event_create(void)
  44. {
  45. struct xrp_event *event = alloc_refcounted(sizeof(*event));
  46. if (!event)
  47. return NULL;
  48. event->status = XRP_STATUS_PENDING;
  49. return event;
  50. }
  51. void xrp_wait(struct xrp_event *event, enum xrp_status *status)
  52. {
  53. if (event->status == XRP_STATUS_PENDING)
  54. set_status(status, XRP_STATUS_FAILURE);
  55. else
  56. set_status(status, XRP_STATUS_SUCCESS);
  57. }
  58. size_t xrp_wait_any(struct xrp_event **event, size_t n_events,
  59. enum xrp_status *status)
  60. {
  61. if (n_events && event[0]->status != XRP_STATUS_PENDING)
  62. set_status(status, XRP_STATUS_SUCCESS);
  63. else
  64. set_status(status, XRP_STATUS_FAILURE);
  65. return 0;
  66. }
  67. void xrp_impl_broadcast_event(struct xrp_event *event, enum xrp_status status)
  68. {
  69. event->status = status;
  70. }
  71. void xrp_impl_release_event(struct xrp_event *event)
  72. {
  73. (void)event;
  74. }