home *** CD-ROM | disk | FTP | other *** search
/ Game Programming - All in One (3rd Edition) / game_prog_all_in_one_3rd_ed.iso / pthread / docs / WinCE-PORT < prev   
Encoding:
Text File  |  2003-09-12  |  7.3 KB  |  209 lines

  1. Some interesting news:
  2.  
  3. I have been able to port pthread-win32 to Windows-CE,
  4. which uses a subset of the WIN32 API.
  5.  
  6. Since we intend to keep using pthread-win32 for our
  7. Commercial WinCE developments, I would be very interested
  8. if WinCE support could be added to the main source tree
  9. of pthread-win32.  Also, I would like to be credited
  10. for this port :-)
  11.  
  12. Now, here is the story...
  13.  
  14. The port was performed and tested on a Casio "Cassiopeia"
  15. PalmSize PC, which runs a MIP processor.  The OS in the
  16. Casio is WinCE version 2.11, but I used VC++ 6.0 with
  17. the WinCE SDK for version 2.01.
  18.  
  19. I used pthread-win32 to port a heavily multithreaded
  20. commercial application (real-time MPEG video player)
  21. from Linux to WinCE.  I consider the changes that
  22. I have done to be quite well tested.
  23.  
  24. Overall the modifications that we had to do are minor.
  25.  
  26. The WinCE port were based on pthread-win32-snap-1999-05-30,
  27. but I am certain that they can be integrated very easiely
  28. to more recent versions of the source.
  29.  
  30. I have attached the modified source code:
  31. pthread-win32-snap-1999-05-30-WinCE.
  32.  
  33. All the changes do not affect the code compiled on non-WinCE
  34. environment, provided that the macros used for WinCE compilation
  35. are not used, of course!
  36.  
  37. Overall description of the WinCE port:
  38. -------------------------------------
  39.  
  40. Most of the changes had to be made in areas where
  41. pthread-win32 was relying on some standard-C librairies
  42. (e.g. _ftime, calloc, errno), which are not available
  43. on WinCE. We have changed the code to use native Win32
  44. API instead (or in some cases we made wrappers).
  45.  
  46. The Win32 Semaphores are not available,
  47. so we had to re-implement Semaphores using mutexes
  48. and events.
  49.  
  50. Limitations / known problems of the WinCE port:
  51. ----------------------------------------------
  52.  
  53. Not all the semaphore routines have been ported
  54. (semaphores are defined by Posix but are not part
  55. pf pthread).  I have just done enough to make
  56. pthread routines (that rely internally on semaphores)
  57. work, like signal conditions.
  58.  
  59. I noticed that the Win32 threads work slightly
  60. differently on WinCE.  This may have some impact
  61. on some tricky parts of pthread-win32, but I have
  62. not really investigated.  For example, on WinCE,
  63. the process is killed if the main thread falls off
  64. the bottom (or calls pthread_exit), regardless
  65. of the existence of any other detached thread.
  66. Microsoft manual indicates that this behavior is
  67. deffirent from that of Windows Threads for other
  68. Win32 platforms.
  69.  
  70.  
  71. Detailed descriptions of the changes and rationals:
  72.  
  73. ------------------------------------
  74. - use a new macro NEED_ERRNO.
  75.  
  76. If defined, the code in errno.c that defines a reentrant errno
  77. is compiled, regardless of _MT and _REENTRANT.
  78.  
  79. Rational: On WinCE, there is no support for <stdio.h>, <errno.h> or
  80. any other standard C library, i.e. even if _MT or _REENTRANT
  81. is defined, errno is not provided by any library.  NEED_ERRNO
  82. must be set to compile for WinCE.
  83.  
  84. ------------------------------------
  85. - In implement.h, change #include <semaphore.h> to #include "semaphore.h".
  86.  
  87. Rational: semaphore.h is provided in pthread-win32 and should not
  88. be searched in the systems standard include.  would not compile.
  89. This change does not seem to create problems on "classic" win32
  90. (e.g. win95).
  91.  
  92. ------------------------------------
  93. - use a new macro NEED_CALLOC.
  94.  
  95. If defined, some code in misc.c will provide a replacement
  96. for calloc, which is not available on Win32.
  97.  
  98.  
  99. ------------------------------------
  100. - use a new macro NEED_CREATETHREAD.
  101.  
  102. If defined, implement.h defines the macro _beginthreadex
  103. and _endthreadex.
  104.  
  105. Rational: On WinCE, the wrappers _beginthreadex and _endthreadex
  106. do not exist. The native Win32 routines must be used.
  107.  
  108. ------------------------------------
  109. - in misc.c:
  110.  
  111. #ifdef NEED_DUPLICATEHANDLE
  112.       /* DuplicateHandle does not exist on WinCE */
  113.       self->threadH = GetCurrentThread();
  114. #else
  115.       if( !DuplicateHandle(
  116.                    GetCurrentProcess(),
  117.                    GetCurrentThread(),
  118.                    GetCurrentProcess(),
  119.                    &self->threadH,
  120.                    0,
  121.                    FALSE,
  122.                    DUPLICATE_SAME_ACCESS ) )
  123.         {
  124.           free( self );
  125.           return (NULL);
  126.         }
  127. #endif
  128.  
  129. Rational: On WinCE, DuplicateHandle does not exist.  I could not understand
  130. why DuplicateHandle must be used.  It seems to me that getting the current
  131. thread handle with GetCurrentThread() is sufficient, and it seems to work
  132. perfectly fine, so maybe DuplicateHandle was just plain useless to begin with ?
  133.  
  134. ------------------------------------
  135. - In private.c, added some code at the beginning of ptw32_processInitialize
  136. to detect the case of multiple calls to ptw32_processInitialize.
  137.  
  138. Rational: In order to debug pthread-win32, it is easier to compile
  139. it as a regular library (it is not possible to debug DLL's on winCE).
  140. In that case, the application must call ptw32_rocessInitialize()
  141. explicitely, to initialize pthread-win32.  It is safer in this circumstance
  142. to handle the case where ptw32_processInitialize() is called on
  143. an already initialized library:
  144.  
  145. int
  146. ptw32_processInitialize (void)
  147. {
  148.     if (ptw32_processInitialized) {
  149.         /* 
  150.          * ignore if already initialized. this is useful for 
  151.          * programs that uses a non-dll pthread
  152.          * library. such programs must call ptw32_processInitialize() explicitely,
  153.          * since this initialization routine is automatically called only when
  154.          * the dll is loaded.
  155.          */
  156.         return TRUE;
  157.     }
  158.     ptw32_processInitialized = TRUE;
  159.       [...]
  160. }
  161.  
  162. ------------------------------------
  163. - in private.c, if macro NEED_FTIME is defined, add routines to
  164. convert timespec_to_filetime and filetime_to_timespec, and modified
  165. code that was using _ftime() to use Win32 API instead.
  166.  
  167. Rational: _ftime is not available on WinCE.  It is necessary to use
  168. the native Win32 time API instead.
  169.  
  170. Note: the routine timespec_to_filetime is provided as a convenience and a mean
  171. to test that filetime_to_timespec works, but it is not used by the library.
  172.  
  173. ------------------------------------
  174. - in semaphore.c, if macro NEED_SEM is defined, add code for the routines
  175. _increase_semaphore and _decrease_semaphore, and modify significantly
  176. the implementation of the semaphores so that it does not use CreateSemaphore.
  177.  
  178. Rational: CreateSemaphore is not available on WinCE.  I had to re-implement
  179. semaphores using mutexes and Events.
  180.  
  181. Note: Only the semaphore routines that are used by pthread are implemented
  182. (i.e. signal conditions rely on a subset of the semaphores routines, and
  183. this subset works). Some other semaphore routines (e.g. sem_trywait) are
  184. not yet supported on my WinCE port (and since I don't need them, I am not
  185. planning to do anything about them).
  186.  
  187. ------------------------------------
  188. - in tsd.c, changed the code that defines TLS_OUT_OF_INDEXES
  189.  
  190. /* TLS_OUT_OF_INDEXES not defined on WinCE */
  191. #ifndef TLS_OUT_OF_INDEXES
  192. #define TLS_OUT_OF_INDEXES 0xffffffff
  193. #endif
  194.  
  195. Rational: TLS_OUT_OF_INDEXES is not defined in any standard include file
  196. on WinCE.
  197.  
  198. ------------------------------------
  199. - added file need_errno.h
  200.  
  201. Rational: On WinCE, there is no errno.h file. need_errno.h is just a
  202. copy of windows version of errno.h, with minor modifications due to the fact
  203. that some of the error codes are defined by the WinCE socket library.
  204. In pthread.h, if NEED_ERRNO is defined, the file need_errno.h is
  205. included (instead of <errno.h>).
  206.  
  207.  
  208. -- eof
  209.