bh_queue.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef _BH_QUEUE_H
  17. #define _BH_QUEUE_H
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include "korp_types.h" /*For bool type*/
  22. #include "bh_platform.h"
  23. struct _bh_queue_node;
  24. typedef struct _bh_queue_node * bh_message_t;
  25. struct bh_queue;
  26. typedef struct bh_queue bh_queue;
  27. typedef void (*bh_queue_handle_msg_callback)(void *message, void *arg);
  28. #define bh_queue_malloc bh_malloc
  29. #define bh_queue_free bh_free
  30. #define bh_queue_mutex korp_mutex
  31. #define bh_queue_sem korp_sem
  32. #define bh_queue_cond korp_cond
  33. #define bh_queue_mutex_init vm_mutex_init
  34. #define bh_queue_mutex_destroy vm_mutex_destroy
  35. #define bh_queue_mutex_lock vm_mutex_lock
  36. #define bh_queue_mutex_unlock vm_mutex_unlock
  37. #define bh_queue_sem_init vm_sem_init
  38. #define bh_queue_sem_destroy vm_sem_destroy
  39. #define bh_queue_sem_wait vm_sem_wait
  40. #define bh_queue_sem_reltimedwait vm_sem_reltimedwait
  41. #define bh_queue_sem_post vm_sem_post
  42. #define bh_queue_cond_init vm_cond_init
  43. #define bh_queue_cond_destroy vm_cond_destroy
  44. #define bh_queue_cond_wait vm_cond_wait
  45. #define bh_queue_cond_timedwait vm_cond_reltimedwait
  46. #define bh_queue_cond_signal vm_cond_signal
  47. #define bh_queue_cond_broadcast vm_cond_broadcast
  48. typedef void (*bh_msg_cleaner)(void *msg);
  49. bh_queue *
  50. bh_queue_create();
  51. void
  52. bh_queue_destroy(bh_queue *queue);
  53. char * bh_message_payload(bh_message_t message);
  54. int bh_message_payload_len(bh_message_t message);
  55. int bh_message_type(bh_message_t message);
  56. bh_message_t bh_new_msg(unsigned short tag, void *body, unsigned int len,
  57. void * handler);
  58. void bh_free_msg(bh_message_t msg);
  59. bool bh_post_msg(bh_queue *queue, unsigned short tag, void *body,
  60. unsigned int len);
  61. bool bh_post_msg2(bh_queue *queue, bh_message_t msg);
  62. bh_message_t bh_get_msg(bh_queue *queue, int timeout);
  63. unsigned
  64. bh_queue_get_message_count(bh_queue *queue);
  65. void
  66. bh_queue_enter_loop_run(bh_queue *queue,
  67. bh_queue_handle_msg_callback handle_cb,
  68. void *arg);
  69. void
  70. bh_queue_exit_loop_run(bh_queue *queue);
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif /* #ifndef _BH_QUEUE_H */