tclean up pthread for linux - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 2a931b7266c8a6550aca5f75b2ce3bf8655aa45b
 (DIR) parent 2709e6e3689c2f7957758de452ee740136e5eec0
 (HTM) Author: rsc <devnull@localhost>
       Date:   Fri, 11 Feb 2005 16:51:43 +0000
       
       clean up pthread for linux
       
       Diffstat:
         M acid/port                           |       6 ------
         A acid/pthread-linux-386              |      53 ++++++++++++++++++++++++++++++
         M acid/thread                         |      76 ++++---------------------------
       
       3 files changed, 62 insertions(+), 73 deletions(-)
       ---
 (DIR) diff --git a/acid/port b/acid/port
       t@@ -33,11 +33,6 @@ notelstk(addr)
                _stk({"PC", pc, "SP", sp, linkreg(addr)}, 1);
        }
        
       -// defn labstk(l)                                // trace from a label
       -// {
       -//         _stk({"PC", *(l+4), "SP", *l, linkreg(0)}, 0);
       -// }
       -
        defn params(param)
        {
                while param do {
       t@@ -119,7 +114,6 @@ defn _stk(regs, dolocals)
                        if callerpc == 0 then
                                done=1;
                }
       -
                if callerpc && !done then {
                        print(stkprefix, fmt(callerpc, 'a'), " ");
                        pfl(callerpc);
 (DIR) diff --git a/acid/pthread-linux-386 b/acid/pthread-linux-386
       t@@ -0,0 +1,53 @@
       +// Linux NPTL 2.3.2
       +complex list_head {
       +        'X'        0        next;
       +        'X'        4        prev;
       +};
       +complex nptl_pthread {
       +        'X'        0        loopback;
       +        'X'        0x48        tid;
       +};
       +
       +// cannot be done at load time -- need shared library symbols
       +defn guessnptl() {
       +        if var("nptl_version") then {
       +                pthreadlibrary = "nptl";
       +                isnptl = 1;
       +        } else {
       +                pthreadlibrary = "linuxclone";
       +                isnptl = 0;
       +        }
       +}
       +
       +defn pthread2tid(p) {
       +        guessnptl();
       +        if p == 0 then
       +                return 0;
       +        if isnptl then {
       +                complex nptl_pthread p;
       +                if p.loopback != p then
       +                        error("bad pthread "+itoa(p, "%x"));
       +                return p.tid;
       +        }else {
       +                return p\X;
       +        }
       +}
       +
       +defn pthreadlist() {
       +        local all, p, n, l;
       +
       +        if isnptl then {
       +                all = {};
       +                l = (list_head)stack_used;
       +                l = (list_head)l.next;
       +                while l != stack_used do {
       +                        p = l - *_thread_db_pthread_list;
       +                        all = append all, p;
       +                        l = (list_head)l.next;
       +                }
       +        } else {
       +                all = {};
       +        }
       +        return all;
       +}
       +                
 (DIR) diff --git a/acid/thread b/acid/thread
       t@@ -3,62 +3,7 @@
        // avoid complicated libthread_db interface
        //
        
       -// Linux NPTL 2.3.2
       -complex list_head {
       -        'X'        0        next;
       -        'X'        4        prev;
       -};
       -complex nptl_pthread {
       -        'X'        0        loopback;
       -        'X'        0x48        tid;
       -};
       -defn isnptl() {
       -        return var("nptl_version") != {};
       -}
       -defn nptl2tid(p) {
       -        complex nptl_pthread p;
       -        if p.loopback != p then 
       -                error("bad pthread "+itoa(p, "%x"));
       -        return p.tid;
       -}
       -defn nptlpthreadlist() {
       -        local all, p, n, l;
       -
       -        all = {};
       -        l = (list_head)stack_used;
       -        l = (list_head)l.next;
       -        while l != stack_used do {
       -                p = l - *_thread_db_pthread_list;
       -                all = append all, p;
       -                l = (list_head)l.next;
       -        }
       -        return all;
       -}
       -
       -// 
       -// Generic dispatch
       -// 
       -defn pthreadlibrary() {
       -        if var("_pthreadlibrary") == {} then {
       -                if isnptl() then
       -                        _pthreadlibrary = "nptl";
       -                else
       -                        _pthreadlibrary = "unknown";
       -        }
       -        return _pthreadlibrary;
       -}
       -
       -defn id2tid(id) {
       -        if pthreadlibrary() == "nptl" then
       -                return nptl2tid(id);
       -        error("unknown pthread library: "+pthreadlibrary);
       -}
       -
       -defn pthreadlist() {
       -        if pthreadlibrary() == "nptl" then
       -                return nptlpthreadlist(id);
       -        error("unknown pthread library: "+pthreadlibrary);
       -}
       +include("pthread-"+systype+"-"+objtype);
        
        // pick apart system mcontext_t structures
        defn mcontext(m)
       t@@ -98,7 +43,7 @@ defn altfmt(A){
                complex Alt A;
        
                s = "alt(";
       -        s = s + "tag(*" + itoa(A.tag, "%x") + "=" + itoa(*A.tag, "%x") + ") ";
       +        s = s + "tag(*" + itoa(A.tag, "%#x") + "=" + itoa(*A.tag, "%#x") + ") ";
                i = 0;
                yes = 0;
                while A.op != CHANEND && A.op != CHANNOBLK do{
       t@@ -109,7 +54,7 @@ defn altfmt(A){
                                if A.op == CHANSND then s = s + "send";
                                if A.op == CHANRCV then s = s + "recv";
                                s = s + "(channel(";
       -                        s = s + itoa(A.c, "%x");
       +                        s = s + itoa(A.c, "%#x");
                                s = s + "))";
                                yes = 1;
                        }
       t@@ -184,7 +129,7 @@ defn fnname(a){
                                return sym[0];
                        s = tail s;
                }
       -        return itoa(a, "%x");
       +        return itoa(a, "%#x");
        }
        
        stkignorelist = {};
       t@@ -199,7 +144,7 @@ defn threadstkline(T){
                P = (Proc)T.proc;
                if P.thread == T then {
                        mainpid = pid;
       -                setproc(id2tid(P.osprocid));
       +                setproc(pthread2tid(P.osprocid));
                        stk = strace({});
                        setproc(mainpid);
                } else
       t@@ -230,7 +175,7 @@ defn threadfmt(T){
                local P, s, name;
        
                P = (Proc)T.proc;
       -        s = "t=(_Thread)"+itoa(T, "%-10x")+" // ";
       +        s = "t=(_Thread)"+itoa(T, "%#-10x")+" // ";
        
                if P.thread == T then
                        s = s + "Running    ";
       t@@ -296,12 +241,10 @@ defn threadstks(P){
                complex Proc P;
                local T,  mainpid, pref, ign;
        
       -        // mainpid = pid;
                pref = stkprefix;
                stkprefix = pref+"\t\t";
                ign = stkignore;
                stkignore = threadstkignore;
       -        // setproc(P.pid);
                T = (_Thread)P.allthreads.$head;
                while T != 0 do{
                        print("\t");
       t@@ -310,7 +253,6 @@ defn threadstks(P){
                        T = (_Thread)T.allnext;
                        print("\n");
                }
       -        // setproc(mainpid);
                stkprefix = pref;
                stkignore = ign;
        }
       t@@ -318,7 +260,7 @@ defn threadstks(P){
        defn proc(P){
                complex Proc P;
        
       -        print("p=(Proc)", itoa(P, "%-10x"), "  // pthread ", P.osprocid\X, " pid ", id2tid(P.osprocid)\D, " ");
       +        print("p=(Proc)", itoa(P, "%#-10x"), "  // pthread ", P.osprocid\X, " pid ", pthread2tid(P.osprocid)\D, " ");
                if P.thread==0 then
                        print(" Sched");
                else
       t@@ -332,7 +274,7 @@ defn threadlstk(T){
        
                P = (Proc)T.proc;
                mainpid = pid;
       -        setproc(id2tid(P.osprocid));
       +        setproc(pthread2tid(P.osprocid));
        
                if P.thread == T then
                        lstk();
       t@@ -347,7 +289,7 @@ defn threadstk(T){
        
                P = (Proc)T.proc;
                mainpid = pid;
       -        setproc(id2tid(P.osprocid));
       +        setproc(pthread2tid(P.osprocid));
        
                if P.thread == T then
                        stk();