mirror of
https://github.com/vlang/v.git
synced 2025-08-03 17:57:59 -04:00
all: replace fn name '@xxx' with 'xxx' (#22506)
This commit is contained in:
parent
45fd7ebcde
commit
da3112e545
@ -11,7 +11,7 @@ const run_time = 10 * time.second
|
||||
fn request(mut mu sync.Mutex, count &int) {
|
||||
for {
|
||||
http.get('http://vlang.io/utc_now') or { panic(err) }
|
||||
mu.@lock()
|
||||
mu.lock()
|
||||
unsafe {
|
||||
(*count)++
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ mut:
|
||||
|
||||
struct FrameworkBenchmarkResponse {
|
||||
insert []int
|
||||
@select []int
|
||||
select []int
|
||||
update []int
|
||||
}
|
||||
|
||||
@ -125,9 +125,9 @@ fn insert_framework_benchmark_times() !FrameworkPlatform {
|
||||
|
||||
fn select_framework_benchmark_times() !FrameworkPlatform {
|
||||
numbers := FrameworkPlatform{
|
||||
v_sqlite_memory: v_sqlite_memory()!.@select
|
||||
// v_sqlite_file: v_sqlite_file()!.@select
|
||||
typescript_sqlite_memory: typescript_sqlite_memory()!.@select
|
||||
v_sqlite_memory: v_sqlite_memory()!.select
|
||||
// v_sqlite_file: v_sqlite_file()!.select
|
||||
typescript_sqlite_memory: typescript_sqlite_memory()!.select
|
||||
}
|
||||
|
||||
return numbers
|
||||
@ -136,7 +136,7 @@ fn select_framework_benchmark_times() !FrameworkPlatform {
|
||||
fn update_framework_benchmark_times() !FrameworkPlatform {
|
||||
numbers := FrameworkPlatform{
|
||||
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
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ fn v_sqlite_file() !FrameworkBenchmarkResponse {
|
||||
// framework_benchmark_response := json.decode(FrameworkBenchmarkResponse, res.body)!
|
||||
framework_benchmark_response := FrameworkBenchmarkResponse{
|
||||
insert: []
|
||||
@select: []
|
||||
select: []
|
||||
update: []
|
||||
}
|
||||
return framework_benchmark_response
|
||||
|
@ -18,7 +18,7 @@ mut:
|
||||
|
||||
struct Response {
|
||||
insert []int
|
||||
@select []int
|
||||
select []int
|
||||
update []int
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ pub fn (mut app App) sqlite_memory(count int) vweb.Result {
|
||||
|
||||
response := Response{
|
||||
insert: insert_stopwatchs
|
||||
@select: select_stopwatchs
|
||||
select: select_stopwatchs
|
||||
update: update_stopwatchs
|
||||
}
|
||||
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 {
|
||||
response := Response{
|
||||
insert: []
|
||||
@select: []
|
||||
select: []
|
||||
update: []
|
||||
}
|
||||
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 {
|
||||
response := Response{
|
||||
insert: []
|
||||
@select: []
|
||||
select: []
|
||||
update: []
|
||||
}
|
||||
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 {
|
||||
response := Response{
|
||||
insert: []
|
||||
@select: []
|
||||
select: []
|
||||
update: []
|
||||
}
|
||||
return app.json(response)
|
||||
|
@ -215,7 +215,7 @@ pub fn (mut cb Clipboard) free() {
|
||||
}
|
||||
|
||||
pub fn (mut cb Clipboard) clear() {
|
||||
cb.mutex.@lock()
|
||||
cb.mutex.lock()
|
||||
C.XSetSelectionOwner(cb.display, cb.selection, Window(0), C.CurrentTime)
|
||||
C.XFlush(cb.display)
|
||||
cb.is_owner = false
|
||||
@ -237,7 +237,7 @@ pub fn (mut cb Clipboard) set_text(text string) bool {
|
||||
if cb.window == Window(0) {
|
||||
return false
|
||||
}
|
||||
cb.mutex.@lock()
|
||||
cb.mutex.lock()
|
||||
cb.text = text
|
||||
cb.is_owner = true
|
||||
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),
|
||||
32, C.PropModeReplace, targets.data, targets.len)
|
||||
} 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,
|
||||
cb.text.str, cb.text.len)
|
||||
cb.mutex.unlock()
|
||||
@ -313,7 +313,7 @@ fn (mut cb Clipboard) start_listener() {
|
||||
if unsafe { event.xselectionclear.window == cb.window } && unsafe {
|
||||
event.xselectionclear.selection == cb.selection
|
||||
} {
|
||||
cb.mutex.@lock()
|
||||
cb.mutex.lock()
|
||||
cb.is_owner = false
|
||||
cb.text = ''
|
||||
cb.mutex.unlock()
|
||||
@ -358,7 +358,7 @@ fn (mut cb Clipboard) start_listener() {
|
||||
} else if unsafe { event.xselection.target == to_be_requested } {
|
||||
sent_request = false
|
||||
to_be_requested = Atom(0)
|
||||
cb.mutex.@lock()
|
||||
cb.mutex.lock()
|
||||
prop := unsafe {
|
||||
read_property(event.xselection.display, event.xselection.requestor,
|
||||
event.xselection.property)
|
||||
|
@ -60,14 +60,14 @@ pub fn (ctx &CancelContext) deadline() ?time.Time {
|
||||
}
|
||||
|
||||
pub fn (mut ctx CancelContext) done() chan int {
|
||||
ctx.mutex.@lock()
|
||||
ctx.mutex.lock()
|
||||
done := ctx.done
|
||||
ctx.mutex.unlock()
|
||||
return done
|
||||
}
|
||||
|
||||
pub fn (mut ctx CancelContext) err() IError {
|
||||
ctx.mutex.@lock()
|
||||
ctx.mutex.lock()
|
||||
err := ctx.err
|
||||
ctx.mutex.unlock()
|
||||
return err
|
||||
@ -89,7 +89,7 @@ fn (mut ctx CancelContext) cancel(remove_from_parent bool, err IError) {
|
||||
panic('context: internal error: missing cancel error')
|
||||
}
|
||||
|
||||
ctx.mutex.@lock()
|
||||
ctx.mutex.lock()
|
||||
if ctx.err !is none {
|
||||
ctx.mutex.unlock()
|
||||
// already canceled
|
||||
|
@ -61,7 +61,7 @@ pub fn (octx OneContext) done() chan int {
|
||||
}
|
||||
|
||||
pub fn (mut octx OneContext) err() IError {
|
||||
octx.err_mutex.@lock()
|
||||
octx.err_mutex.lock()
|
||||
defer {
|
||||
octx.err_mutex.unlock()
|
||||
}
|
||||
@ -102,7 +102,7 @@ pub fn (octx OneContext) str() string {
|
||||
|
||||
pub fn (mut octx OneContext) cancel(err IError) {
|
||||
octx.cancel_fn()
|
||||
octx.err_mutex.@lock()
|
||||
octx.err_mutex.lock()
|
||||
octx.err = err
|
||||
octx.err_mutex.unlock()
|
||||
if !octx.done.closed {
|
||||
|
@ -83,7 +83,7 @@ fn test_mysql_orm() {
|
||||
data: [orm.string_to_primitive('Louis'), orm.int_to_primitive(101)]
|
||||
}) or { panic(err) }
|
||||
|
||||
res := db.@select(orm.SelectConfig{
|
||||
res := db.select(orm.SelectConfig{
|
||||
table: 'Test'
|
||||
has_where: true
|
||||
fields: ['id', 'name', 'age']
|
||||
|
@ -3,8 +3,8 @@ module mysql
|
||||
import orm
|
||||
import time
|
||||
|
||||
// @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 {
|
||||
// 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 {
|
||||
query := orm.orm_select_gen(config, '`', false, '?', 0, where)
|
||||
mut result := [][]orm.Primitive{}
|
||||
mut stmt := db.init_stmt(query)
|
||||
|
@ -6,8 +6,8 @@ import net.conv
|
||||
|
||||
// sql expr
|
||||
|
||||
// @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 {
|
||||
// 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 {
|
||||
query := orm.orm_select_gen(config, '"', true, '$', 1, where)
|
||||
|
||||
rows := pg_stmt_worker(db, query, where, data)!
|
||||
|
@ -97,7 +97,7 @@ fn test_pg_orm() {
|
||||
data: [orm.string_to_primitive('Louis'), orm.int_to_primitive(101)]
|
||||
}) or { panic(err) }
|
||||
|
||||
res := db.@select(orm.SelectConfig{
|
||||
res := db.select(orm.SelectConfig{
|
||||
table: 'Test'
|
||||
is_count: false
|
||||
has_where: true
|
||||
|
@ -3,12 +3,12 @@ module sqlite
|
||||
import orm
|
||||
import time
|
||||
|
||||
// @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 {
|
||||
// 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 {
|
||||
// 1. Create query and bind necessary data
|
||||
query := orm.orm_select_gen(config, '`', true, '?', 1, where)
|
||||
$if trace_sqlite ? {
|
||||
eprintln('> @select query: "${query}"')
|
||||
eprintln('> select query: "${query}"')
|
||||
}
|
||||
stmt := db.new_init_stmt(query)!
|
||||
defer {
|
||||
|
@ -63,7 +63,7 @@ fn test_sqlite_orm() {
|
||||
data: [orm.string_to_primitive('Louis'), orm.i64_to_primitive(100)]
|
||||
}) or { panic(err) }
|
||||
|
||||
res := db.@select(orm.SelectConfig{
|
||||
res := db.select(orm.SelectConfig{
|
||||
table: 'Test'
|
||||
has_where: true
|
||||
fields: ['id', 'name', 'age']
|
||||
|
@ -32,7 +32,7 @@ pub fn (mut x ThreadSafeLog) free() {
|
||||
|
||||
// set_level changes the log level
|
||||
pub fn (mut x ThreadSafeLog) set_level(level Level) {
|
||||
x.mu.@lock()
|
||||
x.mu.lock()
|
||||
x.Log.set_level(level)
|
||||
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.
|
||||
// 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) {
|
||||
x.mu.@lock()
|
||||
x.mu.lock()
|
||||
x.Log.set_always_flush(should_flush)
|
||||
x.mu.unlock()
|
||||
}
|
||||
|
||||
// debug logs a debug message
|
||||
pub fn (mut x ThreadSafeLog) debug(s string) {
|
||||
x.mu.@lock()
|
||||
x.mu.lock()
|
||||
x.Log.debug(s)
|
||||
x.mu.unlock()
|
||||
}
|
||||
|
||||
// info logs an info messagep
|
||||
pub fn (mut x ThreadSafeLog) info(s string) {
|
||||
x.mu.@lock()
|
||||
x.mu.lock()
|
||||
x.Log.info(s)
|
||||
x.mu.unlock()
|
||||
}
|
||||
|
||||
// warn logs a warning message
|
||||
pub fn (mut x ThreadSafeLog) warn(s string) {
|
||||
x.mu.@lock()
|
||||
x.mu.lock()
|
||||
x.Log.warn(s)
|
||||
x.mu.unlock()
|
||||
}
|
||||
|
||||
// error logs an error message
|
||||
pub fn (mut x ThreadSafeLog) error(s string) {
|
||||
x.mu.@lock()
|
||||
x.mu.lock()
|
||||
x.Log.error(s)
|
||||
x.mu.unlock()
|
||||
}
|
||||
@ -76,7 +76,7 @@ pub fn (mut x ThreadSafeLog) error(s string) {
|
||||
// fatal logs a fatal message, and panics
|
||||
@[noreturn]
|
||||
pub fn (mut x ThreadSafeLog) fatal(s string) {
|
||||
x.mu.@lock()
|
||||
x.mu.lock()
|
||||
defer {
|
||||
// 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,
|
||||
|
@ -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.@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)
|
||||
|
||||
|
@ -106,7 +106,7 @@ pub fn close(handle int) ! {
|
||||
}
|
||||
|
||||
// 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{}
|
||||
|
||||
C.FD_ZERO(&set)
|
||||
@ -130,13 +130,13 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
|
||||
|
||||
match test {
|
||||
.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 {
|
||||
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 {
|
||||
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
|
||||
for infinite || time.now() <= deadline {
|
||||
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 {
|
||||
// errno is 4, Spurious wakeup from signal, keep waiting
|
||||
continue
|
||||
|
@ -21,7 +21,7 @@ pub enum Method { // as of 2023-06-20
|
||||
delete
|
||||
label
|
||||
link
|
||||
@lock
|
||||
lock
|
||||
merge
|
||||
mkactivity
|
||||
mkcalendar
|
||||
@ -66,7 +66,7 @@ pub fn (m Method) str() string {
|
||||
.delete { 'DELETE' }
|
||||
.label { 'LABEL' }
|
||||
.link { 'LINK' }
|
||||
.@lock { 'LOCK' }
|
||||
.lock { 'LOCK' }
|
||||
.merge { 'MERGE' }
|
||||
.mkactivity { 'MKACTIVITY' }
|
||||
.mkcalendar { 'MKCALENDAR' }
|
||||
@ -115,7 +115,7 @@ pub fn method_from_str(m string) Method {
|
||||
'DELETE' { Method.delete }
|
||||
'LABEL' { Method.label }
|
||||
'LINK' { Method.link }
|
||||
'LOCK' { Method.@lock }
|
||||
'LOCK' { Method.lock }
|
||||
'MERGE' { Method.merge }
|
||||
'MKACTIVITY' { Method.mkactivity }
|
||||
'MKCALENDAR' { Method.mkcalendar }
|
||||
|
@ -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
|
||||
fn @select(handle int, test Select, timeout time.Duration) !bool {
|
||||
fn select(handle int, test Select, timeout time.Duration) !bool {
|
||||
$if trace_ssl ? {
|
||||
eprintln('${@METHOD} handle: ${handle}, timeout: ${timeout}')
|
||||
}
|
||||
@ -656,13 +656,13 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
|
||||
mut res := -1
|
||||
match test {
|
||||
.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 {
|
||||
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 {
|
||||
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 {
|
||||
@ -688,7 +688,7 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
|
||||
|
||||
// wait_for wraps the common wait code
|
||||
fn wait_for(handle int, what Select, timeout time.Duration) ! {
|
||||
ready := @select(handle, what, timeout)!
|
||||
ready := select(handle, what, timeout)!
|
||||
if ready {
|
||||
return
|
||||
}
|
||||
|
@ -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
|
||||
fn @select(handle int, test Select, timeout time.Duration) !bool {
|
||||
fn select(handle int, test Select, timeout time.Duration) !bool {
|
||||
$if trace_ssl ? {
|
||||
eprintln('${@METHOD} handle: ${handle}, timeout: ${timeout}')
|
||||
}
|
||||
@ -411,13 +411,13 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
|
||||
mut res := -1
|
||||
match test {
|
||||
.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 {
|
||||
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 {
|
||||
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 {
|
||||
@ -443,7 +443,7 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
|
||||
|
||||
// wait_for wraps the common wait code
|
||||
fn wait_for(handle int, what Select, timeout time.Duration) ! {
|
||||
ready := @select(handle, what, timeout)!
|
||||
ready := select(handle, what, timeout)!
|
||||
if ready {
|
||||
return
|
||||
}
|
||||
|
@ -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.
|
||||
mut has_data := true
|
||||
if c.is_blocking {
|
||||
if ok := @select(c.sock.handle, .read, 1) {
|
||||
if ok := select(c.sock.handle, .read, 1) {
|
||||
has_data = ok
|
||||
} else {
|
||||
false
|
||||
@ -392,7 +392,7 @@ pub fn listen_tcp(family AddrFamily, saddr string, options ListenOptions) !&TcpL
|
||||
for {
|
||||
code := error_code()
|
||||
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)
|
||||
if res == 0 {
|
||||
break
|
||||
@ -655,7 +655,7 @@ fn (mut s TcpSocket) connect(a Addr) ! {
|
||||
// determine whether connect() completed successfully (SO_ERROR is zero) or
|
||||
// unsuccessfully (SO_ERROR is one of the usual error codes listed here,
|
||||
// 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
|
||||
len := sizeof(err)
|
||||
xyz := C.getsockopt(s.handle, C.SOL_SOCKET, C.SO_ERROR, &err, &len)
|
||||
|
@ -274,8 +274,8 @@ fn (mut s UdpSocket) close() ! {
|
||||
return close(s.handle)
|
||||
}
|
||||
|
||||
fn (mut s UdpSocket) @select(test Select, timeout time.Duration) !bool {
|
||||
return @select(s.handle, test, timeout)
|
||||
fn (mut s UdpSocket) select(test Select, timeout time.Duration) !bool {
|
||||
return select(s.handle, test, timeout)
|
||||
}
|
||||
|
||||
fn (s &UdpSocket) remote() !Addr {
|
||||
|
@ -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
|
||||
fn @select(handle int, test Select, timeout time.Duration) !bool {
|
||||
fn select(handle int, test Select, timeout time.Duration) !bool {
|
||||
set := C.fd_set{}
|
||||
|
||||
C.FD_ZERO(&set)
|
||||
@ -53,13 +53,13 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
|
||||
|
||||
match test {
|
||||
.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 {
|
||||
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 {
|
||||
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
|
||||
for infinite || time.now() <= deadline {
|
||||
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 {
|
||||
// Spurious wakeup from signal, keep waiting
|
||||
continue
|
||||
|
@ -407,8 +407,8 @@ fn (mut s StreamSocket) close() ! {
|
||||
return close(s.handle)
|
||||
}
|
||||
|
||||
fn (mut s StreamSocket) @select(test Select, timeout time.Duration) !bool {
|
||||
return @select(s.handle, test, timeout)
|
||||
fn (mut s StreamSocket) select(test Select, timeout time.Duration) !bool {
|
||||
return select(s.handle, test, timeout)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
// The socket is nonblocking and the connection cannot be completed
|
||||
// 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
|
||||
len := sizeof(err)
|
||||
// determine whether connect() completed successfully (SO_ERROR is zero)
|
||||
|
@ -193,7 +193,7 @@ pub:
|
||||
// Every function without last_id() returns an optional, which returns an error if present
|
||||
// last_id returns the last inserted id of the db
|
||||
pub interface Connection {
|
||||
@select(config SelectConfig, data QueryData, where QueryData) ![][]Primitive
|
||||
select(config SelectConfig, data QueryData, where QueryData) ![][]Primitive
|
||||
insert(table string, data QueryData) !
|
||||
update(table string, data QueryData, where QueryData) !
|
||||
delete(table string, where QueryData) !
|
||||
|
@ -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
|
||||
st.last = orm.orm_select_gen(config, '`', false, '?', 5, where)
|
||||
st.data = data.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) ! {
|
||||
|
@ -80,7 +80,7 @@ pub:
|
||||
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:
|
||||
fn C.FD_ZERO(fdset &C.fd_set)
|
||||
@ -97,7 +97,7 @@ pub fn fd_is_pending(fd int) bool {
|
||||
tv_sec: 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 C.FD_ISSET(fd, &read_set) != 0 {
|
||||
return true
|
||||
|
@ -68,7 +68,7 @@ fn (mut pv Picoev) poll_once(max_wait_in_sec int) int {
|
||||
tv_sec: u64(max_wait_in_sec)
|
||||
tv_usec: 0
|
||||
}
|
||||
r := C.@select(maxfd + 1, &readfds, &writefds, &errorfds, &tv)
|
||||
r := C.select(maxfd + 1, &readfds, &writefds, &errorfds, &tv)
|
||||
if r == -1 {
|
||||
// timeout
|
||||
return -1
|
||||
|
@ -27,7 +27,7 @@ pub fn (mut m ManyTimes) do(f fn ()) {
|
||||
}
|
||||
|
||||
fn (mut m ManyTimes) do_slow(f fn ()) {
|
||||
m.m.@lock()
|
||||
m.m.lock()
|
||||
if m.count < m.times {
|
||||
stdatomic.store_u64(&m.count, m.count + 1)
|
||||
f()
|
||||
|
@ -6,7 +6,7 @@ pub mut:
|
||||
}
|
||||
|
||||
fn write_10000(mut co Counter, mut mx sync.Mutex) {
|
||||
mx.@lock()
|
||||
mx.lock()
|
||||
co.i = 10000
|
||||
mx.unlock()
|
||||
}
|
||||
@ -14,7 +14,7 @@ fn write_10000(mut co Counter, mut mx sync.Mutex) {
|
||||
fn test_mutex() {
|
||||
mut co := &Counter{10086}
|
||||
mut mx := sync.new_mutex()
|
||||
mx.@lock()
|
||||
mx.lock()
|
||||
co.i = 888
|
||||
th := spawn write_10000(mut co, mut mx)
|
||||
mx.unlock() // after mx unlock, thread write_10000 can continue
|
||||
@ -31,7 +31,7 @@ fn test_try_lock_mutex() {
|
||||
}
|
||||
}
|
||||
mut mx := sync.new_mutex()
|
||||
mx.@lock()
|
||||
mx.lock()
|
||||
try_fail := mx.try_lock()
|
||||
assert try_fail == false
|
||||
mx.unlock()
|
||||
|
@ -24,7 +24,7 @@ pub fn (mut o Once) do(f fn ()) {
|
||||
}
|
||||
|
||||
fn (mut o Once) do_slow(f fn ()) {
|
||||
o.m.@lock()
|
||||
o.m.lock()
|
||||
if o.count < 1 {
|
||||
stdatomic.store_u64(&o.count, 1)
|
||||
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) {
|
||||
o.m.@lock()
|
||||
o.m.lock()
|
||||
if o.count < 1 {
|
||||
stdatomic.store_u64(&o.count, 1)
|
||||
f(param)
|
||||
|
@ -7,7 +7,7 @@ pub mut:
|
||||
}
|
||||
|
||||
fn write_10000(mut co Counter, mut mx sync.RwMutex) {
|
||||
mx.@lock()
|
||||
mx.lock()
|
||||
co.i = 10000
|
||||
mx.unlock()
|
||||
}
|
||||
@ -15,14 +15,14 @@ fn write_10000(mut co Counter, mut mx sync.RwMutex) {
|
||||
fn test_rwmutex() {
|
||||
mut co := &Counter{10086}
|
||||
mut mx := sync.new_rwmutex()
|
||||
mx.@lock()
|
||||
mx.lock()
|
||||
co.i = 888
|
||||
th1 := spawn write_10000(mut co, mut mx)
|
||||
mx.unlock() // after mx unlock, thread write_10000 can continue
|
||||
th1.wait()
|
||||
assert co.i == 10000
|
||||
|
||||
mx.@rlock()
|
||||
mx.rlock()
|
||||
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!
|
||||
time.sleep(1 * time.millisecond)
|
||||
@ -43,7 +43,7 @@ fn test_try_lock_rwmutex() {
|
||||
mut mx := sync.new_rwmutex()
|
||||
|
||||
// try_rlock will always fail when mx locked
|
||||
mx.@lock()
|
||||
mx.lock()
|
||||
try_fail_reading1 := mx.try_rlock()
|
||||
try_fail_writing1 := mx.try_wlock()
|
||||
assert try_fail_reading1 == false
|
||||
|
@ -115,10 +115,10 @@ pub fn (mut m RwMutex) init() {
|
||||
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.
|
||||
@[inline]
|
||||
pub fn (mut m Mutex) @lock() {
|
||||
pub fn (mut m Mutex) lock() {
|
||||
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
|
||||
// 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]
|
||||
pub fn (mut m Mutex) unlock() {
|
||||
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,
|
||||
// once the lock is released by another thread calling unlock.
|
||||
// Once it succeds, it returns.
|
||||
// Note: there may be several threads that are waiting for the same lock.
|
||||
// Note: RwMutex has separate read and write locks.
|
||||
@[inline]
|
||||
pub fn (mut m RwMutex) @rlock() {
|
||||
pub fn (mut m RwMutex) rlock() {
|
||||
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,
|
||||
// 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.
|
||||
// Note: there may be several threads that are waiting for the same lock.
|
||||
// Note: RwMutex has separate read and write locks.
|
||||
@[inline]
|
||||
pub fn (mut m RwMutex) @lock() {
|
||||
pub fn (mut m RwMutex) lock() {
|
||||
C.pthread_rwlock_wrlock(&m.mutex)
|
||||
}
|
||||
|
||||
|
@ -102,10 +102,10 @@ pub fn (mut m RwMutex) init() {
|
||||
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.
|
||||
@[inline]
|
||||
pub fn (mut m Mutex) @lock() {
|
||||
pub fn (mut m Mutex) lock() {
|
||||
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
|
||||
// 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]
|
||||
pub fn (mut m Mutex) unlock() {
|
||||
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,
|
||||
// once the lock is released by another thread calling unlock.
|
||||
// Once it succeds, it returns.
|
||||
// Note: there may be several threads that are waiting for the same lock.
|
||||
// Note: RwMutex has separate read and write locks.
|
||||
@[inline]
|
||||
pub fn (mut m RwMutex) @rlock() {
|
||||
pub fn (mut m RwMutex) rlock() {
|
||||
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,
|
||||
// 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.
|
||||
// Note: there may be several threads that are waiting for the same lock.
|
||||
// Note: RwMutex has separate read and write locks.
|
||||
@[inline]
|
||||
pub fn (mut m RwMutex) @lock() {
|
||||
pub fn (mut m RwMutex) lock() {
|
||||
C.pthread_rwlock_wrlock(&m.mutex)
|
||||
}
|
||||
|
||||
|
@ -100,10 +100,10 @@ pub fn (mut m RwMutex) init() {
|
||||
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.
|
||||
@[inline]
|
||||
pub fn (mut m Mutex) @lock() {
|
||||
pub fn (mut m Mutex) lock() {
|
||||
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
|
||||
// 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]
|
||||
pub fn (mut m Mutex) unlock() {
|
||||
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,
|
||||
// once the lock is released by another thread calling unlock.
|
||||
// Once it succeds, it returns.
|
||||
// Note: there may be several threads that are waiting for the same lock.
|
||||
// Note: RwMutex has separate read and write locks.
|
||||
@[inline]
|
||||
pub fn (mut m RwMutex) @rlock() {
|
||||
pub fn (mut m RwMutex) rlock() {
|
||||
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,
|
||||
// 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.
|
||||
// Note: there may be several threads that are waiting for the same lock.
|
||||
// Note: RwMutex has separate read and write locks.
|
||||
@[inline]
|
||||
pub fn (mut m RwMutex) @lock() {
|
||||
pub fn (mut m RwMutex) lock() {
|
||||
C.pthread_rwlock_wrlock(&m.mutex)
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ pub fn (mut m RwMutex) init() {
|
||||
C.InitializeSRWLock(&m.mx)
|
||||
}
|
||||
|
||||
pub fn (mut m Mutex) @lock() {
|
||||
pub fn (mut m Mutex) lock() {
|
||||
C.AcquireSRWLockExclusive(&m.mx)
|
||||
}
|
||||
|
||||
@ -94,11 +94,11 @@ pub fn (mut m Mutex) unlock() {
|
||||
}
|
||||
|
||||
// RwMutex has separate read- and write locks
|
||||
pub fn (mut m RwMutex) @rlock() {
|
||||
pub fn (mut m RwMutex) rlock() {
|
||||
C.AcquireSRWLockShared(&m.mx)
|
||||
}
|
||||
|
||||
pub fn (mut m RwMutex) @lock() {
|
||||
pub fn (mut m RwMutex) lock() {
|
||||
C.AcquireSRWLockExclusive(&m.mx)
|
||||
}
|
||||
|
||||
|
@ -1395,7 +1395,7 @@ pub mut:
|
||||
pub struct EnumField {
|
||||
pub:
|
||||
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
|
||||
pre_comments []Comment // comment before Enumfield
|
||||
comments []Comment // comment after Enumfield in the same line
|
||||
|
@ -22,8 +22,8 @@ enum SqlExprSide {
|
||||
// select from User
|
||||
// }
|
||||
// ```
|
||||
// cgen will write calling the function `@select` of the needed database.
|
||||
// If you use sqlite, it calls `@select` from `vlib/db/sqlite/orm.v`
|
||||
// cgen will write calling the function `select` of the needed database.
|
||||
// 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
|
||||
// from the database, which is used by the `select` query.
|
||||
|
@ -2,14 +2,14 @@ import sync
|
||||
|
||||
fn main() {
|
||||
mut mutex := sync.new_mutex()
|
||||
mutex.@lock()
|
||||
mutex.lock()
|
||||
mutex.unlock()
|
||||
mutex.destroy()
|
||||
|
||||
mut rwmutex := sync.new_rwmutex()
|
||||
rwmutex.@rlock()
|
||||
rwmutex.rlock()
|
||||
rwmutex.unlock()
|
||||
rwmutex.@lock()
|
||||
rwmutex.lock()
|
||||
rwmutex.unlock()
|
||||
rwmutex.destroy()
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
enum MyEnum {
|
||||
abc
|
||||
def
|
||||
@lock
|
||||
lock
|
||||
xyz
|
||||
@if
|
||||
if
|
||||
}
|
||||
|
||||
@[flag]
|
||||
@ -38,8 +38,8 @@ fn test_enum_from_string() {
|
||||
y := MyFlaggedEnum.from('xyz')!
|
||||
dump(y)
|
||||
assert y == .xyz
|
||||
assert MyEnum.from('if')! == MyEnum.@if
|
||||
assert MyEnum.from('lock')! == MyEnum.@lock
|
||||
assert MyEnum.from('if')! == MyEnum.if
|
||||
assert MyEnum.from('lock')! == MyEnum.lock
|
||||
if z := MyEnum.from('unknown') {
|
||||
assert false
|
||||
} else {
|
||||
|
@ -155,7 +155,7 @@ fn switch2() u64 {
|
||||
mut cnt := u64(0)
|
||||
for {
|
||||
cnt++
|
||||
mtx.@lock()
|
||||
mtx.lock()
|
||||
f1, f2 = f2, f1
|
||||
if f1 == 17.0 || f2 == 17.0 {
|
||||
mtx.unlock()
|
||||
@ -170,18 +170,18 @@ fn test_global_mutex() {
|
||||
assert f1 == 34.0625
|
||||
t := spawn switch2()
|
||||
for _ in 0 .. 25000 {
|
||||
mtx.@lock()
|
||||
mtx.lock()
|
||||
f1, f2 = f2, f1
|
||||
mtx.unlock()
|
||||
}
|
||||
mtx.@lock()
|
||||
mtx.lock()
|
||||
if f1 == 0.0 {
|
||||
f1 = 17.0
|
||||
} else {
|
||||
f2 = 17.0
|
||||
}
|
||||
mtx.unlock()
|
||||
mtx.@rlock()
|
||||
mtx.rlock()
|
||||
assert (f1 == 17.0 && f2 == 34.0625) || (f1 == 34.0625 && f2 == 17.0)
|
||||
mtx.runlock()
|
||||
n := t.wait()
|
||||
|
@ -46,7 +46,7 @@ pub fn FileSet.new() &FileSet {
|
||||
// TODO:
|
||||
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')
|
||||
fs.mu.@lock()
|
||||
fs.mu.lock()
|
||||
defer {
|
||||
fs.mu.unlock()
|
||||
}
|
||||
@ -109,7 +109,7 @@ fn search_files(files []&File, x int) int {
|
||||
|
||||
pub fn (mut fs FileSet) file(pos Pos) &File {
|
||||
// eprintln('>>>>>>>>> file fs: ${voidptr(fs)} | pos: $pos')
|
||||
fs.mu.@lock()
|
||||
fs.mu.lock()
|
||||
defer {
|
||||
fs.mu.unlock()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user