| 1 | /* @title: Thread IDs */ |
|---|---|
| 2 | #include <stdint.h> |
| 3 | #include <structures/rbt.h> |
| 4 | #include <sync/spinlock.h> |
| 5 | |
| 6 | #define TID_RANGE_RESERVE_COUNT 128 |
| 7 | |
| 8 | struct tid_range { |
| 9 | struct rbt_node node; |
| 10 | uint64_t start; |
| 11 | uint64_t length; |
| 12 | struct tid_range *next; |
| 13 | }; |
| 14 | |
| 15 | struct tid_space { |
| 16 | struct rbt tree; |
| 17 | struct spinlock lock; |
| 18 | struct tid_range reserve_pool[TID_RANGE_RESERVE_COUNT]; |
| 19 | struct tid_range *reserve_free; |
| 20 | }; |
| 21 | |
| 22 | uint64_t tid_alloc(struct tid_space *ts); |
| 23 | void tid_free(struct tid_space *ts, uint64_t id); |
| 24 | struct tid_space *tid_space_init(uint64_t max_id); |
| 25 |