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
+8 -8
View File
@@ -7,7 +7,7 @@ _ :: vg
// A Wait_Group waits for a collection of threads to finish // A Wait_Group waits for a collection of threads to finish
// //
// A Wait_Group must not be copied after first use // A Wait_Group must not be copied after first use
Wait_Group :: struct { Wait_Group :: struct #no_copy {
counter: int, counter: int,
mutex: Mutex, mutex: Mutex,
cond: Cond, cond: Cond,
@@ -101,7 +101,7 @@ Example:
fmt.println("Finished") fmt.println("Finished")
} }
*/ */
Barrier :: struct { Barrier :: struct #no_copy {
mutex: Mutex, mutex: Mutex,
cond: Cond, cond: Cond,
index: int, 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 == 0: Event is reset and no threads are waiting
// status == 1: Event is signaled // status == 1: Event is signaled
// status == -N: Event is reset and N threads are waiting // 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, ticket: uint,
serving: uint, serving: uint,
} }
@@ -194,7 +194,7 @@ ticket_mutex_guard :: proc "contextless" (m: ^Ticket_Mutex) -> bool {
} }
Benaphore :: struct { Benaphore :: struct #no_copy {
counter: i32, counter: i32,
sema: Sema, sema: Sema,
} }
@@ -222,7 +222,7 @@ benaphore_guard :: proc "contextless" (m: ^Benaphore) -> bool {
return true return true
} }
Recursive_Benaphore :: struct { Recursive_Benaphore :: struct #no_copy {
counter: int, counter: int,
owner: int, owner: int,
recursion: i32, 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. // Once is a data value that will perform exactly on action.
// //
// A Once must not be copied after first use. // A Once must not be copied after first use.
Once :: struct { Once :: struct #no_copy {
m: Mutex, m: Mutex,
done: bool, done: bool,
} }
@@ -372,7 +372,7 @@ once_do_with_data_contextless :: proc "contextless" (o: ^Once, fn: proc "context
// blocks for the specified duration. // blocks for the specified duration.
// * The `unpark` procedure automatically makes the token available if it // * The `unpark` procedure automatically makes the token available if it
// was not already. // was not already.
Parker :: struct { Parker :: struct #no_copy {
state: Futex, state: Futex,
} }
+5 -5
View File
@@ -11,7 +11,7 @@ current_thread_id :: proc "contextless" () -> int {
// The zero value for a Mutex is an unlocked mutex // The zero value for a Mutex is an unlocked mutex
// //
// A Mutex must not be copied after first use // A Mutex must not be copied after first use
Mutex :: struct { Mutex :: struct #no_copy {
impl: _Mutex, impl: _Mutex,
} }
@@ -47,7 +47,7 @@ mutex_guard :: proc "contextless" (m: ^Mutex) -> bool {
// The zero value for a RW_Mutex is an unlocked mutex // The zero value for a RW_Mutex is an unlocked mutex
// //
// A RW_Mutex must not be copied after first use // A RW_Mutex must not be copied after first use
RW_Mutex :: struct { RW_Mutex :: struct #no_copy {
impl: _RW_Mutex, 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 // The zero value for a Recursive_Mutex is an unlocked mutex
// //
// A Recursive_Mutex must not be copied after first use // A Recursive_Mutex must not be copied after first use
Recursive_Mutex :: struct { Recursive_Mutex :: struct #no_copy {
impl: _Recursive_Mutex, impl: _Recursive_Mutex,
} }
@@ -144,7 +144,7 @@ recursive_mutex_guard :: proc "contextless" (m: ^Recursive_Mutex) -> bool {
// waiting for signalling the occurence of an event // waiting for signalling the occurence of an event
// //
// A Cond must not be copied after first use // A Cond must not be copied after first use
Cond :: struct { Cond :: struct #no_copy {
impl: _Cond, 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. // Posting to the semaphore increases the count by one, or the provided amount.
// //
// A Sema must not be copied after first use // A Sema must not be copied after first use
Sema :: struct { Sema :: struct #no_copy {
impl: _Sema, impl: _Sema,
} }
+5 -5
View File
@@ -13,7 +13,7 @@ Atomic_Mutex_State :: enum Futex {
// The zero value for a Atomic_Mutex is an unlocked mutex // The zero value for a Atomic_Mutex is an unlocked mutex
// //
// An Atomic_Mutex must not be copied after first use // An Atomic_Mutex must not be copied after first use
Atomic_Mutex :: struct { Atomic_Mutex :: struct #no_copy {
state: Atomic_Mutex_State, 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 // The zero value for an Atomic_RW_Mutex is an unlocked mutex
// //
// An Atomic_RW_Mutex must not be copied after first use // 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, state: Atomic_RW_Mutex_State,
mutex: Atomic_Mutex, mutex: Atomic_Mutex,
sema: Atomic_Sema, 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 // The zero value for a Recursive_Mutex is an unlocked mutex
// //
// An Atomic_Recursive_Mutex must not be copied after first use // An Atomic_Recursive_Mutex must not be copied after first use
Atomic_Recursive_Mutex :: struct { Atomic_Recursive_Mutex :: struct #no_copy {
owner: int, owner: int,
recursion: int, recursion: int,
mutex: Mutex, mutex: Mutex,
@@ -285,7 +285,7 @@ atomic_recursive_mutex_guard :: proc "contextless" (m: ^Atomic_Recursive_Mutex)
// waiting for signalling the occurence of an event // waiting for signalling the occurence of an event
// //
// An Atomic_Cond must not be copied after first use // An Atomic_Cond must not be copied after first use
Atomic_Cond :: struct { Atomic_Cond :: struct #no_copy {
state: Futex, 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. // Posting to the semaphore increases the count by one, or the provided amount.
// //
// An Atomic_Sema must not be copied after first use // An Atomic_Sema must not be copied after first use
Atomic_Sema :: struct { Atomic_Sema :: struct #no_copy {
count: Futex, count: Futex,
} }