summaryrefslogtreecommitdiff
path: root/src/internal.h
diff options
context:
space:
mode:
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);
}
}