From edb921f463c4c0b9bbe3f72229126d6c887dd1a9 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 10 May 2020 08:58:54 +0300 Subject: [PATCH] sync: mark sync.WaitGroup and sync.Mutex with [ref_only] --- vlib/sync/sync_nix.c.v | 10 ++++------ vlib/sync/sync_windows.c.v | 2 ++ vlib/sync/waitgroup.v | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/vlib/sync/sync_nix.c.v b/vlib/sync/sync_nix.c.v index a360d0a03b..ad6dedf413 100644 --- a/vlib/sync/sync_nix.c.v +++ b/vlib/sync/sync_nix.c.v @@ -4,14 +4,12 @@ module sync #include -fn C.pthread_mutex_init() +fn C.pthread_mutex_init(voidptr, voidptr) int +fn C.pthread_mutex_lock(voidptr) int +fn C.pthread_mutex_unlock(voidptr) int - -fn C.pthread_mutex_lock() - - -fn C.pthread_mutex_unlock() // [init_with=new_mutex] // TODO: implement support for this struct attribute, and disallow Mutex{} from outside the sync.new_mutex() function. +[ref_only] pub struct Mutex { mutex C.pthread_mutex_t } diff --git a/vlib/sync/sync_windows.c.v b/vlib/sync/sync_windows.c.v index 939dd4e1c6..9c765351b2 100644 --- a/vlib/sync/sync_windows.c.v +++ b/vlib/sync/sync_windows.c.v @@ -8,6 +8,8 @@ module sync type MHANDLE voidptr //[init_with=new_mutex] // TODO: implement support for this struct attribute, and disallow Mutex{} from outside the sync.new_mutex() function. + +[ref_only] pub struct Mutex { mut: mx MHANDLE // mutex handle diff --git a/vlib/sync/waitgroup.v b/vlib/sync/waitgroup.v index 9ed58667b3..78f5ba8794 100644 --- a/vlib/sync/waitgroup.v +++ b/vlib/sync/waitgroup.v @@ -2,7 +2,9 @@ // Use of this source code is governed by an MIT license // that can be found in the LICENSE file. module sync + // [init_with=new_waitgroup] // TODO: implement support for init_with struct attribute, and disallow WaitGroup{} from outside the sync.new_waitgroup() function. +[ref_only] pub struct WaitGroup { mut: mu &Mutex = &Mutex(0)