summaryrefslogtreecommitdiff
path: root/src/internal.h
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-15 12:38:54 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-15 12:38:54 +0300
commit6ee9eb37d8e616a972fb29b3fbdbc33991aa844f (patch)
tree5b257df9f1301f00ca5de49de60c56be45c67274 /src/internal.h
parentcaf7d446446a0af0b30886a6c4ee5851aab553e2 (diff)
parente3d8fe4854a7ef7ff0637688cda9e65feb680122 (diff)
Merge branch 'wt/lock' into api-hardening
# Conflicts: # src/screen.c # tests/term_test.c
Diffstat (limited to 'src/internal.h')
-rw-r--r--src/internal.h18
1 files changed, 4 insertions, 14 deletions
diff --git a/src/internal.h b/src/internal.h
index 5da114d..676413c 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -108,7 +108,8 @@ struct resize_scratch {
struct term {
- _Atomic uint64_t seq;
+ /* The writer section. A waiting thread sleeps on it. */
+ term_mutex write_lock;
_Atomic uint64_t writer_tid;
uint32_t write_depth;
int cols;
@@ -377,18 +378,7 @@ static inline void term_write_begin(struct term *t)
t->write_depth++;
return;
}
- uint64_t s;
- for (;;) {
- s = atomic_load_explicit(&t->seq, memory_order_relaxed);
- if (s & 1) {
- term_cpu_relax();
- continue;
- }
- if (atomic_compare_exchange_weak_explicit(&t->seq, &s, s + 1,
- memory_order_acquire,
- memory_order_relaxed))
- break;
- }
+ term_mutex_lock(&t->write_lock);
atomic_store_explicit(&t->writer_tid, self, memory_order_relaxed);
t->write_depth = 1;
}
@@ -398,7 +388,7 @@ static inline void term_write_end(struct term *t)
if (!t) return;
if (--t->write_depth == 0) {
atomic_store_explicit(&t->writer_tid, 0, memory_order_relaxed);
- atomic_fetch_add_explicit(&t->seq, 1, memory_order_release);
+ term_mutex_unlock(&t->write_lock);
}
}