erlang各种有用的函数包括一些有用nif封装,还有一些性能测试case。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
909 B

пре 5 година
  1. #include "epqueue_item.h"
  2. #include "epqueue_nif.h"
  3. #include "macros.h"
  4. bool epqueue_item_less(void* ax, void* bx)
  5. {
  6. queue_item* a = static_cast<queue_item*>(ax);
  7. queue_item* b = static_cast<queue_item*>(bx);
  8. return a->priority < b->priority;
  9. }
  10. void epqueue_item_update_pos(void* ax, int32_t pos)
  11. {
  12. queue_item* a = static_cast<queue_item*>(ax);
  13. a->heap_index = pos;
  14. }
  15. void epqueue_item_free(ErlNifEnv* env, void* obj)
  16. {
  17. UNUSED(env);
  18. queue_item* item = static_cast<queue_item*>(obj);
  19. enif_release_binary(&item->data);
  20. }
  21. queue_item* epqueue_item_new(const epqueue_data* data, const ErlNifBinary& bin, uint64_t priority)
  22. {
  23. queue_item* item = static_cast<queue_item*>(enif_alloc_resource(data->resPQueueItem, sizeof(queue_item)));
  24. if(item == NULL)
  25. return NULL;
  26. item->heap_index = -1;
  27. item->priority = priority;
  28. item->data = bin;
  29. return item;
  30. }