Add #no_copy to sync primitives

This commit is contained in:
gingerBill
2023-04-15 15:41:30 +01:00
parent 5da76ae34b
commit e79883e4fd
3 changed files with 18 additions and 18 deletions

View File

@@ -7,7 +7,7 @@ _ :: vg
// A Wait_Group waits for a collection of threads to finish
//
// A Wait_Group must not be copied after first use
Wait_Group :: struct {
Wait_Group :: struct #no_copy {
counter: int,
mutex: Mutex,
cond: Cond,
@@ -101,7 +101,7 @@ Example:
fmt.println("Finished")
}
*/
Barrier :: struct {
Barrier :: struct #no_copy {
mutex: Mutex,
cond: Cond,
index: int,
@@ -141,7 +141,7 @@ barrier_wait :: proc "contextless" (b: ^Barrier) -> (is_leader: bool) {
}
Auto_Reset_Event :: struct {
Auto_Reset_Event :: struct #no_copy {
// status == 0: Event is reset and no threads are waiting
// status == 1: Event is signaled
// status == -N: Event is reset and N threads are waiting
@@ -172,7 +172,7 @@ auto_reset_event_wait :: proc "contextless" (e: ^Auto_Reset_Event) {
Ticket_Mutex :: struct {
Ticket_Mutex :: struct #no_copy {
ticket: uint,
serving: uint,
}
@@ -194,7 +194,7 @@ ticket_mutex_guard :: proc "contextless" (m: ^Ticket_Mutex) -> bool {
}
Benaphore :: struct {
Benaphore :: struct #no_copy {
counter: i32,
sema: Sema,
}
@@ -222,7 +222,7 @@ benaphore_guard :: proc "contextless" (m: ^Benaphore) -> bool {
return true
}
Recursive_Benaphore :: struct {
Recursive_Benaphore :: struct #no_copy {
counter: int,
owner: int,
recursion: i32,
@@ -284,7 +284,7 @@ recursive_benaphore_guard :: proc "contextless" (m: ^Recursive_Benaphore) -> boo
// Once is a data value that will perform exactly on action.
//
// A Once must not be copied after first use.
Once :: struct {
Once :: struct #no_copy {
m: Mutex,
done: bool,
}
@@ -372,7 +372,7 @@ once_do_with_data_contextless :: proc "contextless" (o: ^Once, fn: proc "context
// blocks for the specified duration.
// * The `unpark` procedure automatically makes the token available if it
// was not already.
Parker :: struct {
Parker :: struct #no_copy {
state: Futex,
}

View File

@@ -11,7 +11,7 @@ current_thread_id :: proc "contextless" () -> int {
// The zero value for a Mutex is an unlocked mutex
//
// A Mutex must not be copied after first use
Mutex :: struct {
Mutex :: struct #no_copy {
impl: _Mutex,
}
@@ -47,7 +47,7 @@ mutex_guard :: proc "contextless" (m: ^Mutex) -> bool {
// The zero value for a RW_Mutex is an unlocked mutex
//
// A RW_Mutex must not be copied after first use
RW_Mutex :: struct {
RW_Mutex :: struct #no_copy {
impl: _RW_Mutex,
}
@@ -111,7 +111,7 @@ rw_mutex_shared_guard :: proc "contextless" (m: ^RW_Mutex) -> bool {
// The zero value for a Recursive_Mutex is an unlocked mutex
//
// A Recursive_Mutex must not be copied after first use
Recursive_Mutex :: struct {
Recursive_Mutex :: struct #no_copy {
impl: _Recursive_Mutex,
}
@@ -144,7 +144,7 @@ recursive_mutex_guard :: proc "contextless" (m: ^Recursive_Mutex) -> bool {
// waiting for signalling the occurence of an event
//
// A Cond must not be copied after first use
Cond :: struct {
Cond :: struct #no_copy {
impl: _Cond,
}
@@ -172,7 +172,7 @@ cond_broadcast :: proc "contextless" (c: ^Cond) {
// Posting to the semaphore increases the count by one, or the provided amount.
//
// A Sema must not be copied after first use
Sema :: struct {
Sema :: struct #no_copy {
impl: _Sema,
}

View File

@@ -13,7 +13,7 @@ Atomic_Mutex_State :: enum Futex {
// The zero value for a Atomic_Mutex is an unlocked mutex
//
// An Atomic_Mutex must not be copied after first use
Atomic_Mutex :: struct {
Atomic_Mutex :: struct #no_copy {
state: Atomic_Mutex_State,
}
@@ -109,7 +109,7 @@ Atomic_RW_Mutex_State_Reader_Mask :: Atomic_RW_Mutex_State(1<<(Atomic_RW_Mutex_S
// The zero value for an Atomic_RW_Mutex is an unlocked mutex
//
// An Atomic_RW_Mutex must not be copied after first use
Atomic_RW_Mutex :: struct {
Atomic_RW_Mutex :: struct #no_copy {
state: Atomic_RW_Mutex_State,
mutex: Atomic_Mutex,
sema: Atomic_Sema,
@@ -222,7 +222,7 @@ atomic_rw_mutex_shared_guard :: proc "contextless" (m: ^Atomic_RW_Mutex) -> bool
// The zero value for a Recursive_Mutex is an unlocked mutex
//
// An Atomic_Recursive_Mutex must not be copied after first use
Atomic_Recursive_Mutex :: struct {
Atomic_Recursive_Mutex :: struct #no_copy {
owner: int,
recursion: int,
mutex: Mutex,
@@ -285,7 +285,7 @@ atomic_recursive_mutex_guard :: proc "contextless" (m: ^Atomic_Recursive_Mutex)
// waiting for signalling the occurence of an event
//
// An Atomic_Cond must not be copied after first use
Atomic_Cond :: struct {
Atomic_Cond :: struct #no_copy {
state: Futex,
}
@@ -320,7 +320,7 @@ atomic_cond_broadcast :: proc "contextless" (c: ^Atomic_Cond) {
// Posting to the semaphore increases the count by one, or the provided amount.
//
// An Atomic_Sema must not be copied after first use
Atomic_Sema :: struct {
Atomic_Sema :: struct #no_copy {
count: Futex,
}