LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // The sync package provides basic synchronization primitives | 5 // The sync package provides basic synchronization primitives |
6 // such as mutual exclusion locks. Other than the Once type, | 6 // such as mutual exclusion locks. Other than the Once and |
7 // most are intended for use by low-level library routines. | 7 // WaitGroup types, most are intended for use by low-level |
8 // Higher-level synchronization is better done via channels | 8 // library routines. Higher-level synchronization is better |
9 // and communication. | 9 // done via channels and communication. |
10 package sync | 10 package sync |
11 | 11 |
12 import "runtime" | 12 import "runtime" |
13 | 13 |
14 func cas(val *uint32, old, new uint32) bool | 14 func cas(val *uint32, old, new uint32) bool |
15 | 15 |
16 // A Mutex is a mutual exclusion lock. | 16 // A Mutex is a mutual exclusion lock. |
17 // Mutexes can be created as part of other structures; | 17 // Mutexes can be created as part of other structures; |
18 // the zero value for a Mutex is an unlocked mutex. | 18 // the zero value for a Mutex is an unlocked mutex. |
19 type Mutex struct { | 19 type Mutex struct { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 // A locked Mutex is not associated with a particular goroutine. | 52 // A locked Mutex is not associated with a particular goroutine. |
53 // It is allowed for one goroutine to lock a Mutex and then | 53 // It is allowed for one goroutine to lock a Mutex and then |
54 // arrange for another goroutine to unlock it. | 54 // arrange for another goroutine to unlock it. |
55 func (m *Mutex) Unlock() { | 55 func (m *Mutex) Unlock() { |
56 if xadd(&m.key, -1) == 0 { | 56 if xadd(&m.key, -1) == 0 { |
57 // changed from 1 to 0; no contention | 57 // changed from 1 to 0; no contention |
58 return | 58 return |
59 } | 59 } |
60 runtime.Semrelease(&m.sema) | 60 runtime.Semrelease(&m.sema) |
61 } | 61 } |
LEFT | RIGHT |