~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/runtime/lock_sema.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
                runtime·throw("runtime·lock: lock count");
42
42
 
43
43
        // Speculative grab for lock.
44
 
        if(runtime·casp(&l->waitm, nil, (void*)LOCKED))
 
44
        if(runtime·casp((void**)&l->key, nil, (void*)LOCKED))
45
45
                return;
46
46
 
47
47
        if(m->waitsema == 0)
54
54
                spin = ACTIVE_SPIN;
55
55
 
56
56
        for(i=0;; i++) {
57
 
                v = (uintptr)runtime·atomicloadp(&l->waitm);
 
57
                v = (uintptr)runtime·atomicloadp((void**)&l->key);
58
58
                if((v&LOCKED) == 0) {
59
59
unlocked:
60
 
                        if(runtime·casp(&l->waitm, (void*)v, (void*)(v|LOCKED)))
 
60
                        if(runtime·casp((void**)&l->key, (void*)v, (void*)(v|LOCKED)))
61
61
                                return;
62
62
                        i = 0;
63
63
                }
72
72
                        // Queue this M.
73
73
                        for(;;) {
74
74
                                m->nextwaitm = (void*)(v&~LOCKED);
75
 
                                if(runtime·casp(&l->waitm, (void*)v, (void*)((uintptr)m|LOCKED)))
 
75
                                if(runtime·casp((void**)&l->key, (void*)v, (void*)((uintptr)m|LOCKED)))
76
76
                                        break;
77
 
                                v = (uintptr)runtime·atomicloadp(&l->waitm);
 
77
                                v = (uintptr)runtime·atomicloadp((void**)&l->key);
78
78
                                if((v&LOCKED) == 0)
79
79
                                        goto unlocked;
80
80
                        }
97
97
                runtime·throw("runtime·unlock: lock count");
98
98
 
99
99
        for(;;) {
100
 
                v = (uintptr)runtime·atomicloadp(&l->waitm);
 
100
                v = (uintptr)runtime·atomicloadp((void**)&l->key);
101
101
                if(v == LOCKED) {
102
 
                        if(runtime·casp(&l->waitm, (void*)LOCKED, nil))
 
102
                        if(runtime·casp((void**)&l->key, (void*)LOCKED, nil))
103
103
                                break;
104
104
                } else {
105
105
                        // Other M's are waiting for the lock.
106
106
                        // Dequeue an M.
107
107
                        mp = (void*)(v&~LOCKED);
108
 
                        if(runtime·casp(&l->waitm, (void*)v, mp->nextwaitm)) {
 
108
                        if(runtime·casp((void**)&l->key, (void*)v, mp->nextwaitm)) {
109
109
                                // Dequeued an M.  Wake it.
110
110
                                runtime·semawakeup(mp);
111
111
                                break;
118
118
void
119
119
runtime·noteclear(Note *n)
120
120
{
121
 
        n->waitm = nil;
 
121
        n->key = 0;
122
122
}
123
123
 
124
124
void
127
127
        M *mp;
128
128
 
129
129
        do
130
 
                mp = runtime·atomicloadp(&n->waitm);
131
 
        while(!runtime·casp(&n->waitm, mp, (void*)LOCKED));
 
130
                mp = runtime·atomicloadp((void**)&n->key);
 
131
        while(!runtime·casp((void**)&n->key, mp, (void*)LOCKED));
132
132
 
133
133
        // Successfully set waitm to LOCKED.
134
134
        // What was it before?
148
148
{
149
149
        if(m->waitsema == 0)
150
150
                m->waitsema = runtime·semacreate();
151
 
        if(!runtime·casp(&n->waitm, nil, m)) {  // must be LOCKED (got wakeup)
152
 
                if(n->waitm != (void*)LOCKED)
 
151
        if(!runtime·casp((void**)&n->key, nil, m)) {  // must be LOCKED (got wakeup)
 
152
                if(n->key != LOCKED)
153
153
                        runtime·throw("notesleep - waitm out of sync");
154
154
                return;
155
155
        }
176
176
                m->waitsema = runtime·semacreate();
177
177
 
178
178
        // Register for wakeup on n->waitm.
179
 
        if(!runtime·casp(&n->waitm, nil, m)) {  // must be LOCKED (got wakeup already)
180
 
                if(n->waitm != (void*)LOCKED)
 
179
        if(!runtime·casp((void**)&n->key, nil, m)) {  // must be LOCKED (got wakeup already)
 
180
                if(n->key != LOCKED)
181
181
                        runtime·throw("notetsleep - waitm out of sync");
182
182
                return;
183
183
        }
212
212
        // so that any notewakeup racing with the return does not
213
213
        // try to grant us the semaphore when we don't expect it.
214
214
        for(;;) {
215
 
                mp = runtime·atomicloadp(&n->waitm);
 
215
                mp = runtime·atomicloadp((void**)&n->key);
216
216
                if(mp == m) {
217
217
                        // No wakeup yet; unregister if possible.
218
 
                        if(runtime·casp(&n->waitm, mp, nil))
 
218
                        if(runtime·casp((void**)&n->key, mp, nil))
219
219
                                return;
220
220
                } else if(mp == (M*)LOCKED) {
221
221
                        // Wakeup happened so semaphore is available.