Back to index

plt-scheme  4.2.1
pthread_support.h
Go to the documentation of this file.
00001 #ifndef GC_PTHREAD_SUPPORT_H
00002 #define GC_PTHREAD_SUPPORT_H
00003 
00004 # include "private/gc_priv.h"
00005 
00006 # if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS) \
00007      && !defined(GC_WIN32_THREADS)
00008      
00009 #if defined(GC_DARWIN_THREADS)
00010 # include "private/darwin_stop_world.h"
00011 #else
00012 # include "private/pthread_stop_world.h"
00013 #endif
00014 
00015 /* We use the allocation lock to protect thread-related data structures. */
00016 
00017 /* The set of all known threads.  We intercept thread creation and    */
00018 /* joins.                                                      */
00019 /* Protected by allocation/GC lock.                                   */
00020 /* Some of this should be declared volatile, but that's inconsistent  */
00021 /* with some library routine declarations.                            */
00022 typedef struct GC_Thread_Rep {
00023     struct GC_Thread_Rep * next;  /* More recently allocated threads  */
00024                               /* with a given pthread id come  */
00025                               /* first.  (All but the first are       */
00026                               /* guaranteed to be dead, but we may  */
00027                               /* not yet have registered the join.) */
00028     pthread_t id;
00029     /* Extra bookkeeping information the stopping code uses */
00030     struct thread_stop_info stop_info;
00031     
00032     short flags;
00033 #      define FINISHED 1    /* Thread has exited.       */
00034 #      define DETACHED 2    /* Thread is intended to be detached.     */
00035 #      define MAIN_THREAD 4 /* True for the original thread only.     */
00036     short thread_blocked;   /* Protected by GC lock.           */
00037                             /* Treated as a boolean value.  If set,   */
00038                             /* thread will acquire GC lock before     */
00039                             /* doing any pointer manipulations, and   */
00040                             /* has set its sp value.  Thus it does    */
00041                             /* not need to be sent a signal to stop   */
00042                             /* it.                             */
00043     ptr_t stack_end;        /* Cold end of the stack.          */
00044 #   ifdef IA64
00045        ptr_t backing_store_end;
00046        ptr_t backing_store_ptr;
00047 #   endif
00048     void * status;          /* The value returned from the thread.  */
00049                             /* Used only to avoid premature    */
00050                             /* reclamation of any data it might       */
00051                             /* reference.                      */
00052 #   ifdef THREAD_LOCAL_ALLOC
00053 #      if CPP_WORDSZ == 64 && defined(ALIGN_DOUBLE)
00054 #          define GRANULARITY 16
00055 #          define NFREELISTS 49
00056 #      else
00057 #          define GRANULARITY 8
00058 #          define NFREELISTS 65
00059 #      endif
00060        /* The ith free list corresponds to size i*GRANULARITY */
00061 #      define INDEX_FROM_BYTES(n) ((ADD_SLOP(n) + GRANULARITY - 1)/GRANULARITY)
00062 #      define BYTES_FROM_INDEX(i) ((i) * GRANULARITY - EXTRA_BYTES)
00063 #      define SMALL_ENOUGH(bytes) (ADD_SLOP(bytes) <= \
00064                                 (NFREELISTS-1)*GRANULARITY)
00065        ptr_t ptrfree_freelists[NFREELISTS];
00066        ptr_t normal_freelists[NFREELISTS];
00067 #      ifdef GC_GCJ_SUPPORT
00068          ptr_t gcj_freelists[NFREELISTS];
00069 #      endif
00070               /* Free lists contain either a pointer or a small count */
00071               /* reflecting the number of granules allocated at that  */
00072               /* size.                                         */
00073               /* 0 ==> thread-local allocation in use, free list      */
00074               /*       empty.                                         */
00075               /* > 0, <= DIRECT_GRANULES ==> Using global allocation, */
00076               /*       too few objects of this size have been         */
00077               /*      allocated by this thread.                */
00078               /* >= HBLKSIZE  => pointer to nonempty free list.       */
00079               /* > DIRECT_GRANULES, < HBLKSIZE ==> transition to      */
00080               /*    local alloc, equivalent to 0.                     */
00081 #      define DIRECT_GRANULES (HBLKSIZE/GRANULARITY)
00082               /* Don't use local free lists for up to this much       */
00083               /* allocation.                                          */
00084 #   endif
00085 } * GC_thread;
00086 
00087 # define THREAD_TABLE_SZ 128       /* Must be power of 2       */
00088 extern volatile GC_thread GC_threads[THREAD_TABLE_SZ];
00089 
00090 extern GC_bool GC_thr_initialized;
00091 
00092 GC_thread GC_lookup_thread(pthread_t id);
00093 
00094 void GC_stop_init();
00095 
00096 extern GC_bool GC_in_thread_creation;
00097        /* We may currently be in thread creation or destruction.      */
00098        /* Only set to TRUE while allocation lock is held.             */
00099        /* When set, it is OK to run GC from unknown thread.           */
00100 
00101 #endif /* GC_PTHREADS && !GC_SOLARIS_THREADS.... etc */
00102 #endif /* GC_PTHREAD_SUPPORT_H */