/*
Copyright (c) 1993 Xerox Corporation.  All rights reserved.
*/
/*
 * PCR←ThCurr.h
 *
 * Current thread computation guaranteed to work even when there
 *   are multiple processors.
 *
 */

#ifndef ←←PCR←ThCurr←h
#define ←←PCR←ThCurr←h

#include <th/PCR←ThTypes.h>
#include <th/PCR←ThPvt.h>

extern PCR←ThPvt←SlotData *
PCR←ThCurr←GetSlotData(void);

extern PCR←ThPvt←SlotData *
PCR←ThCurr←GetSlotDataFromSP(void *p);
/*
    Return pointer to the thread slot data of the current thread
      or the thread whose stack contains location p.
    The caller must ensure that the thread won't disappear,
      either by holding appropriate locks or by being the thread.
*/

#define PCR←ThCurr←GetForkData() \
        ((PCR←ThCurr←GetSlotData())->tsd←tfd)

#define PCR←ThCurr←GetForkDataFromSP(p) \
        ((PCR←ThCurr←GetSlotDataFromSP(p))->tsd←tfd)

extern PCR←Th←T *
PCR←Th←CurrThread(void);
/*
    Return (opaque) pointer to current thread.
    This is also declared in PCR←Th.h.
    Equivalent to PCR←ThPvt←PublicFromForkData(PCR←ThCurr←GetForkData())
    for any automatic variable x.
*/


extern void
PCR←ThCurr←Update(PCR←ThPvt←SlotData *tsd, PCR←ThPvt←SlotData *newVal);
/*
    Insert tsd's stack into the ThCurr data structures
      so that a call to PCR←ThCurr←GetThread(p) (where p
      is an address in the stack of tsd) will return newVal. 
    Standard usage:
      PCR←ThCurr←Update(tsd, tsd) at thread create time.
      PCR←ThCurr←Update(tsd, NIL) at thread slot destroy time.
    The update to NIL is necessary to allow the thread slot
      to be garbage collected.
*/

#endif /* ←←PCR←ThCurr←h */