skynet_mq.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef SKYNET_MESSAGE_QUEUE_H
  2. #define SKYNET_MESSAGE_QUEUE_H
  3. #include <stdlib.h>
  4. #include <stdint.h>
  5. struct skynet_message {
  6. uint32_t source;
  7. int session;
  8. void * data;
  9. size_t sz;
  10. };
  11. // type is encoding in skynet_message.sz high 8bit
  12. #define MESSAGE_TYPE_MASK (SIZE_MAX >> 8)
  13. #define MESSAGE_TYPE_SHIFT ((sizeof(size_t)-1) * 8)
  14. struct message_queue;
  15. void skynet_globalmq_push(struct message_queue * queue);
  16. struct message_queue * skynet_globalmq_pop(void);
  17. struct message_queue * skynet_mq_create(uint32_t handle);
  18. void skynet_mq_mark_release(struct message_queue *q);
  19. typedef void (*message_drop)(struct skynet_message *, void *);
  20. void skynet_mq_release(struct message_queue *q, message_drop drop_func, void *ud);
  21. uint32_t skynet_mq_handle(struct message_queue *);
  22. // 0 for success
  23. int skynet_mq_pop(struct message_queue *q, struct skynet_message *message);
  24. void skynet_mq_push(struct message_queue *q, struct skynet_message *message);
  25. // return the length of message queue, for debug
  26. int skynet_mq_length(struct message_queue *q);
  27. int skynet_mq_overload(struct message_queue *q);
  28. void skynet_mq_init();
  29. #endif