Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1140)

Delta Between Two Patch Sets: src/pkg/sync/mutex.go

Issue 3770045: code review 3770045: sync: Proposal for barrier implementation (Closed)
Left Patch Set: code review 3770045: sync: Proposal for barrier implementation Created 14 years, 2 months ago
Right Patch Set: diff -r 138fb74f2651 https://go.googlecode.com/hg/ Created 14 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/sync/Makefile ('k') | src/pkg/sync/waitgroup.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(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
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 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b