From 4f201da561d60137c2f0866401982d24d8b3d1bd Mon Sep 17 00:00:00 2001 From: Jeroen van der Heijden Date: Thu, 23 Jul 2026 15:25:44 +0200 Subject: [PATCH 1/2] less sleep, sched_yield instead --- src/ti/archive.c | 4 ++-- src/ti/collection.c | 6 +++--- src/ti/collections.c | 2 +- src/ti/qcache.c | 3 +-- src/ti/store.c | 10 +++++----- src/ti/store/storeaccess.c | 2 +- src/ti/store/storecollection.c | 2 +- src/ti/store/storecollections.c | 2 +- src/ti/store/storecommits.c | 2 +- src/ti/store/storeenums.c | 2 +- src/ti/store/storegcollect.c | 4 ++-- src/ti/store/storemodules.c | 2 +- src/ti/store/storenamedrooms.c | 2 +- src/ti/store/storenames.c | 2 +- src/ti/store/storeprocedures.c | 2 +- src/ti/store/storestatus.c | 2 +- src/ti/store/storetasks.c | 2 +- src/ti/store/storethings.c | 4 ++-- src/ti/store/storetypes.c | 2 +- src/ti/store/storeusers.c | 2 +- 20 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/ti/archive.c b/src/ti/archive.c index 368772e83..845936030 100644 --- a/src/ti/archive.c +++ b/src/ti/archive.c @@ -186,7 +186,7 @@ static int archive__to_disk(void) ti_cpkg_drop(cpkg); - (void) ti_sleep(10); + (void) sched_yield(); } while ((cpkg = queue_shift(archive->queue))); @@ -425,7 +425,7 @@ int ti_archive_to_disk(void) (void) ti_store_store(); /* sleep a little before archiving */ - (void) ti_sleep(200); + (void) ti_sleep(100); /* archive changes, even after full store for synchronizing `other` nodes */ if (archive__to_disk()) diff --git a/src/ti/collection.c b/src/ti/collection.c index 4fad96e82..f39c17676 100644 --- a/src/ti/collection.c +++ b/src/ti/collection.c @@ -539,7 +539,7 @@ int ti_collection_gc(ti_collection_t * collection, _Bool do_mark_things) /* Release the lock */ uv_mutex_unlock(collection->lock); - (void) ti_sleep(5); + (void) sched_yield(); } uv_mutex_lock(collection->lock); @@ -601,7 +601,7 @@ int ti_collection_gc(ti_collection_t * collection, _Bool do_mark_things) /* Release the lock and let the thread sleep some time */ uv_mutex_unlock(collection->lock); - (void) ti_sleep(5); + (void) sched_yield(); /* Take a new lock */ uv_mutex_lock(collection->lock); @@ -626,7 +626,7 @@ int ti_collection_gc(ti_collection_t * collection, _Bool do_mark_things) /* Finished, release the collection lock */ uv_mutex_unlock(collection->lock); - (void) ti_sleep(2); + (void) sched_yield(); ti_counters_add_garbage_collected(n); diff --git a/src/ti/collections.c b/src/ti/collections.c index f6d23b3a0..49e2a3986 100644 --- a/src/ti/collections.c +++ b/src/ti/collections.c @@ -79,7 +79,7 @@ int ti_collections_gc(void) rc = -1; } - (void) ti_sleep(100); + (void) sched_yield(); } return rc; diff --git a/src/ti/qcache.c b/src/ti/qcache.c index 7a0eff5a2..642244934 100644 --- a/src/ti/qcache.c +++ b/src/ti/qcache.c @@ -187,8 +187,7 @@ void ti_qcache_cleanup(void) return; (void) smap_values(qcache, (smap_val_cb) qcache__cleanup_cb, &w); - - (void) ti_sleep(100); + (void) sched_yield(); log_info("removed %u item(s) from query cache", w.qcached->n); diff --git a/src/ti/store.c b/src/ti/store.c index 0c4057ade..1dd04bd81 100644 --- a/src/ti/store.c +++ b/src/ti/store.c @@ -202,7 +202,7 @@ int ti_store_store(void) log_errno_file("cannot create directory", errno, store->tmp_path); } - (void) ti_sleep(5); + (void) sched_yield(); store__set_filename(/* use_tmp: */ true); @@ -231,7 +231,7 @@ int ti_store_store(void) if (!store_collection) goto failed; - (void) ti_sleep(2); + (void) sched_yield(); rc = mkdir(store_collection->collection_path, FX_DEFAULT_DIR_ACCESS); if (rc) @@ -286,7 +286,7 @@ int ti_store_store(void) } (void) rename(store->store_path, store->prev_path); - (void) ti_sleep(2); + (void) sched_yield(); if (rename(store->tmp_path, store->store_path)) { @@ -297,9 +297,9 @@ int ti_store_store(void) goto failed; } - (void) ti_sleep(2); + (void) sched_yield(); (void) fx_rmdir(store->prev_path); - (void) ti_sleep(2); + (void) sched_yield(); store->last_stored_change_id = ti.node->ccid; diff --git a/src/ti/store/storeaccess.c b/src/ti/store/storeaccess.c index dedf427d4..40fdc50ce 100644 --- a/src/ti/store/storeaccess.c +++ b/src/ti/store/storeaccess.c @@ -44,7 +44,7 @@ int ti_store_access_store(const vec_t * access, const char * fn) log_errno_file("cannot close file", errno, fn); return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } diff --git a/src/ti/store/storecollection.c b/src/ti/store/storecollection.c index 033489700..4a334938b 100644 --- a/src/ti/store/storecollection.c +++ b/src/ti/store/storecollection.c @@ -120,7 +120,7 @@ int ti_store_collection_store(ti_collection_t * collection, const char * fn) if (rc == 0) log_debug("stored collection info to file: `%s`", fn); - (void) ti_sleep(5); + (void) sched_yield(); return rc; } diff --git a/src/ti/store/storecollections.c b/src/ti/store/storecollections.c index 2f8905ece..d44de1f09 100644 --- a/src/ti/store/storecollections.c +++ b/src/ti/store/storecollections.c @@ -55,7 +55,7 @@ int ti_store_collections_store(const char * fn) log_errno_file("cannot close file", errno, fn); return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } diff --git a/src/ti/store/storecommits.c b/src/ti/store/storecommits.c index 8caeac4ab..d9b4f221b 100644 --- a/src/ti/store/storecommits.c +++ b/src/ti/store/storecommits.c @@ -52,7 +52,7 @@ int ti_store_commits_store(vec_t * commits, const char * fn) log_errno_file("cannot close file", errno, fn); return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } diff --git a/src/ti/store/storeenums.c b/src/ti/store/storeenums.c index 2060fd958..db051ee5b 100644 --- a/src/ti/store/storeenums.c +++ b/src/ti/store/storeenums.c @@ -78,7 +78,7 @@ int ti_store_enums_store(ti_enums_t * enums, const char * fn) log_errno_file("cannot close file", errno, fn); return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } diff --git a/src/ti/store/storegcollect.c b/src/ti/store/storegcollect.c index 00270c03b..560cb381e 100644 --- a/src/ti/store/storegcollect.c +++ b/src/ti/store/storegcollect.c @@ -55,7 +55,7 @@ int ti_store_gcollect_store(queue_t * queue, const char * fn) log_errno_file("cannot close file", errno, fn); return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } @@ -138,7 +138,7 @@ int ti_store_gcollect_store_data(queue_t * queue, const char * fn) log_errno_file("cannot close file", errno, fn); return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } diff --git a/src/ti/store/storemodules.c b/src/ti/store/storemodules.c index f00f3243b..872bb14fb 100644 --- a/src/ti/store/storemodules.c +++ b/src/ti/store/storemodules.c @@ -62,7 +62,7 @@ int ti_store_modules_store(const char * fn) log_errno_file("cannot close file", errno, fn); return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } diff --git a/src/ti/store/storenamedrooms.c b/src/ti/store/storenamedrooms.c index fac5fca3f..da02ab46c 100644 --- a/src/ti/store/storenamedrooms.c +++ b/src/ti/store/storenamedrooms.c @@ -53,7 +53,7 @@ int ti_store_named_rooms_store(smap_t * named_rooms, const char * fn) log_errno_file("cannot close file", errno, fn); return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } diff --git a/src/ti/store/storenames.c b/src/ti/store/storenames.c index 621c640ef..acfbd06d1 100644 --- a/src/ti/store/storenames.c +++ b/src/ti/store/storenames.c @@ -38,7 +38,7 @@ int ti_store_names_store(const char * fn) log_errno_file("cannot close file", errno, fn); return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } diff --git a/src/ti/store/storeprocedures.c b/src/ti/store/storeprocedures.c index 4bb2f9649..71fc3622a 100644 --- a/src/ti/store/storeprocedures.c +++ b/src/ti/store/storeprocedures.c @@ -53,7 +53,7 @@ int ti_store_procedures_store(smap_t * procedures, const char * fn) log_errno_file("cannot close file", errno, fn); return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } diff --git a/src/ti/store/storestatus.c b/src/ti/store/storestatus.c index ba4483c7e..48276fd0d 100644 --- a/src/ti/store/storestatus.c +++ b/src/ti/store/storestatus.c @@ -36,7 +36,7 @@ int ti_store_status_store(const char * fn) log_errno_file("cannot close file", errno, fn); return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } diff --git a/src/ti/store/storetasks.c b/src/ti/store/storetasks.c index 3c4ac74c2..77f6956a1 100644 --- a/src/ti/store/storetasks.c +++ b/src/ti/store/storetasks.c @@ -62,7 +62,7 @@ int ti_store_tasks_store(vec_t * vtasks, const char * fn) return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } diff --git a/src/ti/store/storethings.c b/src/ti/store/storethings.c index 58a06e71f..b56ceb95f 100644 --- a/src/ti/store/storethings.c +++ b/src/ti/store/storethings.c @@ -76,7 +76,7 @@ int ti_store_things_store(imap_t * things, const char * fn) log_errno_file("cannot close file", errno, fn); return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } @@ -155,7 +155,7 @@ int ti_store_things_store_data(imap_t * things, const char * fn) log_errno_file("cannot close file", errno, fn); return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } diff --git a/src/ti/store/storetypes.c b/src/ti/store/storetypes.c index b4d37f043..1e50cd8c4 100644 --- a/src/ti/store/storetypes.c +++ b/src/ti/store/storetypes.c @@ -160,7 +160,7 @@ int ti_store_types_store(ti_types_t * types, const char * fn) log_errno_file("cannot close file", errno, fn); return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } diff --git a/src/ti/store/storeusers.c b/src/ti/store/storeusers.c index d07d8d58e..7df986e3a 100644 --- a/src/ti/store/storeusers.c +++ b/src/ti/store/storeusers.c @@ -90,7 +90,7 @@ int ti_store_users_store(const char * fn) log_errno_file("cannot close file", errno, fn); return -1; } - (void) ti_sleep(5); + (void) sched_yield(); return 0; } From 9744d264d33627316e8d91d748b996fdeb88a525 Mon Sep 17 00:00:00 2001 From: Jeroen van der Heijden Date: Thu, 23 Jul 2026 15:28:31 +0200 Subject: [PATCH 2/2] Changelog and version --- CHANGELOG.md | 1 + inc/ti/version.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b00a93fb8..139912032 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # v1.9.3-alpha0 * Fixed sanatize runtime checking, pr #455. +* Replaced `ti_sleep(..)` with `sched_yield()` with a few exceptions, pr #456. # v1.9.2 diff --git a/inc/ti/version.h b/inc/ti/version.h index 120e1479b..78962cb1e 100644 --- a/inc/ti/version.h +++ b/inc/ti/version.h @@ -25,7 +25,7 @@ * "-rc0" * "" */ -#define TI_VERSION_PRE_RELEASE "-alpha0" +#define TI_VERSION_PRE_RELEASE "-alpha1" #define TI_MAINTAINER \ "Jeroen van der Heijden "