tid_allocator.h 897 B

123456789101112131415161718192021222324252627282930313233343536
  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. #define TID_ALLOCATOR_INIT_SIZE CLUSTER_MAX_THREAD_NUM
  9. enum {
  10. TID_MIN = 1,
  11. TID_MAX = 0x1FFFFFFF
  12. }; // Reserved TIDs (WASI specification)
  13. /* Stack data structure to track available thread identifiers */
  14. typedef struct {
  15. int32 *ids; // Array used to store the stack
  16. uint32 size; // Stack capacity
  17. uint32 pos; // Index of the element after the stack top
  18. } TidAllocator;
  19. bool
  20. tid_allocator_init(TidAllocator *tid_allocator);
  21. void
  22. tid_allocator_deinit(TidAllocator *tid_allocator);
  23. int32
  24. tid_allocator_get_tid(TidAllocator *tid_allocator);
  25. void
  26. tid_allocator_release_tid(TidAllocator *tid_allocator, int32 thread_id);
  27. #endif /* _TID_ALLOCATOR_H */