| 1007 | } |
| 1008 | |
| 1009 | void cbm_destroy_thread_parser(void) { |
| 1010 | // Full cleanup: delete the parser. Call on worker thread exit. |
| 1011 | if (tl_parser) { |
| 1012 | ts_parser_delete(tl_parser); |
| 1013 | tl_parser = NULL; |
| 1014 | tl_parser_lang = CBM_LANG_COUNT; |
| 1015 | } |
| 1016 | if (tl_cursor_live) { |
| 1017 | ts_tree_cursor_delete(&tl_cursor); |
| 1018 | tl_cursor_live = false; |
| 1019 | } |
| 1020 | if (tl_cursor_pool) { |
| 1021 | bool busy = false; |
| 1022 | for (int d = 0; d < CURSOR_POOL_DEPTH; d++) { |
| 1023 | /* a busy slot belongs to a walk still on this stack: leave it */ |
| 1024 | if (tl_cursor_pool->state[d] == CURSOR_LIVE) { |
| 1025 | ts_tree_cursor_delete(&tl_cursor_pool->cursors[d]); |
| 1026 | tl_cursor_pool->state[d] = 0; |
| 1027 | } else if (tl_cursor_pool->state[d] & CURSOR_BUSY) { |
| 1028 | busy = true; |
| 1029 | } |
| 1030 | } |
| 1031 | /* Outstanding leases point INTO this block, so it is only released once |
| 1032 | * no walk still holds a slot. */ |
| 1033 | if (!busy) { |
| 1034 | cbm_free(CBM_MEM_CLASS_OTHER, tl_cursor_pool); |
| 1035 | tl_cursor_pool = NULL; |
| 1036 | } |
| 1037 | } |
| 1038 | cbm_ts_field_cache_release_thread(); |
| 1039 | } |
| 1040 | |
| 1041 | void cbm_shutdown(void) { |
| 1042 | // Clean up thread-local parser for the calling thread. |