[svn] w32pth - r25 - trunk

svn author wk cvs at cvs.gnupg.org
Tue May 27 13:51:44 CEST 2008


Author: wk
Date: 2008-05-27 13:51:42 +0200 (Tue, 27 May 2008)
New Revision: 25

Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/libw32pth.def
   trunk/pth.h
   trunk/w32-io.c
   trunk/w32-io.h
   trunk/w32-pth.c
Log:
New funtion pth_thread_id.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-03-25 03:45:46 UTC (rev 24)
+++ trunk/ChangeLog	2008-05-27 11:51:42 UTC (rev 25)
@@ -1,3 +1,17 @@
+2008-05-27  Werner Koch  <wk at g10code.com>
+
+	* w32-pth.c (_pth_malloc, _pth_calloc, _pth_free): New.  Always
+	use these wrappers to be prepared to change the allocators. 
+
+2008-05-26  Werner Koch  <wk at g10code.com>
+
+	* w32-io.c (_pth_debug): Print tick, process and thread id.
+	* w32-pth.c (enter_pth, leave_pth): Use debug function.
+
+	* w32-pth.c (pth_thread_id): New.
+
+	* libw32pth.def (pth_thread_id): New.
+	
 2008-03-25  Marcus Brinkmann  <marcus at g10code.de>
 
 	* debug.h (DEBUG_INFO, DEBUG_CALLS): New macros.
@@ -53,6 +67,13 @@
 	about remaining issues.
 	(do_pth_event_body): Fix type in va_arg invocation.
 
+2007-11-20  Werner Koch  <wk at g10code.com>
+
+	* pth.h (PTH_EVENT_HANDLE): New.
+	* w32-pth.c (struct pth_event_s): Add HANDLE.
+	(do_pth_event_body, do_pth_wait): Implement handle event.
+	(do_pth_event_free): Do not close HD for a handle event.
+
 2007-08-16  Werner Koch  <wk at g10code.com>
 
 	Released 2.0.1.

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2008-03-25 03:45:46 UTC (rev 24)
+++ trunk/NEWS	2008-05-27 11:51:42 UTC (rev 25)
@@ -11,6 +11,9 @@
 
  * Bug fixes.
 
+ * New non-standard fucntion pth_thread_id.
+
+
 Noteworthy changes in version 2.0.1 (2007-08-16)
 ------------------------------------------------
 

Modified: trunk/libw32pth.def
===================================================================
--- trunk/libw32pth.def	2008-03-25 03:45:46 UTC (rev 24)
+++ trunk/libw32pth.def	2008-05-27 11:51:42 UTC (rev 25)
@@ -72,3 +72,4 @@
       pth_mutex_destroy @41
 
       pth_usleep @42
+      pth_thread_id @43

Modified: trunk/pth.h
===================================================================
--- trunk/pth.h	2008-03-25 03:45:46 UTC (rev 24)
+++ trunk/pth.h	2008-05-27 11:51:42 UTC (rev 25)
@@ -280,7 +280,12 @@
 int pth_yield (pth_t tid);
 
 
+/* Special W32 function to cope with the problem that pth_self returns
+   just a pseudo handle which is not very usefule for debugging.  */
+unsigned long pth_thread_id (void);
+#define PTH_HAVE_PTH_THREAD_ID 1
 
+
 /*-- pth_util.c --*/
 
 /* void sigemptyset (struct sigset_s * ss); */

Modified: trunk/w32-io.c
===================================================================
--- trunk/w32-io.c	2008-03-25 03:45:46 UTC (rev 24)
+++ trunk/w32-io.c	2008-05-27 11:51:42 UTC (rev 25)
@@ -103,7 +103,7 @@
         return;
     }
     /* now init it */
-    mp = malloc ( sizeof *mp );
+    mp = _pth_malloc ( sizeof *mp );
     if (!mp) {
         LeaveCriticalSection (&init_lock);
         sema_fatal ("out of core while creating critical section lock");
@@ -143,7 +143,7 @@
 {
     if (s && s->priv) {
         DeleteCriticalSection ((CRITICAL_SECTION*)s->priv);
-        free (s->priv);
+        _pth_free (s->priv);
         s->priv = NULL;
     }
 }
@@ -167,6 +167,10 @@
     
   va_start (arg_ptr, format);
   LOCK (debug_lock);
+  fprintf (dbgfp, "%05lu/%lu.%lu/libw32pth: ", 
+           ((unsigned long)GetTickCount () % 100000),
+           (unsigned long)GetCurrentProcessId (),
+           (unsigned long)GetCurrentThreadId ());
   vfprintf (dbgfp, format, arg_ptr);
   va_end (arg_ptr);
   if(format && *format && format[strlen (format) - 1] != '\n')
@@ -380,7 +384,7 @@
   sec_attr.nLength = sizeof sec_attr;
   sec_attr.bInheritHandle = FALSE;
   
-  ctx = calloc (1, sizeof *ctx);
+  ctx = _pth_calloc (1, sizeof *ctx);
   if (!ctx)
     {
       TRACE_SYSERR (errno);
@@ -403,7 +407,7 @@
 	CloseHandle (ctx->have_space_ev);
       if (ctx->stopped)
 	CloseHandle (ctx->stopped);
-      free (ctx);
+      _pth_free (ctx);
       /* FIXME: Translate the error code.  */
       TRACE_SYSERR (EIO);
       return NULL;
@@ -423,7 +427,7 @@
 	CloseHandle (ctx->have_space_ev);
       if (ctx->stopped)
 	CloseHandle (ctx->stopped);
-      free (ctx);
+      _pth_free (ctx);
       TRACE_SYSERR (EIO);
       return NULL;
     }    
@@ -469,7 +473,7 @@
     CloseHandle (ctx->have_space_ev);
   CloseHandle (ctx->thread_hd);
   DESTROY_LOCK (ctx->mutex);
-  free (ctx);
+  _pth_free (ctx);
 }
 
 
@@ -685,7 +689,7 @@
   sec_attr.nLength = sizeof sec_attr;
   sec_attr.bInheritHandle = FALSE;
 
-  ctx = calloc (1, sizeof *ctx);
+  ctx = _pth_calloc (1, sizeof *ctx);
   if (!ctx)
     {
       TRACE_SYSERR (errno);
@@ -708,7 +712,7 @@
 	CloseHandle (ctx->is_empty);
       if (ctx->stopped)
 	CloseHandle (ctx->stopped);
-      free (ctx);
+      _pth_free (ctx);
       /* FIXME: Translate the error code.  */
       TRACE_SYSERR (EIO);
       return NULL;
@@ -728,7 +732,7 @@
 	CloseHandle (ctx->is_empty);
       if (ctx->stopped)
 	CloseHandle (ctx->stopped);
-      free (ctx);
+      _pth_free (ctx);
       TRACE_SYSERR (EIO);
       return NULL;
     }    
@@ -773,7 +777,7 @@
     CloseHandle (ctx->is_empty);
   CloseHandle (ctx->thread_hd);
   DESTROY_LOCK (ctx->mutex);
-  free (ctx);
+  _pth_free (ctx);
 }
 
 

Modified: trunk/w32-io.h
===================================================================
--- trunk/w32-io.h	2008-03-25 03:45:46 UTC (rev 24)
+++ trunk/w32-io.h	2008-05-27 11:51:42 UTC (rev 25)
@@ -21,6 +21,13 @@
 #ifndef W32_IO_H
 #define W32_IO_H
 
+/* Actually in w32-pth.c */
+void *pth_malloc (size_t n);
+void *pth_calloc (size_t n, size_t m);
+void _pth_free (void *p);
+
+
+/* w32-io.c */
 void _pth_sema_subsystem_init (void);
 
 /* For select.  */
@@ -30,4 +37,5 @@
 int _pth_io_read (int fd, void *buffer, size_t count);
 int _pth_io_write (int fd, const void *buffer, size_t count);
 
+
 #endif	/* W32_IO_H */

Modified: trunk/w32-pth.c
===================================================================
--- trunk/w32-pth.c	2008-03-25 03:45:46 UTC (rev 24)
+++ trunk/w32-pth.c	2008-05-27 11:51:42 UTC (rev 25)
@@ -64,6 +64,7 @@
 /* States whether this module has been initialized.  */
 static int pth_initialized;
 
+/* Debug helpers.  */
 int debug_level;
 FILE *dbgfp;
 
@@ -154,6 +155,33 @@
   return "libw32pth";
 }
 
+
+/* Our own malloc function.  Eventually we will use HeapCreate to use
+   a private heap here.  */
+void *
+_pth_malloc (size_t n)
+{
+  void *p;
+  p = malloc (n);
+  return p;
+}
+
+void *
+_pth_calloc (size_t n, size_t m)
+{
+  void *p;
+  p = calloc (n, m);
+  return p;
+}
+
+void
+_pth_free (void *p)
+{
+  if (p)
+    free (p);
+}
+
+
 static char *
 w32_strerror (char *strerr, size_t strerrsize)
 {
@@ -409,7 +437,7 @@
           s1++;
           if (!(s2 = strchr (s1, ';')))
             s2 = s1 + strlen (s1);
-          p = malloc (s2 - s1 + 1);
+          p = _pth_malloc (s2 - s1 + 1);
           if (p)
             {
               memcpy (p, s1, s2-s1);
@@ -417,14 +445,14 @@
               dbgfp = fopen (p, "a");
               if (dbgfp)
                 setvbuf (dbgfp, NULL, _IOLBF, 0);
-              free (p);
+              _pth_free (p);
             }
         }
     }
   if (!dbgfp)
     dbgfp = stderr;
   if (debug_level)
-    fprintf (dbgfp, "%s: pth_init: called.\n", log_get_prefix (NULL));
+    _pth_debug (DEBUG_ERROR, "pth_init called\n");
 
   if (WSAStartup (0x202, &wsadat))
     return FALSE;
@@ -466,8 +494,7 @@
   /* Fixme: I am not sure whether the same thread my enter a critical
      section twice.  */
   if (DBG_CALLS)
-    fprintf (dbgfp, "%s: enter_pth (%s)\n",
-             log_get_prefix (NULL), function? function:"");
+    _pth_debug (DEBUG_CALLS, "enter_pth (%s)\n", function? function:"");
   LeaveCriticalSection (&pth_shd);
 }
 
@@ -477,8 +504,7 @@
 {
   EnterCriticalSection (&pth_shd);
   if (DBG_CALLS)
-    fprintf (dbgfp, "%s: leave_pth (%s)\n",
-             log_get_prefix (NULL), function? function:"");
+    _pth_debug (DEBUG_CALLS, "leave_pth (%s)\n", function? function:"");
 }
 
 
@@ -1096,7 +1122,7 @@
   pth_attr_t hd;
 
   implicit_init ();
-  hd = calloc (1, sizeof *hd);
+  hd = _pth_calloc (1, sizeof *hd);
   return hd;
 }
 
@@ -1108,8 +1134,8 @@
     return -1;
   implicit_init ();
   if (hd->name)
-    free (hd->name);
-  free (hd);
+    _pth_free (hd->name);
+  _pth_free (hd);
   return TRUE;
 }
 
@@ -1153,7 +1179,7 @@
     case PTH_ATTR_NAME:
       str = va_arg (args, char*);
       if (hd->name)
-        free (hd->name);
+        _pth_free (hd->name);
       if (str)
         {
           hd->name = strdup (str);
@@ -1191,7 +1217,7 @@
   sa.lpSecurityDescriptor = NULL;
   sa.nLength = sizeof sa;
 
-  ctx = calloc (1, sizeof *ctx);
+  ctx = _pth_calloc (1, sizeof *ctx);
   if (!ctx)
     return NULL;
   ctx->thread = func;
@@ -1217,7 +1243,7 @@
     fprintf (dbgfp, "%s: do_pth_spawn created thread %p\n",
              log_get_prefix (NULL),th);
   if (!th)
-    free (ctx);
+    _pth_free (ctx);
   else
     ResumeThread (th);
   
@@ -1246,6 +1272,16 @@
   return GetCurrentThread ();
 }
 
+
+/* Special W32 function to cope with the problem that pth_self returns
+   just a pseudo handle which is not very usefule for debugging.  */
+unsigned long 
+pth_thread_id (void)
+{
+  return GetCurrentThreadId ();
+}
+
+
 int
 pth_join (pth_t hd, void **value)
 {
@@ -1407,7 +1443,7 @@
   if (DBG_INFO)
     fprintf (dbgfp, "%s: pth_event spec=%lx\n", log_get_prefix (NULL), spec);
 
-  ev = calloc (1, sizeof *ev);
+  ev = _pth_calloc (1, sizeof *ev);
   if (!ev)
     return NULL;
   ev->next = ev;
@@ -1418,7 +1454,7 @@
     ev->hd = create_event ();
   if (!ev->hd)
     {
-      free (ev);
+      _pth_free (ev);
       return NULL;
     }
 
@@ -1582,7 +1618,7 @@
          deallocated handle. Don't use it directly but setup proper
          scheduling queues.  */
       enter_pth (__FUNCTION__);
-      free (c);
+      _pth_free (c);
     }
   ExitThread (0);
   return NULL;
@@ -1662,7 +1698,7 @@
           pth_event_t next = cur->next;
           CloseHandle (cur->hd);
           cur->hd = NULL;
-          free (cur);
+          _pth_free (cur);
           cur = next;
         }
       while (cur != ev);
@@ -1673,7 +1709,7 @@
       ev->next->prev = ev->prev;
       CloseHandle (ev->hd);
       ev->hd = NULL;	    
-      free (ev);
+      _pth_free (ev);
     }
   else
     return FALSE;




More information about the Gnupg-commits mailing list