OXIESEC PANEL
- Current Dir:
/
/
opt
/
golang
/
1.19.4
/
src
/
sync
Server IP: 2a02:4780:11:1084:0:327f:3464:10
Upload:
Create Dir:
Name
Size
Modified
Perms
π
..
-
12/01/2022 06:13:58 PM
rwxr-xr-x
π
atomic
-
12/01/2022 06:13:56 PM
rwxr-xr-x
π
cond.go
3.49 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
cond_test.go
5.07 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
example_pool_test.go
1017 bytes
12/01/2022 06:13:00 PM
rw-r--r--
π
example_test.go
1.13 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
export_test.go
1.2 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
map.go
11.86 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
map_bench_test.go
6.29 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
map_reference_test.go
3.53 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
map_test.go
5.69 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
mutex.go
8.27 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
mutex_test.go
5.94 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
once.go
2.43 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
once_test.go
1.1 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
pool.go
8.77 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
pool_test.go
7.72 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
poolqueue.go
8.8 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
runtime.go
1.97 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
runtime2.go
465 bytes
12/01/2022 06:13:00 PM
rw-r--r--
π
runtime2_lockrank.go
546 bytes
12/01/2022 06:13:00 PM
rw-r--r--
π
runtime_sema_test.go
1.34 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
rwmutex.go
6.61 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
rwmutex_test.go
4.89 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
waitgroup.go
4.83 KB
12/01/2022 06:13:00 PM
rw-r--r--
π
waitgroup_test.go
3.01 KB
12/01/2022 06:13:00 PM
rw-r--r--
Editing: cond.go
Close
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package sync import ( "sync/atomic" "unsafe" ) // Cond implements a condition variable, a rendezvous point // for goroutines waiting for or announcing the occurrence // of an event. // // Each Cond has an associated Locker L (often a *Mutex or *RWMutex), // which must be held when changing the condition and // when calling the Wait method. // // A Cond must not be copied after first use. // // In the terminology of the Go memory model, Cond arranges that // a call to Broadcast or Signal βsynchronizes beforeβ any Wait call // that it unblocks. // // For many simple use cases, users will be better off using channels than a // Cond (Broadcast corresponds to closing a channel, and Signal corresponds to // sending on a channel). // // For more on replacements for sync.Cond, see [Roberto Clapis's series on // advanced concurrency patterns], as well as [Bryan Mills's talk on concurrency // patterns]. // // [Roberto Clapis's series on advanced concurrency patterns]: https://blogtitle.github.io/categories/concurrency/ // [Bryan Mills's talk on concurrency patterns]: https://drive.google.com/file/d/1nPdvhB0PutEJzdCq5ms6UI58dp50fcAN/view type Cond struct { noCopy noCopy // L is held while observing or changing the condition L Locker notify notifyList checker copyChecker } // NewCond returns a new Cond with Locker l. func NewCond(l Locker) *Cond { return &Cond{L: l} } // Wait atomically unlocks c.L and suspends execution // of the calling goroutine. After later resuming execution, // Wait locks c.L before returning. Unlike in other systems, // Wait cannot return unless awoken by Broadcast or Signal. // // Because c.L is not locked when Wait first resumes, the caller // typically cannot assume that the condition is true when // Wait returns. Instead, the caller should Wait in a loop: // // c.L.Lock() // for !condition() { // c.Wait() // } // ... make use of condition ... // c.L.Unlock() func (c *Cond) Wait() { c.checker.check() t := runtime_notifyListAdd(&c.notify) c.L.Unlock() runtime_notifyListWait(&c.notify, t) c.L.Lock() } // Signal wakes one goroutine waiting on c, if there is any. // // It is allowed but not required for the caller to hold c.L // during the call. // // Signal() does not affect goroutine scheduling priority; if other goroutines // are attempting to lock c.L, they may be awoken before a "waiting" goroutine. func (c *Cond) Signal() { c.checker.check() runtime_notifyListNotifyOne(&c.notify) } // Broadcast wakes all goroutines waiting on c. // // It is allowed but not required for the caller to hold c.L // during the call. func (c *Cond) Broadcast() { c.checker.check() runtime_notifyListNotifyAll(&c.notify) } // copyChecker holds back pointer to itself to detect object copying. type copyChecker uintptr func (c *copyChecker) check() { if uintptr(*c) != uintptr(unsafe.Pointer(c)) && !atomic.CompareAndSwapUintptr((*uintptr)(c), 0, uintptr(unsafe.Pointer(c))) && uintptr(*c) != uintptr(unsafe.Pointer(c)) { panic("sync.Cond is copied") } } // noCopy may be added to structs which must not be copied // after the first use. // // See https://golang.org/issues/8005#issuecomment-190753527 // for details. // // Note that it must not be embedded, due to the Lock and Unlock methods. type noCopy struct{} // Lock is a no-op used by -copylocks checker from `go vet`. func (*noCopy) Lock() {} func (*noCopy) Unlock() {}