Subject: ThreadedX patch, take 2
To: None <tech-x11@netbsd.org>
From: Jason R Thorpe <thorpej@wasabisystems.com>
List: tech-userlevel
Date: 01/19/2003 21:48:25
--YZ5djTAD1cGYuMQK
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

So, assuming bleeding edge xsrc and bleeding edge src, the following
patch seeems to DTRT with regards to pulling in stubs for non-threaded
apps, and the real routines for threaded apps.  Patch against xsrc/xfree.

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>

--YZ5djTAD1cGYuMQK
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=xthreads-patch

Index: include/Xthreads.h
===================================================================
RCS file: /cvsroot/xsrc/xfree/xc/include/Xthreads.h,v
retrieving revision 1.1.1.4
diff -c -r1.1.1.4 Xthreads.h
*** include/Xthreads.h	2002/01/19 14:59:25	1.1.1.4
--- include/Xthreads.h	2003/01/20 05:38:03
***************
*** 196,201 ****
--- 196,232 ----
  #define xcondition_signal(c) tis_cond_signal(c)
  #define xcondition_broadcast(c) tis_cond_broadcast(c)
  #else
+ #ifdef USE_NBSD_THREADLIB
+ /*
+  * NetBSD threadlib support is intended for thread safe libraries.
+  * This should not be used for general client programming.
+  */
+ #include <threadlib.h>
+ typedef thr_t xthread_t;
+ typedef thread_key_t xthread_key_t;
+ typedef cond_t xcondition_rec;
+ typedef mutex_t xmutex_rec;
+ #define xthread_self thr_self
+ #define xthread_fork(func,closure) { thr_t _tmpxthr; \
+ 	/* XXX Create it detached?  --thorpej */ \
+ 	thr_create(&_tmpxthr,NULL,func,closure); }
+ #define xthread_yield() thr_yield()
+ #define xthread_exit(v) thr_exit(v)
+ #define xthread_key_create(kp,d) thr_key_create(kp,d)
+ #define xthread_key_delete(k) thr_key_delete(k)
+ #define xthread_set_specific(k,v) thr_setspecific(k,v)
+ #define xthread_get_specific(k,vp) *(vp) = thr_getspecific(k)
+ #define XMUTEX_INITIALIZER MUTEX_INITIALIZER
+ #define xmutex_init(m) mutex_init(m, 0)
+ #define xmutex_clear(m) mutex_destroy(m)
+ #define xmutex_lock(m) mutex_lock(m)
+ #define xmutex_unlock(m) mutex_unlock(m)
+ #define xcondition_init(c) cond_init(c, 0, 0)
+ #define xcondition_clear(c) cond_destroy(c)
+ #define xcondition_wait(c,m) cond_wait(c,m)
+ #define xcondition_signal(c) cond_signal(c)
+ #define xcondition_broadcast(c) cond_broadcast(c)
+ #else
  #include <pthread.h>
  typedef pthread_t xthread_t;
  typedef pthread_key_t xthread_key_t;
***************
*** 248,253 ****
--- 279,285 ----
  #define xcondition_set_name(cv,str) ((char**)(cv)->field1)[5] = (str)
  #endif /* DEBUG */
  #endif /* _CMA_VENDOR_ == _CMA__IBM */
+ #endif /* USE_NBSD_THREADLIB */
  #endif /* USE_TIS_SUPPORT */
  #endif /* WIN32 */
  #endif /* SVR4 */
Index: config/cf/NetBSD.cf
===================================================================
RCS file: /cvsroot/xsrc/xfree/xc/config/cf/NetBSD.cf,v
retrieving revision 1.38
diff -c -r1.38 NetBSD.cf
*** config/cf/NetBSD.cf	2003/01/19 14:37:19	1.38
--- config/cf/NetBSD.cf	2003/01/20 05:38:04
***************
*** 99,104 ****
--- 99,105 ----
   * NetBSD 1.6M and newer supports POSIX Threads.
   */
  
+ #define	NetBSDThreads
  #if defined(NetBSDThreads) && \
      ((OSMajorVersion > 1) || \
       (OSMajorVersion == 1 && OSMinorVersion > 6) || \
***************
*** 107,116 ****
  # define HasPosixThreads	YES
  # define ThreadedX		YES
  # define HasThreadSafeAPI	YES
! # define ThreadsLibraries	-lpthread
  # define SystemMTDefines	-D_REENTRANT
  # define MTSafeAPIDefines	-DXUSE_MTSAFE_API -DXNO_MTSAFE_PWDAPI
! # define SharedX11Reqs		-lpthread
  #endif
  
  /*
--- 108,118 ----
  # define HasPosixThreads	YES
  # define ThreadedX		YES
  # define HasThreadSafeAPI	YES
! XCOMM # define ThreadsLibraries	-lpthread
! # define LibraryMTDefines	-DUSE_NBSD_THREADLIB
  # define SystemMTDefines	-D_REENTRANT
  # define MTSafeAPIDefines	-DXUSE_MTSAFE_API -DXNO_MTSAFE_PWDAPI
! XCOMM # define SharedX11Reqs		-lpthread
  #endif
  
  /*

--YZ5djTAD1cGYuMQK--