cvsuser     03/12/24 02:43:12

  Modified:    include/parrot pobj.h thread.h
               src      thread.c
  Log:
  parrot-threads-13
  * new _Sync structure holding interpreter back-pointer, mutex
  * new {UN,}LOCK_INTERPRETER macros to protect shared interpreter
    access
  
  Revision  Changes    Path
  1.31      +8 -2      parrot/include/parrot/pobj.h
  
  Index: pobj.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/pobj.h,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -w -r1.30 -r1.31
  --- pobj.h    20 Dec 2003 11:56:33 -0000      1.30
  +++ pobj.h    24 Dec 2003 10:43:08 -0000      1.31
  @@ -1,7 +1,7 @@
   /* pobj.h
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: pobj.h,v 1.30 2003/12/20 11:56:33 leo Exp $
  + *     $Id: pobj.h,v 1.31 2003/12/24 10:43:08 leo Exp $
    *  Overview:
    *     Parrot Object data members and flags enum
    *  Data Structure and Algorithms:
  @@ -106,13 +106,19 @@
   #  define PMC_data(pmc) (pmc)->data
   #endif
   
  +struct _Sync;   /* forward decl */
  +
   struct PMC_EXT {
   #if PMC_DATA_IN_EXT
       DPOINTER *data;
   #endif
       PMC *metadata;      /* properties */
  +    /*
  +     * PMC access synchronization for shared PMCs
  +     * s. parrot/thread.h
  +     */
  +    struct _Sync *synchronize;
   
  -    SYNC *synchronize;
       /* This flag determines the next PMC in the 'used' list during
          dead object detection in the GC. It is a linked list, which is
          only valid in trace_active_PMCs. Also, the linked list is
  
  
  
  1.14      +27 -2     parrot/include/parrot/thread.h
  
  Index: thread.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/thread.h,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -w -r1.13 -r1.14
  --- thread.h  19 Dec 2003 12:49:18 -0000      1.13
  +++ thread.h  24 Dec 2003 10:43:08 -0000      1.14
  @@ -1,7 +1,7 @@
   /* thread.h
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: thread.h,v 1.13 2003/12/19 12:49:18 leo Exp $
  + *     $Id: thread.h,v 1.14 2003/12/24 10:43:08 leo Exp $
    *  Overview:
    *     This is the api header for the thread primitives
    *  Data Structure and Algorithms:
  @@ -68,8 +68,26 @@
       Parrot_thread       thread;         /* pthread_t or such */
       thread_state_enum   state;
       UINTVAL             tid;            /* 0.. n-1 idx in interp array */
  +
  +    /* for wr access to interpreter e.g. for DOD/GC
  +     * if only used for DOD/GC the lock could be in the arena
  +     * instead here, or in the interpreter, with negative size impact
  +     * for the non-threaded case
  +     */
  +    Parrot_mutex interp_lock;
   } Thread_data;
   
  +#define LOCK_INTERPRETER(interp) \
  +    if ( (interp)->thread_data ) \
  +        LOCK((interp)->thread_data->interp_lock)
  +#define UNLOCK_INTERPRETER(interp) \
  +    if ( (interp)->thread_data ) \
  +        UNLOCK((interp)->thread_data->interp_lock)
  +
  +#define INTERPRETER_LOCK_INIT(interp) \
  +        MUTEX_INIT((interp)->thread_data->interp_lock)
  +#define INTERPRETER_LOCK_DESTROY(interp) \
  +        MUTEX_DESTROY((interp)->thread_data->interp_lock)
   /*
    * this global mutex protects the list of interpreters
    */
  @@ -77,7 +95,12 @@
   VAR_SCOPE struct Parrot_Interp          ** interpreter_array;
   VAR_SCOPE size_t                        n_interpreters;
   
  -#endif
  +
  +typedef struct _Sync {
  +    Parrot_Interp owner;                /* that interpreter, that owns
  +                                           the arena, where the PMC is in */
  +    Parrot_mutex pmc_lock;              /* for wr access to PMCs content */
  +} Sync;
   
   /*
    * thread.c interface functions
  @@ -91,6 +114,8 @@
   void pt_thread_detach(UINTVAL);
   void pt_thread_kill(UINTVAL);
   void pt_join_threads(Parrot_Interp);
  +
  +#endif
   
   /*
    * Local variables:
  
  
  
  1.9       +3 -1      parrot/src/thread.c
  
  Index: thread.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/thread.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -w -r1.8 -r1.9
  --- thread.c  22 Dec 2003 15:32:02 -0000      1.8
  +++ thread.c  24 Dec 2003 10:43:12 -0000      1.9
  @@ -1,7 +1,7 @@
   /* thread.c
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: thread.c,v 1.8 2003/12/22 15:32:02 leo Exp $
  + *     $Id: thread.c,v 1.9 2003/12/24 10:43:12 leo Exp $
    *  Overview:
    *     Thread handling stuff
    *  Data Structure and Algorithms:
  @@ -293,6 +293,7 @@
       size_t i;
   
       new_interp->thread_data = mem_sys_allocate_zeroed(sizeof(Thread_data));
  +    INTERPRETER_LOCK_INIT(new_interp);
       if (n_interpreters == 0) {
           /*
            * first time - add master interpreter and thread
  @@ -302,6 +303,7 @@
           interpreter_array[1] = new_interp;
           interpreter->thread_data =
               mem_sys_allocate_zeroed(sizeof(Thread_data));
  +        INTERPRETER_LOCK_INIT(interpreter);
           interpreter->thread_data->tid = 0;
           new_interp ->thread_data->tid = 1;
           n_interpreters = 2;
  
  
  

Reply via email to