all: replace fn name '@xxx' with 'xxx' (#22506)

This commit is contained in:
yuyi 2024-10-13 03:17:02 +08:00 committed by GitHub
parent 45fd7ebcde
commit da3112e545
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
40 changed files with 141 additions and 141 deletions

View File

@ -11,7 +11,7 @@ const run_time = 10 * time.second
fn request(mut mu sync.Mutex, count &int) { fn request(mut mu sync.Mutex, count &int) {
for { for {
http.get('http://vlang.io/utc_now') or { panic(err) } http.get('http://vlang.io/utc_now') or { panic(err) }
mu.@lock() mu.lock()
unsafe { unsafe {
(*count)++ (*count)++
} }

View File

@ -18,7 +18,7 @@ mut:
struct FrameworkBenchmarkResponse { struct FrameworkBenchmarkResponse {
insert []int insert []int
@select []int select []int
update []int update []int
} }
@ -125,9 +125,9 @@ fn insert_framework_benchmark_times() !FrameworkPlatform {
fn select_framework_benchmark_times() !FrameworkPlatform { fn select_framework_benchmark_times() !FrameworkPlatform {
numbers := FrameworkPlatform{ numbers := FrameworkPlatform{
v_sqlite_memory: v_sqlite_memory()!.@select v_sqlite_memory: v_sqlite_memory()!.select
// v_sqlite_file: v_sqlite_file()!.@select // v_sqlite_file: v_sqlite_file()!.select
typescript_sqlite_memory: typescript_sqlite_memory()!.@select typescript_sqlite_memory: typescript_sqlite_memory()!.select
} }
return numbers return numbers
@ -136,7 +136,7 @@ fn select_framework_benchmark_times() !FrameworkPlatform {
fn update_framework_benchmark_times() !FrameworkPlatform { fn update_framework_benchmark_times() !FrameworkPlatform {
numbers := FrameworkPlatform{ numbers := FrameworkPlatform{
v_sqlite_memory: v_sqlite_memory()!.update v_sqlite_memory: v_sqlite_memory()!.update
// v_sqlite_file: v_sqlite_file()!.@select // v_sqlite_file: v_sqlite_file()!.select
typescript_sqlite_memory: typescript_sqlite_memory()!.update typescript_sqlite_memory: typescript_sqlite_memory()!.update
} }
@ -163,7 +163,7 @@ fn v_sqlite_file() !FrameworkBenchmarkResponse {
// framework_benchmark_response := json.decode(FrameworkBenchmarkResponse, res.body)! // framework_benchmark_response := json.decode(FrameworkBenchmarkResponse, res.body)!
framework_benchmark_response := FrameworkBenchmarkResponse{ framework_benchmark_response := FrameworkBenchmarkResponse{
insert: [] insert: []
@select: [] select: []
update: [] update: []
} }
return framework_benchmark_response return framework_benchmark_response

View File

@ -18,7 +18,7 @@ mut:
struct Response { struct Response {
insert []int insert []int
@select []int select []int
update []int update []int
} }
@ -94,7 +94,7 @@ pub fn (mut app App) sqlite_memory(count int) vweb.Result {
response := Response{ response := Response{
insert: insert_stopwatchs insert: insert_stopwatchs
@select: select_stopwatchs select: select_stopwatchs
update: update_stopwatchs update: update_stopwatchs
} }
return app.json(response) return app.json(response)
@ -104,7 +104,7 @@ pub fn (mut app App) sqlite_memory(count int) vweb.Result {
pub fn (mut app App) sqlite_file(count int) vweb.Result { pub fn (mut app App) sqlite_file(count int) vweb.Result {
response := Response{ response := Response{
insert: [] insert: []
@select: [] select: []
update: [] update: []
} }
return app.json(response) return app.json(response)
@ -114,7 +114,7 @@ pub fn (mut app App) sqlite_file(count int) vweb.Result {
pub fn (mut app App) postgres(count int) vweb.Result { pub fn (mut app App) postgres(count int) vweb.Result {
response := Response{ response := Response{
insert: [] insert: []
@select: [] select: []
update: [] update: []
} }
return app.json(response) return app.json(response)
@ -124,7 +124,7 @@ pub fn (mut app App) postgres(count int) vweb.Result {
pub fn (mut app App) mysql(count int) vweb.Result { pub fn (mut app App) mysql(count int) vweb.Result {
response := Response{ response := Response{
insert: [] insert: []
@select: [] select: []
update: [] update: []
} }
return app.json(response) return app.json(response)

View File

@ -215,7 +215,7 @@ pub fn (mut cb Clipboard) free() {
} }
pub fn (mut cb Clipboard) clear() { pub fn (mut cb Clipboard) clear() {
cb.mutex.@lock() cb.mutex.lock()
C.XSetSelectionOwner(cb.display, cb.selection, Window(0), C.CurrentTime) C.XSetSelectionOwner(cb.display, cb.selection, Window(0), C.CurrentTime)
C.XFlush(cb.display) C.XFlush(cb.display)
cb.is_owner = false cb.is_owner = false
@ -237,7 +237,7 @@ pub fn (mut cb Clipboard) set_text(text string) bool {
if cb.window == Window(0) { if cb.window == Window(0) {
return false return false
} }
cb.mutex.@lock() cb.mutex.lock()
cb.text = text cb.text = text
cb.is_owner = true cb.is_owner = true
cb.take_ownership() cb.take_ownership()
@ -281,7 +281,7 @@ fn (mut cb Clipboard) transmit_selection(xse &C.XSelectionEvent) bool {
C.XChangeProperty(xse.display, xse.requestor, xse.property, cb.get_atom(.xa_atom), C.XChangeProperty(xse.display, xse.requestor, xse.property, cb.get_atom(.xa_atom),
32, C.PropModeReplace, targets.data, targets.len) 32, C.PropModeReplace, targets.data, targets.len)
} else if cb.is_supported_target(xse.target) && cb.is_owner && cb.text != '' { } else if cb.is_supported_target(xse.target) && cb.is_owner && cb.text != '' {
cb.mutex.@lock() cb.mutex.lock()
C.XChangeProperty(xse.display, xse.requestor, xse.property, xse.target, 8, C.PropModeReplace, C.XChangeProperty(xse.display, xse.requestor, xse.property, xse.target, 8, C.PropModeReplace,
cb.text.str, cb.text.len) cb.text.str, cb.text.len)
cb.mutex.unlock() cb.mutex.unlock()
@ -313,7 +313,7 @@ fn (mut cb Clipboard) start_listener() {
if unsafe { event.xselectionclear.window == cb.window } && unsafe { if unsafe { event.xselectionclear.window == cb.window } && unsafe {
event.xselectionclear.selection == cb.selection event.xselectionclear.selection == cb.selection
} { } {
cb.mutex.@lock() cb.mutex.lock()
cb.is_owner = false cb.is_owner = false
cb.text = '' cb.text = ''
cb.mutex.unlock() cb.mutex.unlock()
@ -358,7 +358,7 @@ fn (mut cb Clipboard) start_listener() {
} else if unsafe { event.xselection.target == to_be_requested } { } else if unsafe { event.xselection.target == to_be_requested } {
sent_request = false sent_request = false
to_be_requested = Atom(0) to_be_requested = Atom(0)
cb.mutex.@lock() cb.mutex.lock()
prop := unsafe { prop := unsafe {
read_property(event.xselection.display, event.xselection.requestor, read_property(event.xselection.display, event.xselection.requestor,
event.xselection.property) event.xselection.property)

View File

@ -60,14 +60,14 @@ pub fn (ctx &CancelContext) deadline() ?time.Time {
} }
pub fn (mut ctx CancelContext) done() chan int { pub fn (mut ctx CancelContext) done() chan int {
ctx.mutex.@lock() ctx.mutex.lock()
done := ctx.done done := ctx.done
ctx.mutex.unlock() ctx.mutex.unlock()
return done return done
} }
pub fn (mut ctx CancelContext) err() IError { pub fn (mut ctx CancelContext) err() IError {
ctx.mutex.@lock() ctx.mutex.lock()
err := ctx.err err := ctx.err
ctx.mutex.unlock() ctx.mutex.unlock()
return err return err
@ -89,7 +89,7 @@ fn (mut ctx CancelContext) cancel(remove_from_parent bool, err IError) {
panic('context: internal error: missing cancel error') panic('context: internal error: missing cancel error')
} }
ctx.mutex.@lock() ctx.mutex.lock()
if ctx.err !is none { if ctx.err !is none {
ctx.mutex.unlock() ctx.mutex.unlock()
// already canceled // already canceled

View File

@ -61,7 +61,7 @@ pub fn (octx OneContext) done() chan int {
} }
pub fn (mut octx OneContext) err() IError { pub fn (mut octx OneContext) err() IError {
octx.err_mutex.@lock() octx.err_mutex.lock()
defer { defer {
octx.err_mutex.unlock() octx.err_mutex.unlock()
} }
@ -102,7 +102,7 @@ pub fn (octx OneContext) str() string {
pub fn (mut octx OneContext) cancel(err IError) { pub fn (mut octx OneContext) cancel(err IError) {
octx.cancel_fn() octx.cancel_fn()
octx.err_mutex.@lock() octx.err_mutex.lock()
octx.err = err octx.err = err
octx.err_mutex.unlock() octx.err_mutex.unlock()
if !octx.done.closed { if !octx.done.closed {

View File

@ -83,7 +83,7 @@ fn test_mysql_orm() {
data: [orm.string_to_primitive('Louis'), orm.int_to_primitive(101)] data: [orm.string_to_primitive('Louis'), orm.int_to_primitive(101)]
}) or { panic(err) } }) or { panic(err) }
res := db.@select(orm.SelectConfig{ res := db.select(orm.SelectConfig{
table: 'Test' table: 'Test'
has_where: true has_where: true
fields: ['id', 'name', 'age'] fields: ['id', 'name', 'age']

View File

@ -3,8 +3,8 @@ module mysql
import orm import orm
import time import time
// @select is used internally by V's ORM for processing `SELECT ` queries. // select is used internally by V's ORM for processing `SELECT ` queries.
pub fn (db DB) @select(config orm.SelectConfig, data orm.QueryData, where orm.QueryData) ![][]orm.Primitive { pub fn (db DB) select(config orm.SelectConfig, data orm.QueryData, where orm.QueryData) ![][]orm.Primitive {
query := orm.orm_select_gen(config, '`', false, '?', 0, where) query := orm.orm_select_gen(config, '`', false, '?', 0, where)
mut result := [][]orm.Primitive{} mut result := [][]orm.Primitive{}
mut stmt := db.init_stmt(query) mut stmt := db.init_stmt(query)

View File

@ -6,8 +6,8 @@ import net.conv
// sql expr // sql expr
// @select is used internally by V's ORM for processing `SELECT ` queries // select is used internally by V's ORM for processing `SELECT ` queries
pub fn (db DB) @select(config orm.SelectConfig, data orm.QueryData, where orm.QueryData) ![][]orm.Primitive { pub fn (db DB) select(config orm.SelectConfig, data orm.QueryData, where orm.QueryData) ![][]orm.Primitive {
query := orm.orm_select_gen(config, '"', true, '$', 1, where) query := orm.orm_select_gen(config, '"', true, '$', 1, where)
rows := pg_stmt_worker(db, query, where, data)! rows := pg_stmt_worker(db, query, where, data)!

View File

@ -97,7 +97,7 @@ fn test_pg_orm() {
data: [orm.string_to_primitive('Louis'), orm.int_to_primitive(101)] data: [orm.string_to_primitive('Louis'), orm.int_to_primitive(101)]
}) or { panic(err) } }) or { panic(err) }
res := db.@select(orm.SelectConfig{ res := db.select(orm.SelectConfig{
table: 'Test' table: 'Test'
is_count: false is_count: false
has_where: true has_where: true

View File

@ -3,12 +3,12 @@ module sqlite
import orm import orm
import time import time
// @select is used internally by V's ORM for processing `SELECT ` queries // select is used internally by V's ORM for processing `SELECT ` queries
pub fn (db DB) @select(config orm.SelectConfig, data orm.QueryData, where orm.QueryData) ![][]orm.Primitive { pub fn (db DB) select(config orm.SelectConfig, data orm.QueryData, where orm.QueryData) ![][]orm.Primitive {
// 1. Create query and bind necessary data // 1. Create query and bind necessary data
query := orm.orm_select_gen(config, '`', true, '?', 1, where) query := orm.orm_select_gen(config, '`', true, '?', 1, where)
$if trace_sqlite ? { $if trace_sqlite ? {
eprintln('> @select query: "${query}"') eprintln('> select query: "${query}"')
} }
stmt := db.new_init_stmt(query)! stmt := db.new_init_stmt(query)!
defer { defer {

View File

@ -63,7 +63,7 @@ fn test_sqlite_orm() {
data: [orm.string_to_primitive('Louis'), orm.i64_to_primitive(100)] data: [orm.string_to_primitive('Louis'), orm.i64_to_primitive(100)]
}) or { panic(err) } }) or { panic(err) }
res := db.@select(orm.SelectConfig{ res := db.select(orm.SelectConfig{
table: 'Test' table: 'Test'
has_where: true has_where: true
fields: ['id', 'name', 'age'] fields: ['id', 'name', 'age']

View File

@ -32,7 +32,7 @@ pub fn (mut x ThreadSafeLog) free() {
// set_level changes the log level // set_level changes the log level
pub fn (mut x ThreadSafeLog) set_level(level Level) { pub fn (mut x ThreadSafeLog) set_level(level Level) {
x.mu.@lock() x.mu.lock()
x.Log.set_level(level) x.Log.set_level(level)
x.mu.unlock() x.mu.unlock()
} }
@ -40,35 +40,35 @@ pub fn (mut x ThreadSafeLog) set_level(level Level) {
// set_always_flush called with true, will make the log flush after every single .fatal(), .error(), .warn(), .info(), .debug() call. // set_always_flush called with true, will make the log flush after every single .fatal(), .error(), .warn(), .info(), .debug() call.
// That can be much slower, if you plan to do lots of frequent calls, but if your program exits early or crashes, your logs will be more complete. // That can be much slower, if you plan to do lots of frequent calls, but if your program exits early or crashes, your logs will be more complete.
pub fn (mut x ThreadSafeLog) set_always_flush(should_flush bool) { pub fn (mut x ThreadSafeLog) set_always_flush(should_flush bool) {
x.mu.@lock() x.mu.lock()
x.Log.set_always_flush(should_flush) x.Log.set_always_flush(should_flush)
x.mu.unlock() x.mu.unlock()
} }
// debug logs a debug message // debug logs a debug message
pub fn (mut x ThreadSafeLog) debug(s string) { pub fn (mut x ThreadSafeLog) debug(s string) {
x.mu.@lock() x.mu.lock()
x.Log.debug(s) x.Log.debug(s)
x.mu.unlock() x.mu.unlock()
} }
// info logs an info messagep // info logs an info messagep
pub fn (mut x ThreadSafeLog) info(s string) { pub fn (mut x ThreadSafeLog) info(s string) {
x.mu.@lock() x.mu.lock()
x.Log.info(s) x.Log.info(s)
x.mu.unlock() x.mu.unlock()
} }
// warn logs a warning message // warn logs a warning message
pub fn (mut x ThreadSafeLog) warn(s string) { pub fn (mut x ThreadSafeLog) warn(s string) {
x.mu.@lock() x.mu.lock()
x.Log.warn(s) x.Log.warn(s)
x.mu.unlock() x.mu.unlock()
} }
// error logs an error message // error logs an error message
pub fn (mut x ThreadSafeLog) error(s string) { pub fn (mut x ThreadSafeLog) error(s string) {
x.mu.@lock() x.mu.lock()
x.Log.error(s) x.Log.error(s)
x.mu.unlock() x.mu.unlock()
} }
@ -76,7 +76,7 @@ pub fn (mut x ThreadSafeLog) error(s string) {
// fatal logs a fatal message, and panics // fatal logs a fatal message, and panics
@[noreturn] @[noreturn]
pub fn (mut x ThreadSafeLog) fatal(s string) { pub fn (mut x ThreadSafeLog) fatal(s string) {
x.mu.@lock() x.mu.lock()
defer { defer {
// TODO: Log.fatal() is marked as noreturn, but this defer is allowed. // TODO: Log.fatal() is marked as noreturn, but this defer is allowed.
// Think whether it should be, or if it should be a compiler notice at least, // Think whether it should be, or if it should be a compiler notice at least,

View File

@ -104,7 +104,7 @@ fn C.ioctlsocket(s int, cmd int, argp &u32) int
fn C.fcntl(fd int, cmd int, arg ...voidptr) int fn C.fcntl(fd int, cmd int, arg ...voidptr) int
fn C.@select(ndfs int, readfds &C.fd_set, writefds &C.fd_set, exceptfds &C.fd_set, timeout &C.timeval) int fn C.select(ndfs int, readfds &C.fd_set, writefds &C.fd_set, exceptfds &C.fd_set, timeout &C.timeval) int
fn C.FD_ZERO(fdset &C.fd_set) fn C.FD_ZERO(fdset &C.fd_set)

View File

@ -106,7 +106,7 @@ pub fn close(handle int) ! {
} }
// Select waits for an io operation (specified by parameter `test`) to be available // Select waits for an io operation (specified by parameter `test`) to be available
fn @select(handle int, test Select, timeout time.Duration) !bool { fn select(handle int, test Select, timeout time.Duration) !bool {
set := C.fd_set{} set := C.fd_set{}
C.FD_ZERO(&set) C.FD_ZERO(&set)
@ -130,13 +130,13 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
match test { match test {
.read { .read {
socket_error(C.@select(handle + 1, &set, C.NULL, C.NULL, timeval_timeout))! socket_error(C.select(handle + 1, &set, C.NULL, C.NULL, timeval_timeout))!
} }
.write { .write {
socket_error(C.@select(handle + 1, C.NULL, &set, C.NULL, timeval_timeout))! socket_error(C.select(handle + 1, C.NULL, &set, C.NULL, timeval_timeout))!
} }
.except { .except {
socket_error(C.@select(handle + 1, C.NULL, C.NULL, &set, timeval_timeout))! socket_error(C.select(handle + 1, C.NULL, C.NULL, &set, timeval_timeout))!
} }
} }
@ -149,7 +149,7 @@ fn select_deadline(handle int, test Select, deadline time.Time) !bool {
infinite := deadline.unix() == 0 infinite := deadline.unix() == 0
for infinite || time.now() <= deadline { for infinite || time.now() <= deadline {
timeout := if infinite { infinite_timeout } else { deadline - time.now() } timeout := if infinite { infinite_timeout } else { deadline - time.now() }
ready := @select(handle, test, timeout) or { ready := select(handle, test, timeout) or {
if err.code() == C.EINTR { if err.code() == C.EINTR {
// errno is 4, Spurious wakeup from signal, keep waiting // errno is 4, Spurious wakeup from signal, keep waiting
continue continue

View File

@ -21,7 +21,7 @@ pub enum Method { // as of 2023-06-20
delete delete
label label
link link
@lock lock
merge merge
mkactivity mkactivity
mkcalendar mkcalendar
@ -66,7 +66,7 @@ pub fn (m Method) str() string {
.delete { 'DELETE' } .delete { 'DELETE' }
.label { 'LABEL' } .label { 'LABEL' }
.link { 'LINK' } .link { 'LINK' }
.@lock { 'LOCK' } .lock { 'LOCK' }
.merge { 'MERGE' } .merge { 'MERGE' }
.mkactivity { 'MKACTIVITY' } .mkactivity { 'MKACTIVITY' }
.mkcalendar { 'MKCALENDAR' } .mkcalendar { 'MKCALENDAR' }
@ -115,7 +115,7 @@ pub fn method_from_str(m string) Method {
'DELETE' { Method.delete } 'DELETE' { Method.delete }
'LABEL' { Method.label } 'LABEL' { Method.label }
'LINK' { Method.link } 'LINK' { Method.link }
'LOCK' { Method.@lock } 'LOCK' { Method.lock }
'MERGE' { Method.merge } 'MERGE' { Method.merge }
'MKACTIVITY' { Method.mkactivity } 'MKACTIVITY' { Method.mkactivity }
'MKCALENDAR' { Method.mkcalendar } 'MKCALENDAR' { Method.mkcalendar }

View File

@ -629,7 +629,7 @@ pub fn (mut s SSLConn) write_string(str string) !int {
} }
// Select waits for an io operation (specified by parameter `test`) to be available // Select waits for an io operation (specified by parameter `test`) to be available
fn @select(handle int, test Select, timeout time.Duration) !bool { fn select(handle int, test Select, timeout time.Duration) !bool {
$if trace_ssl ? { $if trace_ssl ? {
eprintln('${@METHOD} handle: ${handle}, timeout: ${timeout}') eprintln('${@METHOD} handle: ${handle}, timeout: ${timeout}')
} }
@ -656,13 +656,13 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
mut res := -1 mut res := -1
match test { match test {
.read { .read {
res = net.socket_error(C.@select(handle + 1, &set, C.NULL, C.NULL, timeval_timeout))! res = net.socket_error(C.select(handle + 1, &set, C.NULL, C.NULL, timeval_timeout))!
} }
.write { .write {
res = net.socket_error(C.@select(handle + 1, C.NULL, &set, C.NULL, timeval_timeout))! res = net.socket_error(C.select(handle + 1, C.NULL, &set, C.NULL, timeval_timeout))!
} }
.except { .except {
res = net.socket_error(C.@select(handle + 1, C.NULL, C.NULL, &set, timeval_timeout))! res = net.socket_error(C.select(handle + 1, C.NULL, C.NULL, &set, timeval_timeout))!
} }
} }
if res < 0 { if res < 0 {
@ -688,7 +688,7 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
// wait_for wraps the common wait code // wait_for wraps the common wait code
fn wait_for(handle int, what Select, timeout time.Duration) ! { fn wait_for(handle int, what Select, timeout time.Duration) ! {
ready := @select(handle, what, timeout)! ready := select(handle, what, timeout)!
if ready { if ready {
return return
} }

View File

@ -384,7 +384,7 @@ pub fn (mut s SSLConn) write_string(str string) !int {
} }
// Select waits for an io operation (specified by parameter `test`) to be available // Select waits for an io operation (specified by parameter `test`) to be available
fn @select(handle int, test Select, timeout time.Duration) !bool { fn select(handle int, test Select, timeout time.Duration) !bool {
$if trace_ssl ? { $if trace_ssl ? {
eprintln('${@METHOD} handle: ${handle}, timeout: ${timeout}') eprintln('${@METHOD} handle: ${handle}, timeout: ${timeout}')
} }
@ -411,13 +411,13 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
mut res := -1 mut res := -1
match test { match test {
.read { .read {
res = net.socket_error(C.@select(handle + 1, &set, C.NULL, C.NULL, timeval_timeout))! res = net.socket_error(C.select(handle + 1, &set, C.NULL, C.NULL, timeval_timeout))!
} }
.write { .write {
res = net.socket_error(C.@select(handle + 1, C.NULL, &set, C.NULL, timeval_timeout))! res = net.socket_error(C.select(handle + 1, C.NULL, &set, C.NULL, timeval_timeout))!
} }
.except { .except {
res = net.socket_error(C.@select(handle + 1, C.NULL, C.NULL, &set, timeval_timeout))! res = net.socket_error(C.select(handle + 1, C.NULL, C.NULL, &set, timeval_timeout))!
} }
} }
if res < 0 { if res < 0 {
@ -443,7 +443,7 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
// wait_for wraps the common wait code // wait_for wraps the common wait code
fn wait_for(handle int, what Select, timeout time.Duration) ! { fn wait_for(handle int, what Select, timeout time.Duration) ! {
ready := @select(handle, what, timeout)! ready := select(handle, what, timeout)!
if ready { if ready {
return return
} }

View File

@ -145,7 +145,7 @@ pub fn (c TcpConn) read_ptr(buf_ptr &u8, len int) !int {
// The new socket returned by accept() behaves differently in blocking mode and needs special treatment. // The new socket returned by accept() behaves differently in blocking mode and needs special treatment.
mut has_data := true mut has_data := true
if c.is_blocking { if c.is_blocking {
if ok := @select(c.sock.handle, .read, 1) { if ok := select(c.sock.handle, .read, 1) {
has_data = ok has_data = ok
} else { } else {
false false
@ -392,7 +392,7 @@ pub fn listen_tcp(family AddrFamily, saddr string, options ListenOptions) !&TcpL
for { for {
code := error_code() code := error_code()
if code in [int(error_einprogress), int(error_ewouldblock), int(error_eagain), C.EINTR] { if code in [int(error_einprogress), int(error_ewouldblock), int(error_eagain), C.EINTR] {
@select(s.handle, .read, connect_timeout)! select(s.handle, .read, connect_timeout)!
res = C.listen(s.handle, options.backlog) res = C.listen(s.handle, options.backlog)
if res == 0 { if res == 0 {
break break
@ -655,7 +655,7 @@ fn (mut s TcpSocket) connect(a Addr) ! {
// determine whether connect() completed successfully (SO_ERROR is zero) or // determine whether connect() completed successfully (SO_ERROR is zero) or
// unsuccessfully (SO_ERROR is one of the usual error codes listed here, // unsuccessfully (SO_ERROR is one of the usual error codes listed here,
// ex plaining the reason for the failure). // ex plaining the reason for the failure).
write_result := @select(s.handle, .write, connect_timeout)! write_result := select(s.handle, .write, connect_timeout)!
err := 0 err := 0
len := sizeof(err) len := sizeof(err)
xyz := C.getsockopt(s.handle, C.SOL_SOCKET, C.SO_ERROR, &err, &len) xyz := C.getsockopt(s.handle, C.SOL_SOCKET, C.SO_ERROR, &err, &len)

View File

@ -274,8 +274,8 @@ fn (mut s UdpSocket) close() ! {
return close(s.handle) return close(s.handle)
} }
fn (mut s UdpSocket) @select(test Select, timeout time.Duration) !bool { fn (mut s UdpSocket) select(test Select, timeout time.Duration) !bool {
return @select(s.handle, test, timeout) return select(s.handle, test, timeout)
} }
fn (s &UdpSocket) remote() !Addr { fn (s &UdpSocket) remote() !Addr {

View File

@ -29,7 +29,7 @@ pub fn shutdown(handle int, config net.ShutdownConfig) int {
} }
// Select waits for an io operation (specified by parameter `test`) to be available // Select waits for an io operation (specified by parameter `test`) to be available
fn @select(handle int, test Select, timeout time.Duration) !bool { fn select(handle int, test Select, timeout time.Duration) !bool {
set := C.fd_set{} set := C.fd_set{}
C.FD_ZERO(&set) C.FD_ZERO(&set)
@ -53,13 +53,13 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
match test { match test {
.read { .read {
net.socket_error(C.@select(handle + 1, &set, C.NULL, C.NULL, timeval_timeout))! net.socket_error(C.select(handle + 1, &set, C.NULL, C.NULL, timeval_timeout))!
} }
.write { .write {
net.socket_error(C.@select(handle + 1, C.NULL, &set, C.NULL, timeval_timeout))! net.socket_error(C.select(handle + 1, C.NULL, &set, C.NULL, timeval_timeout))!
} }
.except { .except {
net.socket_error(C.@select(handle + 1, C.NULL, C.NULL, &set, timeval_timeout))! net.socket_error(C.select(handle + 1, C.NULL, C.NULL, &set, timeval_timeout))!
} }
} }
@ -72,7 +72,7 @@ fn select_deadline(handle int, test Select, deadline time.Time) !bool {
infinite := deadline.unix() == 0 infinite := deadline.unix() == 0
for infinite || time.now() <= deadline { for infinite || time.now() <= deadline {
timeout := if infinite { net.infinite_timeout } else { deadline - time.now() } timeout := if infinite { net.infinite_timeout } else { deadline - time.now() }
ready := @select(handle, test, timeout) or { ready := select(handle, test, timeout) or {
if err.code() == 4 { if err.code() == 4 {
// Spurious wakeup from signal, keep waiting // Spurious wakeup from signal, keep waiting
continue continue

View File

@ -407,8 +407,8 @@ fn (mut s StreamSocket) close() ! {
return close(s.handle) return close(s.handle)
} }
fn (mut s StreamSocket) @select(test Select, timeout time.Duration) !bool { fn (mut s StreamSocket) select(test Select, timeout time.Duration) !bool {
return @select(s.handle, test, timeout) return select(s.handle, test, timeout)
} }
// set_option sets an option on the socket // set_option sets an option on the socket
@ -462,7 +462,7 @@ fn (mut s StreamSocket) connect(socket_path string) ! {
if ecode == int(net.error_ewouldblock) { if ecode == int(net.error_ewouldblock) {
// The socket is nonblocking and the connection cannot be completed // The socket is nonblocking and the connection cannot be completed
// immediately. Wait till the socket is ready to write // immediately. Wait till the socket is ready to write
write_result := s.@select(.write, connect_timeout)! write_result := s.select(.write, connect_timeout)!
err := 0 err := 0
len := sizeof(err) len := sizeof(err)
// determine whether connect() completed successfully (SO_ERROR is zero) // determine whether connect() completed successfully (SO_ERROR is zero)

View File

@ -193,7 +193,7 @@ pub:
// Every function without last_id() returns an optional, which returns an error if present // Every function without last_id() returns an optional, which returns an error if present
// last_id returns the last inserted id of the db // last_id returns the last inserted id of the db
pub interface Connection { pub interface Connection {
@select(config SelectConfig, data QueryData, where QueryData) ![][]Primitive select(config SelectConfig, data QueryData, where QueryData) ![][]Primitive
insert(table string, data QueryData) ! insert(table string, data QueryData) !
update(table string, data QueryData, where QueryData) ! update(table string, data QueryData, where QueryData) !
delete(table string, where QueryData) ! delete(table string, where QueryData) !

View File

@ -23,12 +23,12 @@ fn MockDB.new() &MockDB {
} }
} }
fn (db MockDB) @select(config orm.SelectConfig, data orm.QueryData, where orm.QueryData) ![][]orm.Primitive { fn (db MockDB) select(config orm.SelectConfig, data orm.QueryData, where orm.QueryData) ![][]orm.Primitive {
mut st := db.st mut st := db.st
st.last = orm.orm_select_gen(config, '`', false, '?', 5, where) st.last = orm.orm_select_gen(config, '`', false, '?', 5, where)
st.data = data.data st.data = data.data
st.where = where.data st.where = where.data
return db.db.@select(config, data, where) return db.db.select(config, data, where)
} }
fn (db MockDB) insert(table string, data orm.QueryData) ! { fn (db MockDB) insert(table string, data orm.QueryData) ! {

View File

@ -80,7 +80,7 @@ pub:
tv_usec u64 tv_usec u64
} }
fn C.@select(ndfs int, readfds &C.fd_set, writefds &C.fd_set, exceptfds &C.fd_set, timeout &C.timeval) int fn C.select(ndfs int, readfds &C.fd_set, writefds &C.fd_set, exceptfds &C.fd_set, timeout &C.timeval) int
// These are C macros, but from the V's point of view, can be treated as C functions: // These are C macros, but from the V's point of view, can be treated as C functions:
fn C.FD_ZERO(fdset &C.fd_set) fn C.FD_ZERO(fdset &C.fd_set)
@ -97,7 +97,7 @@ pub fn fd_is_pending(fd int) bool {
tv_sec: 0 tv_sec: 0
tv_usec: 0 tv_usec: 0
} }
res := C.@select(fd + 1, &read_set, C.NULL, C.NULL, &ts) res := C.select(fd + 1, &read_set, C.NULL, C.NULL, &ts)
if res > 0 { if res > 0 {
if C.FD_ISSET(fd, &read_set) != 0 { if C.FD_ISSET(fd, &read_set) != 0 {
return true return true

View File

@ -68,7 +68,7 @@ fn (mut pv Picoev) poll_once(max_wait_in_sec int) int {
tv_sec: u64(max_wait_in_sec) tv_sec: u64(max_wait_in_sec)
tv_usec: 0 tv_usec: 0
} }
r := C.@select(maxfd + 1, &readfds, &writefds, &errorfds, &tv) r := C.select(maxfd + 1, &readfds, &writefds, &errorfds, &tv)
if r == -1 { if r == -1 {
// timeout // timeout
return -1 return -1

View File

@ -27,7 +27,7 @@ pub fn (mut m ManyTimes) do(f fn ()) {
} }
fn (mut m ManyTimes) do_slow(f fn ()) { fn (mut m ManyTimes) do_slow(f fn ()) {
m.m.@lock() m.m.lock()
if m.count < m.times { if m.count < m.times {
stdatomic.store_u64(&m.count, m.count + 1) stdatomic.store_u64(&m.count, m.count + 1)
f() f()

View File

@ -6,7 +6,7 @@ pub mut:
} }
fn write_10000(mut co Counter, mut mx sync.Mutex) { fn write_10000(mut co Counter, mut mx sync.Mutex) {
mx.@lock() mx.lock()
co.i = 10000 co.i = 10000
mx.unlock() mx.unlock()
} }
@ -14,7 +14,7 @@ fn write_10000(mut co Counter, mut mx sync.Mutex) {
fn test_mutex() { fn test_mutex() {
mut co := &Counter{10086} mut co := &Counter{10086}
mut mx := sync.new_mutex() mut mx := sync.new_mutex()
mx.@lock() mx.lock()
co.i = 888 co.i = 888
th := spawn write_10000(mut co, mut mx) th := spawn write_10000(mut co, mut mx)
mx.unlock() // after mx unlock, thread write_10000 can continue mx.unlock() // after mx unlock, thread write_10000 can continue
@ -31,7 +31,7 @@ fn test_try_lock_mutex() {
} }
} }
mut mx := sync.new_mutex() mut mx := sync.new_mutex()
mx.@lock() mx.lock()
try_fail := mx.try_lock() try_fail := mx.try_lock()
assert try_fail == false assert try_fail == false
mx.unlock() mx.unlock()

View File

@ -24,7 +24,7 @@ pub fn (mut o Once) do(f fn ()) {
} }
fn (mut o Once) do_slow(f fn ()) { fn (mut o Once) do_slow(f fn ()) {
o.m.@lock() o.m.lock()
if o.count < 1 { if o.count < 1 {
stdatomic.store_u64(&o.count, 1) stdatomic.store_u64(&o.count, 1)
f() f()
@ -56,7 +56,7 @@ pub fn (mut o Once) do_with_param(f fn (voidptr), param voidptr) {
} }
fn (mut o Once) do_slow_with_param(f fn (p voidptr), param voidptr) { fn (mut o Once) do_slow_with_param(f fn (p voidptr), param voidptr) {
o.m.@lock() o.m.lock()
if o.count < 1 { if o.count < 1 {
stdatomic.store_u64(&o.count, 1) stdatomic.store_u64(&o.count, 1)
f(param) f(param)

View File

@ -7,7 +7,7 @@ pub mut:
} }
fn write_10000(mut co Counter, mut mx sync.RwMutex) { fn write_10000(mut co Counter, mut mx sync.RwMutex) {
mx.@lock() mx.lock()
co.i = 10000 co.i = 10000
mx.unlock() mx.unlock()
} }
@ -15,14 +15,14 @@ fn write_10000(mut co Counter, mut mx sync.RwMutex) {
fn test_rwmutex() { fn test_rwmutex() {
mut co := &Counter{10086} mut co := &Counter{10086}
mut mx := sync.new_rwmutex() mut mx := sync.new_rwmutex()
mx.@lock() mx.lock()
co.i = 888 co.i = 888
th1 := spawn write_10000(mut co, mut mx) th1 := spawn write_10000(mut co, mut mx)
mx.unlock() // after mx unlock, thread write_10000 can continue mx.unlock() // after mx unlock, thread write_10000 can continue
th1.wait() th1.wait()
assert co.i == 10000 assert co.i == 10000
mx.@rlock() mx.rlock()
th2 := spawn write_10000(mut co, mut mx) // write_10000 will be blocked th2 := spawn write_10000(mut co, mut mx) // write_10000 will be blocked
co.i = 999 // for demo purpose, don't modify data in rlock! co.i = 999 // for demo purpose, don't modify data in rlock!
time.sleep(1 * time.millisecond) time.sleep(1 * time.millisecond)
@ -43,7 +43,7 @@ fn test_try_lock_rwmutex() {
mut mx := sync.new_rwmutex() mut mx := sync.new_rwmutex()
// try_rlock will always fail when mx locked // try_rlock will always fail when mx locked
mx.@lock() mx.lock()
try_fail_reading1 := mx.try_rlock() try_fail_reading1 := mx.try_rlock()
try_fail_writing1 := mx.try_wlock() try_fail_writing1 := mx.try_wlock()
assert try_fail_reading1 == false assert try_fail_reading1 == false

View File

@ -115,10 +115,10 @@ pub fn (mut m RwMutex) init() {
C.pthread_rwlock_init(&m.mutex, &a.attr) C.pthread_rwlock_init(&m.mutex, &a.attr)
} }
// @lock locks the mutex instance (`lock` is a keyword). // lock locks the mutex instance (`lock` is a keyword).
// If the mutex was already locked, it will block, till it is unlocked. // If the mutex was already locked, it will block, till it is unlocked.
@[inline] @[inline]
pub fn (mut m Mutex) @lock() { pub fn (mut m Mutex) lock() {
C.pthread_mutex_lock(&m.mutex) C.pthread_mutex_lock(&m.mutex)
} }
@ -130,7 +130,7 @@ pub fn (mut m Mutex) try_lock() bool {
} }
// unlock unlocks the mutex instance. The mutex is released, and one of // unlock unlocks the mutex instance. The mutex is released, and one of
// the other threads, that were blocked, because they called @lock can continue. // the other threads, that were blocked, because they called lock can continue.
@[inline] @[inline]
pub fn (mut m Mutex) unlock() { pub fn (mut m Mutex) unlock() {
C.pthread_mutex_unlock(&m.mutex) C.pthread_mutex_unlock(&m.mutex)
@ -146,25 +146,25 @@ pub fn (mut m Mutex) destroy() {
} }
} }
// @rlock locks the given RwMutex instance for reading. // rlock locks the given RwMutex instance for reading.
// If the mutex was already locked, it will block, and will try to get the lock, // If the mutex was already locked, it will block, and will try to get the lock,
// once the lock is released by another thread calling unlock. // once the lock is released by another thread calling unlock.
// Once it succeds, it returns. // Once it succeds, it returns.
// Note: there may be several threads that are waiting for the same lock. // Note: there may be several threads that are waiting for the same lock.
// Note: RwMutex has separate read and write locks. // Note: RwMutex has separate read and write locks.
@[inline] @[inline]
pub fn (mut m RwMutex) @rlock() { pub fn (mut m RwMutex) rlock() {
C.pthread_rwlock_rdlock(&m.mutex) C.pthread_rwlock_rdlock(&m.mutex)
} }
// @lock locks the given RwMutex instance for writing. // lock locks the given RwMutex instance for writing.
// If the mutex was already locked, it will block, till it is unlocked, // If the mutex was already locked, it will block, till it is unlocked,
// then it will try to get the lock, and if it can, it will return, otherwise // then it will try to get the lock, and if it can, it will return, otherwise
// it will continue waiting for the mutex to become unlocked. // it will continue waiting for the mutex to become unlocked.
// Note: there may be several threads that are waiting for the same lock. // Note: there may be several threads that are waiting for the same lock.
// Note: RwMutex has separate read and write locks. // Note: RwMutex has separate read and write locks.
@[inline] @[inline]
pub fn (mut m RwMutex) @lock() { pub fn (mut m RwMutex) lock() {
C.pthread_rwlock_wrlock(&m.mutex) C.pthread_rwlock_wrlock(&m.mutex)
} }

View File

@ -102,10 +102,10 @@ pub fn (mut m RwMutex) init() {
C.pthread_rwlockattr_destroy(&a.attr) // destroy the attr when done C.pthread_rwlockattr_destroy(&a.attr) // destroy the attr when done
} }
// @lock locks the mutex instance (`lock` is a keyword). // lock locks the mutex instance (`lock` is a keyword).
// If the mutex was already locked, it will block, till it is unlocked. // If the mutex was already locked, it will block, till it is unlocked.
@[inline] @[inline]
pub fn (mut m Mutex) @lock() { pub fn (mut m Mutex) lock() {
C.pthread_mutex_lock(&m.mutex) C.pthread_mutex_lock(&m.mutex)
} }
@ -117,7 +117,7 @@ pub fn (mut m Mutex) try_lock() bool {
} }
// unlock unlocks the mutex instance. The mutex is released, and one of // unlock unlocks the mutex instance. The mutex is released, and one of
// the other threads, that were blocked, because they called @lock can continue. // the other threads, that were blocked, because they called lock can continue.
@[inline] @[inline]
pub fn (mut m Mutex) unlock() { pub fn (mut m Mutex) unlock() {
C.pthread_mutex_unlock(&m.mutex) C.pthread_mutex_unlock(&m.mutex)
@ -132,25 +132,25 @@ pub fn (mut m Mutex) destroy() {
} }
} }
// @rlock locks the given RwMutex instance for reading. // rlock locks the given RwMutex instance for reading.
// If the mutex was already locked, it will block, and will try to get the lock, // If the mutex was already locked, it will block, and will try to get the lock,
// once the lock is released by another thread calling unlock. // once the lock is released by another thread calling unlock.
// Once it succeds, it returns. // Once it succeds, it returns.
// Note: there may be several threads that are waiting for the same lock. // Note: there may be several threads that are waiting for the same lock.
// Note: RwMutex has separate read and write locks. // Note: RwMutex has separate read and write locks.
@[inline] @[inline]
pub fn (mut m RwMutex) @rlock() { pub fn (mut m RwMutex) rlock() {
C.pthread_rwlock_rdlock(&m.mutex) C.pthread_rwlock_rdlock(&m.mutex)
} }
// @lock locks the given RwMutex instance for writing. // lock locks the given RwMutex instance for writing.
// If the mutex was already locked, it will block, till it is unlocked, // If the mutex was already locked, it will block, till it is unlocked,
// then it will try to get the lock, and if it can, it will return, otherwise // then it will try to get the lock, and if it can, it will return, otherwise
// it will continue waiting for the mutex to become unlocked. // it will continue waiting for the mutex to become unlocked.
// Note: there may be several threads that are waiting for the same lock. // Note: there may be several threads that are waiting for the same lock.
// Note: RwMutex has separate read and write locks. // Note: RwMutex has separate read and write locks.
@[inline] @[inline]
pub fn (mut m RwMutex) @lock() { pub fn (mut m RwMutex) lock() {
C.pthread_rwlock_wrlock(&m.mutex) C.pthread_rwlock_wrlock(&m.mutex)
} }

View File

@ -100,10 +100,10 @@ pub fn (mut m RwMutex) init() {
C.pthread_rwlockattr_destroy(&a.attr) // destroy the attr when done C.pthread_rwlockattr_destroy(&a.attr) // destroy the attr when done
} }
// @lock locks the mutex instance (`lock` is a keyword). // lock locks the mutex instance (`lock` is a keyword).
// If the mutex was already locked, it will block, till it is unlocked. // If the mutex was already locked, it will block, till it is unlocked.
@[inline] @[inline]
pub fn (mut m Mutex) @lock() { pub fn (mut m Mutex) lock() {
C.pthread_mutex_lock(&m.mutex) C.pthread_mutex_lock(&m.mutex)
} }
@ -115,7 +115,7 @@ pub fn (mut m Mutex) try_lock() bool {
} }
// unlock unlocks the mutex instance. The mutex is released, and one of // unlock unlocks the mutex instance. The mutex is released, and one of
// the other threads, that were blocked, because they called @lock can continue. // the other threads, that were blocked, because they called lock can continue.
@[inline] @[inline]
pub fn (mut m Mutex) unlock() { pub fn (mut m Mutex) unlock() {
C.pthread_mutex_unlock(&m.mutex) C.pthread_mutex_unlock(&m.mutex)
@ -130,25 +130,25 @@ pub fn (mut m Mutex) destroy() {
} }
} }
// @rlock locks the given RwMutex instance for reading. // rlock locks the given RwMutex instance for reading.
// If the mutex was already locked, it will block, and will try to get the lock, // If the mutex was already locked, it will block, and will try to get the lock,
// once the lock is released by another thread calling unlock. // once the lock is released by another thread calling unlock.
// Once it succeds, it returns. // Once it succeds, it returns.
// Note: there may be several threads that are waiting for the same lock. // Note: there may be several threads that are waiting for the same lock.
// Note: RwMutex has separate read and write locks. // Note: RwMutex has separate read and write locks.
@[inline] @[inline]
pub fn (mut m RwMutex) @rlock() { pub fn (mut m RwMutex) rlock() {
C.pthread_rwlock_rdlock(&m.mutex) C.pthread_rwlock_rdlock(&m.mutex)
} }
// @lock locks the given RwMutex instance for writing. // lock locks the given RwMutex instance for writing.
// If the mutex was already locked, it will block, till it is unlocked, // If the mutex was already locked, it will block, till it is unlocked,
// then it will try to get the lock, and if it can, it will return, otherwise // then it will try to get the lock, and if it can, it will return, otherwise
// it will continue waiting for the mutex to become unlocked. // it will continue waiting for the mutex to become unlocked.
// Note: there may be several threads that are waiting for the same lock. // Note: there may be several threads that are waiting for the same lock.
// Note: RwMutex has separate read and write locks. // Note: RwMutex has separate read and write locks.
@[inline] @[inline]
pub fn (mut m RwMutex) @lock() { pub fn (mut m RwMutex) lock() {
C.pthread_rwlock_wrlock(&m.mutex) C.pthread_rwlock_wrlock(&m.mutex)
} }

View File

@ -72,7 +72,7 @@ pub fn (mut m RwMutex) init() {
C.InitializeSRWLock(&m.mx) C.InitializeSRWLock(&m.mx)
} }
pub fn (mut m Mutex) @lock() { pub fn (mut m Mutex) lock() {
C.AcquireSRWLockExclusive(&m.mx) C.AcquireSRWLockExclusive(&m.mx)
} }
@ -94,11 +94,11 @@ pub fn (mut m Mutex) unlock() {
} }
// RwMutex has separate read- and write locks // RwMutex has separate read- and write locks
pub fn (mut m RwMutex) @rlock() { pub fn (mut m RwMutex) rlock() {
C.AcquireSRWLockShared(&m.mx) C.AcquireSRWLockShared(&m.mx)
} }
pub fn (mut m RwMutex) @lock() { pub fn (mut m RwMutex) lock() {
C.AcquireSRWLockExclusive(&m.mx) C.AcquireSRWLockExclusive(&m.mx)
} }

View File

@ -1395,7 +1395,7 @@ pub mut:
pub struct EnumField { pub struct EnumField {
pub: pub:
name string // just `lock`, or `abc`, etc, no matter if the name is a keyword or not. name string // just `lock`, or `abc`, etc, no matter if the name is a keyword or not.
source_name string // The name in the source, for example `@lock`, and `abc`. Note that `lock` is a keyword in V. source_name string // The name in the source, for example `lock`, and `abc`. Note that `lock` is a keyword in V.
pos token.Pos pos token.Pos
pre_comments []Comment // comment before Enumfield pre_comments []Comment // comment before Enumfield
comments []Comment // comment after Enumfield in the same line comments []Comment // comment after Enumfield in the same line

View File

@ -22,8 +22,8 @@ enum SqlExprSide {
// select from User // select from User
// } // }
// ``` // ```
// cgen will write calling the function `@select` of the needed database. // cgen will write calling the function `select` of the needed database.
// If you use sqlite, it calls `@select` from `vlib/db/sqlite/orm.v` // If you use sqlite, it calls `select` from `vlib/db/sqlite/orm.v`
// sql_select_expr writes C code that calls ORM functions for selecting objects // sql_select_expr writes C code that calls ORM functions for selecting objects
// from the database, which is used by the `select` query. // from the database, which is used by the `select` query.

View File

@ -2,14 +2,14 @@ import sync
fn main() { fn main() {
mut mutex := sync.new_mutex() mut mutex := sync.new_mutex()
mutex.@lock() mutex.lock()
mutex.unlock() mutex.unlock()
mutex.destroy() mutex.destroy()
mut rwmutex := sync.new_rwmutex() mut rwmutex := sync.new_rwmutex()
rwmutex.@rlock() rwmutex.rlock()
rwmutex.unlock() rwmutex.unlock()
rwmutex.@lock() rwmutex.lock()
rwmutex.unlock() rwmutex.unlock()
rwmutex.destroy() rwmutex.destroy()

View File

@ -1,9 +1,9 @@
enum MyEnum { enum MyEnum {
abc abc
def def
@lock lock
xyz xyz
@if if
} }
@[flag] @[flag]
@ -38,8 +38,8 @@ fn test_enum_from_string() {
y := MyFlaggedEnum.from('xyz')! y := MyFlaggedEnum.from('xyz')!
dump(y) dump(y)
assert y == .xyz assert y == .xyz
assert MyEnum.from('if')! == MyEnum.@if assert MyEnum.from('if')! == MyEnum.if
assert MyEnum.from('lock')! == MyEnum.@lock assert MyEnum.from('lock')! == MyEnum.lock
if z := MyEnum.from('unknown') { if z := MyEnum.from('unknown') {
assert false assert false
} else { } else {

View File

@ -155,7 +155,7 @@ fn switch2() u64 {
mut cnt := u64(0) mut cnt := u64(0)
for { for {
cnt++ cnt++
mtx.@lock() mtx.lock()
f1, f2 = f2, f1 f1, f2 = f2, f1
if f1 == 17.0 || f2 == 17.0 { if f1 == 17.0 || f2 == 17.0 {
mtx.unlock() mtx.unlock()
@ -170,18 +170,18 @@ fn test_global_mutex() {
assert f1 == 34.0625 assert f1 == 34.0625
t := spawn switch2() t := spawn switch2()
for _ in 0 .. 25000 { for _ in 0 .. 25000 {
mtx.@lock() mtx.lock()
f1, f2 = f2, f1 f1, f2 = f2, f1
mtx.unlock() mtx.unlock()
} }
mtx.@lock() mtx.lock()
if f1 == 0.0 { if f1 == 0.0 {
f1 = 17.0 f1 = 17.0
} else { } else {
f2 = 17.0 f2 = 17.0
} }
mtx.unlock() mtx.unlock()
mtx.@rlock() mtx.rlock()
assert (f1 == 17.0 && f2 == 34.0625) || (f1 == 34.0625 && f2 == 17.0) assert (f1 == 17.0 && f2 == 34.0625) || (f1 == 34.0625 && f2 == 17.0)
mtx.runlock() mtx.runlock()
n := t.wait() n := t.wait()

View File

@ -46,7 +46,7 @@ pub fn FileSet.new() &FileSet {
// TODO: // TODO:
pub fn (mut fs FileSet) add_file(filename string, base_ int, size int) &File { pub fn (mut fs FileSet) add_file(filename string, base_ int, size int) &File {
// eprintln('>>> add_file fs: ${voidptr(fs)} | filename: $filename | base_: $base_ | size: $size') // eprintln('>>> add_file fs: ${voidptr(fs)} | filename: $filename | base_: $base_ | size: $size')
fs.mu.@lock() fs.mu.lock()
defer { defer {
fs.mu.unlock() fs.mu.unlock()
} }
@ -109,7 +109,7 @@ fn search_files(files []&File, x int) int {
pub fn (mut fs FileSet) file(pos Pos) &File { pub fn (mut fs FileSet) file(pos Pos) &File {
// eprintln('>>>>>>>>> file fs: ${voidptr(fs)} | pos: $pos') // eprintln('>>>>>>>>> file fs: ${voidptr(fs)} | pos: $pos')
fs.mu.@lock() fs.mu.lock()
defer { defer {
fs.mu.unlock() fs.mu.unlock()
} }