Annotation of lucent/sys/src/9/port/taslock.c, revision 1.1.1.1

1.1       root        1: #include "u.h"
                      2: #include "../port/lib.h"
                      3: #include "mem.h"
                      4: #include "dat.h"
                      5: #include "fns.h"
                      6: #include "../port/error.h"
                      7: 
                      8: void
                      9: lock(Lock *l)
                     10: {
                     11:        int i;
                     12:        ulong pc;
                     13: 
                     14:        pc = getcallerpc(((uchar*)&l) - sizeof(l));
                     15: 
                     16:        for(i = 0; i < 10000000; i++){
                     17:                if (tas(&l->key) == 0){
                     18:                        if(u)
                     19:                                u->p->hasspin = 1;
                     20:                        l->pc = pc;
                     21:                        return;
                     22:                }
                     23:        }
                     24:        l->key = 0;
                     25:        panic("lock loop 0x%lux key 0x%lux pc 0x%lux held by pc 0x%lux\n",
                     26:                        l->key, i, pc, l->pc);
                     27: }
                     28: 
                     29: void
                     30: ilock(Lock *l)
                     31: {
                     32:        int i;
                     33:        ulong pc;
                     34:        ulong x;
                     35: 
                     36:        pc = getcallerpc(((uchar*)&l) - sizeof(l));
                     37: 
                     38:        x = splhi();
                     39:        for(i = 0; i < 10000000; i++){
                     40:                if (tas(&l->key) == 0){
                     41:                        l->pc = pc;
                     42:                        l->sr = x;
                     43:                        return;
                     44:                }
                     45:        }
                     46:        l->key = 0;
                     47:        splx(x);
                     48:        panic("lock loop 0x%lux key 0x%lux pc 0x%lux held by pc 0x%lux\n",
                     49:                        l->key, i, pc, l->pc);
                     50: }
                     51: 
                     52: int
                     53: canlock(Lock *l)
                     54: {
                     55:        if(tas(&l->key))
                     56:                return 0;
                     57:        l->pc = getcallerpc(((uchar*)&l) - sizeof(l));
                     58:        if(u && u->p)
                     59:                u->p->hasspin = 1;
                     60:        return 1;
                     61: }
                     62: 
                     63: void
                     64: unlock(Lock *l)
                     65: {
                     66:        l->pc = 0;
                     67:        l->key = 0;
                     68:        if(u && u->p)
                     69:                u->p->hasspin = 0;
                     70: }
                     71: 
                     72: void
                     73: iunlock(Lock *l)
                     74: {
                     75:        ulong sr;
                     76: 
                     77:        sr = l->sr;
                     78:        l->pc = 0;
                     79:        l->key = 0;
                     80:        splx(sr);
                     81: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.