queue_test.cpp 805 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright 2010-2025 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
  4. */
  5. #include "test.h"
  6. #include <bx/spscqueue.h>
  7. #include <bx/mpscqueue.h>
  8. void* bitsToPtr(uintptr_t _ui)
  9. {
  10. union { uintptr_t ui; void* ptr; } cast = { _ui };
  11. return cast.ptr;
  12. }
  13. uintptr_t ptrToBits(void* _ptr)
  14. {
  15. union { void* ptr; uintptr_t ui; } cast = { _ptr };
  16. return cast.ui;
  17. }
  18. TEST_CASE("SpSc", "")
  19. {
  20. bx::DefaultAllocator allocator;
  21. bx::SpScUnboundedQueue queue(&allocator);
  22. queue.push(bitsToPtr(0xdeadbeef) );
  23. REQUIRE(0xdeadbeef == ptrToBits(queue.pop() ) );
  24. }
  25. TEST_CASE("MpSc", "")
  26. {
  27. bx::DefaultAllocator allocator;
  28. bx::MpScUnboundedQueueT<void> queue(&allocator);
  29. queue.push(bitsToPtr(0xdeadbeef) );
  30. REQUIRE(0xdeadbeef == ptrToBits(queue.pop() ) );
  31. }