[Gc] WinCE(again) + threads + patch by Ivan

Zeyi Lee biosli at hotmail.com
Wed Aug 19 23:44:28 PDT 2009


Dear Ivan:
         I've downloaded the latest gc(ChangeLog date: 2009-08-11), and then 
merged your patch code for WinCE (Part 1/2/3).
                  
         I found there are several types of issues as following:
         In diff144c
         diff -ru CVS_plus_diff112/bdwgc/win32_threads.c 
updated/bdwgc/win32_threads.c
--- CVS_plus_diff112/bdwgc/win32_threads.c  2009-08-02 18:02:12.000000000 +0400
+++ updated/bdwgc/win32_threads.c        2009-08-06 12:17:44.000000000 +0400
@@ -491,7 +504,9 @@
     } else {
       return (GC_thread)(dll_thread_table + i);
     }
-  } else {
+  }
+#endif
+  {
     word hv = ((word)thread_id) % THREAD_TABLE_SZ;
     register GC_thread p = GC_threads[hv];
I thought the added lines may could change like this:
@@ -491,7 +504,9 @@
     } else {
       return (GC_thread)(dll_thread_table + i);
     }
-  } else {
+  } else
+#endif
+  {
     word hv = ((word)thread_id) % THREAD_TABLE_SZ;
     register GC_thread p = GC_threads[hv];
The same issue :
@@ -718,7 +737,9 @@
        i++);
     if (i > my_max) return 0;
     return (GC_thread)(dll_thread_table + i);
-  } else {
+  }
+#endif
+  {
     /* We first try the cache.  If that fails, we use a very slow */
     /* approach.                                                             
*/
     int hv_guess = GET_PTHREAD_MAP_CACHE(id) % THREAD_TABLE_SZ;
change like:
@@ -718,7 +737,9 @@
        i++);
     if (i > my_max) return 0;
     return (GC_thread)(dll_thread_table + i);
-  } else {
+  } else
+#endif
+  {
     /* We first try the cache.  If that fails, we use a very slow */
     /* approach.                                                             
*/
     int hv_guess = GET_PTHREAD_MAP_CACHE(id) % THREAD_TABLE_SZ;
 
When I finished the above-mentioned process, I started to compile the project. 
Then i got error as below:
1>Compiling...
1>misc.c
1>.\source\misc.c(871) : fatal error C1083: Cannot open include 
file: 'crtdbg.h': No such file or directory
WinCE doesn't support "debug"function.
Hence, I think i have to add a crtdbg.h for WinCE to libgc? Like 
this:https://www.codeproject.com/KB/mobile/ce_crtdbg.aspx?msg=1055787
Meanwhile I changed misc.c provisional as following:
--- C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/misc.c-revBASE.svn000.tmp.c        Aug 
20 11:29:44 2009
+++ D:/WorkBackup/My_Test_Project/libGCWinCE/libgc/source/misc.c    Aug 20 
11:19:27 2009
@@ -867,7 +867,7 @@
 
 
 #if defined(MSWIN32) || defined(MSWINCE)
-# if defined(_MSC_VER) && defined(_DEBUG)
+# if defined(_MSC_VER) && defined(_DEBUG) && !defined(MSWINCE)
 #  include <crtdbg.h>
 # endif
 
@@ -941,7 +941,15 @@
       if (!tmp)
          DebugBreak();
 #     if defined(_MSC_VER) && defined(_DEBUG)
-          _CrtDbgReport(_CRT_WARN, NULL, 0, NULL, "%.*s", len, buf);
+#              if defined(MSWINCE)
+                  {
+                          WCHAR temp[1024];
+                          MultiByteToWideChar(CP_ACP, 0, buf, len, temp, 
1024);
+                          OutputDebugString(temp);
+                  }      
+#              else
+                          _CrtDbgReport(_CRT_WARN, NULL, 0, NULL, "%.*s", 
len, buf);
+#              endif
 #     endif
       IF_NEED_TO_LOCK(LeaveCriticalSection(&GC_write_cs));
       return tmp ? (int)written : -1;
 
The compiling went through but i was notified by a link error as shown below:
2>Linking...
2>libgc_smt2005_d.lib(os_dep.obj) : error LNK2019: unresolved external symbol 
backtrace referenced in function GC_save_callers
2>libgc_smt2005_d.lib(os_dep.obj) : error LNK2019: unresolved external symbol 
backtrace_symbols referenced in function GC_print_callers
     So, I commented on the SAVE_CALL_CHAIN and SAVE_CALL_COUNT.
     It ran with run-time error:
     Last error code: 87
DuplicateHandle failed
I found DuplicateHandle function help in MSDN for WINCE 5.0: 
https://msdn.microsoft.com/en-us/library/ms885208.aspx
Below is its description by type.
------------------------MSDN------------------>
DuplicateHandle can duplicate handles only to the types of objects in the 
following table.
Handle	Description
Event	Returned by CreateEvent or OpenEvent.

Mutex	Returned by CreateMutex.

Semaphore	Returned by CreateSemaphore.
------------------------MSDN------------------>
         I see DuplicateHandle function in WinCE 5.0 could not duplicate 
handles returned by CreateTread.
         Could I change the code like this:
--- C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/win32_threads.-revBASE.svn001.tmp.c Aug 
20 13:11:16 2009
+++ D:/WorkBackup/My_Test_Project/libGCWinCE/libgc/source/win32_threads.c    
Aug 20 13:08:39 2009
@@ -416,16 +416,21 @@
 #   define GetCurrentThread() (HANDLE)-2L /* "thread_self" pseudohandle */
 # endif
                   
-  if (!DuplicateHandle(GetCurrentProcess(),
-                           GetCurrentThread(),
-                         GetCurrentProcess(),
-                         (HANDLE*)&(me -> handle),
-                         0,
-                         0,
-                         DUPLICATE_SAME_ACCESS)) {
-        GC_err_printf("Last error code: %d\n", (int)GetLastError());
-        ABORT("DuplicateHandle failed");
-  }
+#ifdef UNDER_CE
+       /* DuplicateHandle does not exist on WinCE */
+       me -> handle = GetCurrentThread();
+#else
+       if (!DuplicateHandle(GetCurrentProcess(),
+                GetCurrentThread(),
+                GetCurrentProcess(),
+                (HANDLE*)&(me -> handle),
+                0,
+                0,
+                DUPLICATE_SAME_ACCESS)) {
+                          GC_err_printf("Last error code: %d\n", (int)
GetLastError());
+                          ABORT("DuplicateHandle failed");
+       }
+#endif
   me -> last_stack_min = ADDR_LIMIT;
   me -> stack_base = sb -> mem_base;
 # ifdef IA64
Could you pls help review it? Great thanks in advance!
Warmest regards,
GC Beginner
Zeyi Lee





More information about the Gc mailing list