tid_allocator.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _TID_ALLOCATOR_H
  6. #define _TID_ALLOCATOR_H
  7. #include "platform_common.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #define TID_ALLOCATOR_INIT_SIZE CLUSTER_MAX_THREAD_NUM
  12. enum {
  13. /* Keep it in sync with
  14. https://github.com/WebAssembly/wasi-threads#design-choice-thread-ids */
  15. TID_MIN = 1,
  16. TID_MAX = 0x1FFFFFFF
  17. }; // Reserved TIDs (WASI specification)
  18. /* Stack data structure to track available thread identifiers */
  19. typedef struct {
  20. int32 *ids; // Array used to store the stack
  21. uint32 size; // Stack capacity
  22. uint32 pos; // Index of the element after the stack top
  23. } TidAllocator;
  24. bool
  25. tid_allocator_init(TidAllocator *tid_allocator);
  26. void
  27. tid_allocator_deinit(TidAllocator *tid_allocator);
  28. int32
  29. tid_allocator_get_tid(TidAllocator *tid_allocator);
  30. void
  31. tid_allocator_release_tid(TidAllocator *tid_allocator, int32 thread_id);
  32. #ifdef __cplusplus
  33. }
  34. #endif
  35. #endif /* _TID_ALLOCATOR_H */