This is the mail archive of the java-prs@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: libgcj/117: _Jv_PthreadCheckMonitor test is not portable.


The following reply was made to PR libgcj/117; it has been noted by GNATS.

From: Tom Tromey <tromey@cygnus.com>
To: charles.gauthier@iit.nrc.ca
Cc: java-gnats@sourceware.cygnus.com
Subject: Re: libgcj/117: _Jv_PthreadCheckMonitor test  is not portable.
Date: Wed, 8 Dec 1999 18:53:54 -0800 (PST)

 I apparently forgot about the no-recursive-mutexes case when writing
 this code.  Can you try this patch?  I haven't even tried compiling
 it... but if it fails, it at least gives the general idea of what to do.
 
 Index: include/posix-threads.h
 ===================================================================
 RCS file: /cvs/java/libgcj/libjava/include/posix-threads.h,v
 retrieving revision 1.9
 diff -u -r1.9 posix-threads.h
 --- posix-threads.h	1999/11/04 16:45:11	1.9
 +++ posix-threads.h	1999/12/09 02:51:30
 @@ -103,10 +103,13 @@
  inline int
  _Jv_PthreadCheckMonitor (_Jv_Mutex_t *mu)
  {
 -  pthread_mutex_t *pmu = _Jv_PthreadGetMutex (mu);
 +  pthread_mutex_t *pmu;
 +#ifdef HAVE_RECURSIVE_MUTEX
 +  pmu = _Jv_PthreadGetMutex (mu);
    // See if the mutex is locked by this thread.
    if (pthread_mutex_trylock (pmu))
      return 1;
 +
  #if defined (PTHREAD_MUTEX_HAVE_M_COUNT)
    // On Linux we exploit knowledge of the implementation.
    int r = pmu->m_count == 1;
 @@ -117,6 +120,17 @@
  #else
    int r = mu->count == 0;
  #endif
 +
 +#else /* HAVE_RECURSIVE_MUTEX */
 +  // In this case we must lock our structure and then see if this
 +  // thread owns the mutex.
 +  pmu = &mu->mutex;
 +  if (pthread_mutex_lock (pmu))
 +    return 0;
 +
 +  int r = mu->thread == pthread_self () && mu->count == 0;
 +#endif /* HAVE_RECURSIVE_MUTEX */
 +
    pthread_mutex_unlock (pmu);
    return r;
  }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]