From 058f3ba013c9c220e38addeba716d0639f10728f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kr=C3=BCger?= <45282134+UweKrueger@users.noreply.github.com> Date: Sat, 30 Jan 2021 15:23:55 +0100 Subject: [PATCH] sync: rename `m_lock() -> @lock()`, `r_lock() -> @rlock()`, ... (#8443) --- vlib/clipboard/x11/clipboard.c.v | 10 +++++----- vlib/sync/pool.v | 2 +- vlib/sync/sync_default.c.v | 12 ++++++------ vlib/sync/sync_macos.c.v | 12 ++++++------ vlib/sync/sync_windows.c.v | 10 +++++----- vlib/sync/waitgroup.v | 2 +- vlib/v/gen/cgen.v | 16 ++++++++-------- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/vlib/clipboard/x11/clipboard.c.v b/vlib/clipboard/x11/clipboard.c.v index 593a918484..a7f5af04d7 100644 --- a/vlib/clipboard/x11/clipboard.c.v +++ b/vlib/clipboard/x11/clipboard.c.v @@ -210,7 +210,7 @@ fn (mut cb Clipboard) free() { } fn (mut cb Clipboard) clear() { - cb.mutex.m_lock() + cb.mutex.@lock() C.XSetSelectionOwner(cb.display, cb.selection, C.Window(C.None), C.CurrentTime) C.XFlush(cb.display) cb.is_owner = false @@ -232,7 +232,7 @@ pub fn (mut cb Clipboard) set_text(text string) bool { if cb.window == C.Window(C.None) { return false } - cb.mutex.m_lock() + cb.mutex.@lock() cb.text = text cb.is_owner = true cb.take_ownership() @@ -276,7 +276,7 @@ fn (mut cb Clipboard) transmit_selection(xse &C.XSelectionEvent) bool { C.XChangeProperty(xse.display, xse.requestor, xse.property, cb.get_atom(.xa_atom), 32, C.PropModeReplace, targets.data, targets.len) } else if cb.is_supported_target(xse.target) && cb.is_owner && cb.text != '' { - cb.mutex.m_lock() + cb.mutex.@lock() C.XChangeProperty(xse.display, xse.requestor, xse.property, xse.target, 8, C.PropModeReplace, cb.text.str, cb.text.len) cb.mutex.unlock() @@ -308,7 +308,7 @@ fn (mut cb Clipboard) start_listener() { event.xselectionclear.selection == cb.selection } { - cb.mutex.m_lock() + cb.mutex.@lock() cb.is_owner = false cb.text = '' cb.mutex.unlock() @@ -353,7 +353,7 @@ fn (mut cb Clipboard) start_listener() { } else if unsafe { event.xselection.target == to_be_requested } { sent_request = false to_be_requested = C.Atom(0) - cb.mutex.m_lock() + cb.mutex.@lock() prop := unsafe { read_property(event.xselection.display, event.xselection.requestor, event.xselection.property) diff --git a/vlib/sync/pool.v b/vlib/sync/pool.v index 07c08ba2da..06ea156a12 100644 --- a/vlib/sync/pool.v +++ b/vlib/sync/pool.v @@ -139,7 +139,7 @@ fn process_in_thread(mut pool PoolProcessor, task_id int) { if pool.ntask >= ilen { break } - pool.ntask_mtx.m_lock() + pool.ntask_mtx.@lock() idx = pool.ntask pool.ntask++ pool.ntask_mtx.unlock() diff --git a/vlib/sync/sync_default.c.v b/vlib/sync/sync_default.c.v index 744fb15e15..1fa67aa807 100644 --- a/vlib/sync/sync_default.c.v +++ b/vlib/sync/sync_default.c.v @@ -69,8 +69,8 @@ pub fn (mut m RwMutex) init() { C.pthread_rwlock_init(&m.mutex, &a.attr) } -// m_lock(), for *manual* mutex handling, since `lock` is a keyword -pub fn (mut m Mutex) m_lock() { +// @lock(), for *manual* mutex handling, since `lock` is a keyword +pub fn (mut m Mutex) @lock() { C.pthread_mutex_lock(&m.mutex) } @@ -79,21 +79,21 @@ pub fn (mut m Mutex) unlock() { } // RwMutex has separate read- and write locks -pub fn (mut m RwMutex) r_lock() { +pub fn (mut m RwMutex) @rlock() { C.pthread_rwlock_rdlock(&m.mutex) } -pub fn (mut m RwMutex) w_lock() { +pub fn (mut m RwMutex) @lock() { C.pthread_rwlock_wrlock(&m.mutex) } // Windows SRWLocks have different function to unlock // So provide two functions here, too, to have a common interface -pub fn (mut m RwMutex) r_unlock() { +pub fn (mut m RwMutex) runlock() { C.pthread_rwlock_unlock(&m.mutex) } -pub fn (mut m RwMutex) w_unlock() { +pub fn (mut m RwMutex) unlock() { C.pthread_rwlock_unlock(&m.mutex) } diff --git a/vlib/sync/sync_macos.c.v b/vlib/sync/sync_macos.c.v index c92d389087..1c93a7dfb4 100644 --- a/vlib/sync/sync_macos.c.v +++ b/vlib/sync/sync_macos.c.v @@ -80,8 +80,8 @@ pub fn (mut m RwMutex) init() { C.pthread_rwlock_init(&m.mutex, &a.attr) } -// m_lock(), for *manual* mutex handling, since `lock` is a keyword -pub fn (mut m Mutex) m_lock() { +// @lock(), for *manual* mutex handling, since `lock` is a keyword +pub fn (mut m Mutex) @lock() { C.pthread_mutex_lock(&m.mutex) } @@ -90,21 +90,21 @@ pub fn (mut m Mutex) unlock() { } // RwMutex has separate read- and write locks -pub fn (mut m RwMutex) r_lock() { +pub fn (mut m RwMutex) @rlock() { C.pthread_rwlock_rdlock(&m.mutex) } -pub fn (mut m RwMutex) w_lock() { +pub fn (mut m RwMutex) @lock() { C.pthread_rwlock_wrlock(&m.mutex) } // Windows SRWLocks have different function to unlock // So provide two functions here, too, to have a common interface -pub fn (mut m RwMutex) r_unlock() { +pub fn (mut m RwMutex) runlock() { C.pthread_rwlock_unlock(&m.mutex) } -pub fn (mut m RwMutex) w_unlock() { +pub fn (mut m RwMutex) unlock() { C.pthread_rwlock_unlock(&m.mutex) } diff --git a/vlib/sync/sync_windows.c.v b/vlib/sync/sync_windows.c.v index 8f9cc31c28..aa3a0ba5a7 100644 --- a/vlib/sync/sync_windows.c.v +++ b/vlib/sync/sync_windows.c.v @@ -57,7 +57,7 @@ pub fn (mut m RwMutex) init() { C.InitializeSRWLock(&m.mx) } -pub fn (mut m Mutex) m_lock() { +pub fn (mut m Mutex) @lock() { C.AcquireSRWLockExclusive(&m.mx) } @@ -66,21 +66,21 @@ pub fn (mut m Mutex) unlock() { } // RwMutex has separate read- and write locks -pub fn (mut m RwMutex) r_lock() { +pub fn (mut m RwMutex) @rlock() { C.AcquireSRWLockShared(&m.mx) } -pub fn (mut m RwMutex) w_lock() { +pub fn (mut m RwMutex) @lock() { C.AcquireSRWLockExclusive(&m.mx) } // Windows SRWLocks have different function to unlock // So provide two functions here, too, to have a common interface -pub fn (mut m RwMutex) r_unlock() { +pub fn (mut m RwMutex) runlock() { C.ReleaseSRWLockShared(&m.mx) } -pub fn (mut m RwMutex) w_unlock() { +pub fn (mut m RwMutex) unlock() { C.ReleaseSRWLockExclusive(&m.mx) } diff --git a/vlib/sync/waitgroup.v b/vlib/sync/waitgroup.v index 0fd73d02e9..f61cd11e8c 100644 --- a/vlib/sync/waitgroup.v +++ b/vlib/sync/waitgroup.v @@ -30,7 +30,7 @@ pub fn new_waitgroup() &WaitGroup { // add panics if task count drops below zero. pub fn (mut wg WaitGroup) add(delta int) { // protect task_count - wg.task_count_mutex.m_lock() + wg.task_count_mutex.@lock() defer { wg.task_count_mutex.unlock() } diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 40c287bf4b..207f02110a 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -2756,7 +2756,7 @@ fn (mut g Gen) expr(node ast.Expr) { } ast.PostfixExpr { if node.auto_locked != '' { - g.writeln('sync__RwMutex_w_lock(&$node.auto_locked->mtx);') + g.writeln('sync__RwMutex_lock(&$node.auto_locked->mtx);') } g.inside_map_postfix = true g.expr(node.expr) @@ -2764,7 +2764,7 @@ fn (mut g Gen) expr(node ast.Expr) { g.write(node.op.str()) if node.auto_locked != '' { g.writeln(';') - g.write('sync__RwMutex_w_unlock(&$node.auto_locked->mtx)') + g.write('sync__RwMutex_unlock(&$node.auto_locked->mtx)') } } ast.PrefixExpr { @@ -3019,7 +3019,7 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) { // string + string, string == string etc // g.infix_op = node.op if node.auto_locked != '' { - g.writeln('sync__RwMutex_w_lock(&$node.auto_locked->mtx);') + g.writeln('sync__RwMutex_lock(&$node.auto_locked->mtx);') } left_type := g.unwrap_generic(node.left_type) left_sym := g.table.get_type_symbol(left_type) @@ -3409,18 +3409,18 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) { } if node.auto_locked != '' { g.writeln(';') - g.write('sync__RwMutex_w_unlock(&$node.auto_locked->mtx)') + g.write('sync__RwMutex_unlock(&$node.auto_locked->mtx)') } } fn (mut g Gen) lock_expr(node ast.LockExpr) { - mut lock_prefixes := []byte{len: 0, cap: node.lockeds.len} + mut lock_prefixes := []string{len: 0, cap: node.lockeds.len} for id in node.lockeds { name := id.name deref := if id.is_mut { '->' } else { '.' } - lock_prefix := if node.is_rlock { `r` } else { `w` } + lock_prefix := if node.is_rlock { 'r' } else { '' } lock_prefixes << lock_prefix // keep for unlock - g.writeln('sync__RwMutex_${lock_prefix:c}_lock(&$name${deref}mtx);') + g.writeln('sync__RwMutex_${lock_prefix}lock(&$name${deref}mtx);') } g.stmts(node.stmts) // unlock in reverse order @@ -3429,7 +3429,7 @@ fn (mut g Gen) lock_expr(node ast.LockExpr) { lock_prefix := lock_prefixes[i] name := id.name deref := if id.is_mut { '->' } else { '.' } - g.writeln('sync__RwMutex_${lock_prefix:c}_unlock(&$name${deref}mtx);') + g.writeln('sync__RwMutex_${lock_prefix}unlock(&$name${deref}mtx);') } }