r3865 - in branches/beast-mingw: . birnet



Author: stw
Date: 2006-08-24 14:13:15 -0400 (Thu, 24 Aug 2006)
New Revision: 3865

Modified:
   branches/beast-mingw/ChangeLog.win32
   branches/beast-mingw/birnet/birnetcore.h
   branches/beast-mingw/birnet/birnetcpu.c
   branches/beast-mingw/birnet/birnetmsg.c
   branches/beast-mingw/birnet/birnetthread.c
   branches/beast-mingw/birnet/birnetutils.c
   branches/beast-mingw/birnet/birnetutils.h
   branches/beast-mingw/birnet/birnetutilsxx.cc
   branches/beast-mingw/birnet/configure.inc
Log:
Thu Aug 24 19:45:54 2006  Stefan Westerfeld  <stefan space twc de>

	* birnet/birnetcore.h: Provide fake definitions for those errno's that
	mingw doesn't have, but beast does use.

	* birnet/birnetthread.c: For now, allow beast to use uninitialized
	mutexes and conditions, by lazily intializing them, if they are not
	initialized. Set NO_LAZY_INIT global variable with gdb to disable
	lazy initialization and get G_BREAKPOINT()s instead.
	Replaced gettimeofday() with g_get_current_time(), although it is not
	clear that this was really necessary.
	Some nasty hacks to get it to compile (#if 0'd out very platform
	specific code).

	* birnet/birnetutilsxx.cc: lrand48() is not available.

	* birnet/birnetutils.c: Various types of special files don't exist
	in the filesystem (such as sockets or block devices). lrand48()
	is not available. And sizeof(wchar_t) is 2, not 4.

	* birnet/birnetmsg.c: Syslogging is not available on windows - at
	least the API looks differently.

	* birnet/birnetcpu.c: Disabled the ssesys check on windows (signals
	don't work like that here, so the check doesn't work), and assume that
	sse support is always present on windows.
	However, I don't know if really old versions of windows actually do
	have SSE support, so we might need to check the windows version here.

	* birnet/configure.inc: Allow user to specify zlib specific CFLAGS via
	LIBZ_CFLAGS environment variable.

	* birnet/birnetutils.h: "uint" is not always defined, but only when
	_BIRNET_SOURCE_EXTENSIONS is defined: so I removed it from the function
	prototype.


Modified: branches/beast-mingw/ChangeLog.win32
===================================================================
--- branches/beast-mingw/ChangeLog.win32	2006-08-24 16:40:32 UTC (rev 3864)
+++ branches/beast-mingw/ChangeLog.win32	2006-08-24 18:13:15 UTC (rev 3865)
@@ -1,3 +1,39 @@
+Thu Aug 24 19:45:54 2006  Stefan Westerfeld  <stefan space twc de>
+
+	* birnet/birnetcore.h: Provide fake definitions for those errno's that
+	mingw doesn't have, but beast does use.
+
+	* birnet/birnetthread.c: For now, allow beast to use uninitialized
+	mutexes and conditions, by lazily intializing them, if they are not
+	initialized. Set NO_LAZY_INIT global variable with gdb to disable
+	lazy initialization and get G_BREAKPOINT()s instead.
+	Replaced gettimeofday() with g_get_current_time(), although it is not
+	clear that this was really necessary.
+	Some nasty hacks to get it to compile (#if 0'd out very platform
+	specific code).
+
+	* birnet/birnetutilsxx.cc: lrand48() is not available.
+
+	* birnet/birnetutils.c: Various types of special files don't exist
+	in the filesystem (such as sockets or block devices). lrand48()
+	is not available. And sizeof(wchar_t) is 2, not 4.
+
+	* birnet/birnetmsg.c: Syslogging is not available on windows - at
+	least the API looks differently.
+
+	* birnet/birnetcpu.c: Disabled the ssesys check on windows (signals
+	don't work like that here, so the check doesn't work), and assume that
+	sse support is always present on windows.
+	However, I don't know if really old versions of windows actually do
+	have SSE support, so we might need to check the windows version here.
+
+	* birnet/configure.inc: Allow user to specify zlib specific CFLAGS via
+	LIBZ_CFLAGS environment variable.
+
+	* birnet/birnetutils.h: "uint" is not always defined, but only when
+	_BIRNET_SOURCE_EXTENSIONS is defined: so I removed it from the function
+	prototype.
+
 Thu Aug 24 18:38:14 2006  Stefan Westerfeld  <stefan space twc de>
 
 	* configure.in: The old configure.in generates the following line

Modified: branches/beast-mingw/birnet/birnetcore.h
===================================================================
--- branches/beast-mingw/birnet/birnetcore.h	2006-08-24 16:40:32 UTC (rev 3864)
+++ branches/beast-mingw/birnet/birnetcore.h	2006-08-24 18:13:15 UTC (rev 3865)
@@ -25,6 +25,13 @@
 #include <glib.h>
 #include <birnet/birnetconfig.h>
 
+#ifdef WIN32
+/* mingw doesn't have these errnos, but beast uses
+   them internally, to indicate internal error types */
+#define ELOOP 		1000
+#define ENODATA 	1001
+#endif
+
 BIRNET_EXTERN_C_BEGIN();
 
 /* --- standard macros --- */

Modified: branches/beast-mingw/birnet/birnetcpu.c
===================================================================
--- branches/beast-mingw/birnet/birnetcpu.c	2006-08-24 16:40:32 UTC (rev 3864)
+++ branches/beast-mingw/birnet/birnetcpu.c	2006-08-24 18:13:15 UTC (rev 3865)
@@ -193,6 +193,9 @@
   /* check system support for SSE */
   if (ci->x86_sse)
     {
+#ifdef WIN32 /* on windows: always */
+      ci->x86_ssesys = true;
+#else
       struct sigaction action, old_action;
       action.sa_handler = cpu_info_sigill_handler;
       sigemptyset (&action.sa_mask);
@@ -211,6 +214,7 @@
           // g_printerr ("caught SIGILL\n");
         }
       sigaction (SIGILL, &old_action, NULL);
+#endif
     }
 
   return true;

Modified: branches/beast-mingw/birnet/birnetmsg.c
===================================================================
--- branches/beast-mingw/birnet/birnetmsg.c	2006-08-24 16:40:32 UTC (rev 3864)
+++ branches/beast-mingw/birnet/birnetmsg.c	2006-08-24 18:13:15 UTC (rev 3865)
@@ -22,7 +22,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#if 0
 #include <syslog.h>
+#endif
 
 #ifndef _ // FIXME
 #define _(x) x
@@ -760,6 +762,8 @@
   /* log to syslog */
   if ((msg.primary || msg.secondary) && stdlog_syslog_priority && (actions & BIRNET_MSG_TO_STDLOG))
     {
+      g_error ("syslog logging not available under win32\n");
+#if 0
       char *prefix = log_prefix (NULL, 0, msg.log_domain, NULL, ident);
       if (msg.title && FALSE) // skip title in syslog
         syslog (stdlog_syslog_priority, "%s:0: %s\n", prefix, msg.title);
@@ -770,6 +774,7 @@
       if (msg.details && FALSE) // skip details in syslog
         syslog (stdlog_syslog_priority, "%s:3: %s\n", prefix, msg.details);
       g_free (prefix);
+#endif
     }
   /* log to stderr */
   bool tostderr = (actions & BIRNET_MSG_TO_STDERR) != 0;

Modified: branches/beast-mingw/birnet/birnetthread.c
===================================================================
--- branches/beast-mingw/birnet/birnetthread.c	2006-08-24 16:40:32 UTC (rev 3864)
+++ branches/beast-mingw/birnet/birnetthread.c	2006-08-24 18:13:15 UTC (rev 3865)
@@ -25,16 +25,13 @@
 #include "birnetthread.h"
 #include "birnetring.h"
 #include <sys/time.h>
-#include <sched.h>
 #include <unistd.h>     /* sched_yield() */
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 #include <errno.h>
 #include <string.h>
-#include <sys/resource.h>
 #include <sys/time.h>
-#include <sys/times.h>
 
 #define HAVE_GSLICE     (GLIB_MAJOR_VERSION >= 2 && GLIB_MINOR_VERSION >= 9)
 
@@ -61,7 +58,7 @@
   GData		        *qdata;
   /* accounting */
   struct {
-    struct timeval stamp;
+    GTimeVal       stamp;
     gint64         utime, stime;
     gint64         cutime, cstime;
   }                ac;
@@ -777,8 +774,8 @@
     birnet_cond_wait (cond, mutex);
   else if (max_useconds > 0)
     {
-      struct timeval now, limit;
-      gettimeofday (&now, NULL);
+      GTimeVal now, limit;
+      g_get_current_time (&now);
       BirnetInt64 secs = max_useconds / 1000000;
       limit.tv_sec = now.tv_sec + secs;
       max_useconds -= secs * 1000000;
@@ -827,7 +824,7 @@
 
 /* --- thread info --- */
 static inline unsigned long long int
-timeval_usecs (const struct timeval *tv)
+timeval_usecs (const GTimeVal *tv)
 {
   return tv->tv_usec + tv->tv_sec * (guint64) 1000000;
 }
@@ -904,11 +901,11 @@
 birnet_thread_accounting_L (BirnetThread *self,
                             bool          force_update)
 {
-  struct timeval stamp, ostamp = self->ac.stamp;
+  GTimeVal stamp, ostamp = self->ac.stamp;
   guint diff = 0;
   if (self->accounting)
     {
-      gettimeofday (&stamp, NULL);
+      g_get_current_time (&stamp);
       diff = timeval_usecs (&stamp) - timeval_usecs (&ostamp);
       diff = MAX (diff, 0);
     }
@@ -920,6 +917,7 @@
       gint64 old_cstime = self->ac.cstime;
       gdouble dfact = 1000000.0 / MAX (diff, 1);
       self->ac.stamp = stamp;
+#if 0
       if (0)
         {
           struct rusage res = { { 0 } };
@@ -930,8 +928,11 @@
           self->ac.cutime = timeval_usecs (&res.ru_utime);
           self->ac.cstime = timeval_usecs (&res.ru_stime);
         }
+#endif
       thread_info_from_stat_L (self, dfact);
+#if 0
       self->info.priority = getpriority (PRIO_PROCESS, self->tid);
+#endif
       self->info.utime = MAX (self->ac.utime - old_utime, 0) * dfact;
       self->info.stime = MAX (self->ac.stime - old_stime, 0) * dfact;
       self->info.cutime = MAX (self->ac.cutime - old_cutime, 0) * dfact;
@@ -944,11 +945,11 @@
 birnet_thread_info_collect (BirnetThread *thread)
 {
   BirnetThreadInfo *info = g_new0 (BirnetThreadInfo, 1);
-  struct timeval now;
+  GTimeVal now;
   gboolean recent = TRUE;
   if (!thread)
     thread = birnet_thread_self ();
-  gettimeofday (&now, NULL);
+  g_get_current_time (&now);
   birnet_mutex_lock (&global_thread_mutex);
   info->name = g_strdup (thread->name);
   info->aborted = thread->aborted;
@@ -1228,15 +1229,59 @@
   mutex->mutex_pointer = g_mutex_new ();
 }
 
+int NO_LAZY_INIT = 0;
+
+static void
+lazy_mutex_init (BirnetMutex *mutex)
+{
+  if (!mutex->mutex_pointer)
+    {
+      g_printerr ("lazy mutex init\n");
+      fallback_mutex_init (mutex);
+      if (NO_LAZY_INIT)
+	G_BREAKPOINT();
+    }
+}
+
+static void fallback_rec_mutex_init (BirnetRecMutex *rec_mutex);
+
+static void
+lazy_rec_mutex_init (BirnetRecMutex *rec_mutex)
+{
+  if (!rec_mutex->mutex.mutex_pointer)
+    {
+      g_printerr ("lazy rec_mutex init\n");
+      fallback_rec_mutex_init (rec_mutex);
+      if (NO_LAZY_INIT)
+	G_BREAKPOINT();
+    }
+}
+
+static void fallback_cond_init (BirnetCond *cond);
+
+static void
+lazy_cond_init (BirnetCond *cond)
+{
+  if (!cond->cond_pointer)
+    {
+      g_printerr ("lazy cond init\n");
+      fallback_cond_init (cond);
+      if (NO_LAZY_INIT)
+	G_BREAKPOINT();
+    }
+}
+
 static int
 fallback_mutex_trylock (BirnetMutex *mutex)
 {
+  lazy_mutex_init (mutex);
   return g_mutex_trylock (mutex->mutex_pointer) ? 0 : -1;
 }
 
 static void
 fallback_mutex_lock (BirnetMutex *mutex)
 {
+  lazy_mutex_init (mutex);
   static gboolean is_smp_system = FALSE; // FIXME
   
   /* spin locks should be held only very short times,
@@ -1270,12 +1315,14 @@
 static void
 fallback_mutex_unlock (BirnetMutex *mutex)
 {
+  lazy_mutex_init (mutex);
   g_mutex_unlock (mutex->mutex_pointer);
 }
 
 static void
 fallback_mutex_destroy (BirnetMutex *mutex)
 {
+  lazy_mutex_init (mutex);
   g_mutex_free (mutex->mutex_pointer);
   memset (mutex, 0, sizeof (*mutex));
 }
@@ -1291,6 +1338,7 @@
 static int
 fallback_rec_mutex_trylock (BirnetRecMutex *rec_mutex)
 {
+  lazy_rec_mutex_init (rec_mutex);
   BirnetThread *self = birnet_thread_self ();
   
   if (rec_mutex->owner == self)
@@ -1315,6 +1363,7 @@
 static void
 fallback_rec_mutex_lock (BirnetRecMutex *rec_mutex)
 {
+  lazy_rec_mutex_init (rec_mutex);
   BirnetThread *self = birnet_thread_self ();
   
   if (rec_mutex->owner == self)
@@ -1334,6 +1383,7 @@
 static void
 fallback_rec_mutex_unlock (BirnetRecMutex *rec_mutex)
 {
+  lazy_rec_mutex_init (rec_mutex);
   BirnetThread *self = birnet_thread_self ();
   
   if (rec_mutex->owner == self && rec_mutex->depth > 0)
@@ -1353,6 +1403,7 @@
 static void
 fallback_rec_mutex_destroy (BirnetRecMutex *rec_mutex)
 {
+  lazy_rec_mutex_init (rec_mutex);
   if (rec_mutex->owner || rec_mutex->depth)
     g_warning ("recursive mutex still locked during destruction");
   else
@@ -1373,24 +1424,29 @@
                     BirnetMutex *mutex)
 {
   /* infinite wait */
+  lazy_cond_init (cond);
+  lazy_mutex_init (mutex);
   g_cond_wait (cond->cond_pointer, mutex->mutex_pointer);
 }
 
 static void
 fallback_cond_signal (BirnetCond *cond)
 {
+  lazy_cond_init (cond);
   g_cond_signal (cond->cond_pointer);
 }
 
 static void
 fallback_cond_broadcast (BirnetCond *cond)
 {
+  lazy_cond_init (cond);
   g_cond_broadcast (cond->cond_pointer);
 }
 
 static void
 fallback_cond_destroy (BirnetCond *cond)
 {
+  lazy_cond_init (cond);
   g_cond_free (cond->cond_pointer);
 }
 
@@ -1407,6 +1463,7 @@
                           BirnetUInt64 abs_secs,
                           BirnetUInt64 abs_usecs)
 {
+  lazy_cond_init (cond);
   GTimeVal gtime;
   gtime.tv_sec = abs_secs;
   gtime.tv_usec = abs_usecs;

Modified: branches/beast-mingw/birnet/birnetutils.c
===================================================================
--- branches/beast-mingw/birnet/birnetutils.c	2006-08-24 16:40:32 UTC (rev 3864)
+++ branches/beast-mingw/birnet/birnetutils.c	2006-08-24 18:13:15 UTC (rev 3865)
@@ -135,7 +135,7 @@
   while (fd < 0)
     {
       g_free (tname);
-      tname = g_strdup_printf ("/tmp/Url%08X%04X.html", (int) lrand48(), getpid());
+      tname = g_strdup_printf ("/tmp/Url%08X%04X.html", (int) g_random_int(), getpid());
       fd = open (tname, O_WRONLY | O_CREAT | O_EXCL, 00600);
       if (fd < 0 && errno != EEXIST)
         {
@@ -278,10 +278,20 @@
 {
   BIRNET_STATIC_ASSERT (sizeof (*mem) == 4);
   BIRNET_STATIC_ASSERT (sizeof (filler) == 4);
+#ifdef WIN32
+  while (length--)
+    *mem++ = filler;
+#else
   BIRNET_STATIC_ASSERT (sizeof (wchar_t) == 4);
   wmemset ((wchar_t*) mem, filler, length);
+#endif
 }
 
+#ifdef WIN32
+#define S_ISLNK(x) false
+#define S_ISSOCK(x) false
+#endif
+
 /* --- file testing --- */
 static int
 errno_check_file (const char *file_name,
@@ -319,8 +329,11 @@
       
       if (check_link)
         {
+	  return -EINVAL;
+#if 0
           if (lstat (file_name, &st) < 0)
             return -errno;
+#endif
         }
       else if (stat (file_name, &st) < 0)
         return -errno;
@@ -346,14 +359,20 @@
         return -EINVAL;
       if (check_char && !S_ISCHR (st.st_mode))
         return -ENODEV;
+#if 0
       if (check_block && !S_ISBLK (st.st_mode))
         return -ENOTBLK;
+#endif
       if (check_pipe && !S_ISFIFO (st.st_mode))
         return -ENXIO;
+#if 0
       if (check_socket && !S_ISSOCK (st.st_mode))
         return -ENOTSOCK;
+#endif
+#if 0
       if (check_exec && !(st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
         return -EACCES; /* for root executable, any +x bit is good enough */
+#endif
     }
   
   return 0;

Modified: branches/beast-mingw/birnet/birnetutils.h
===================================================================
--- branches/beast-mingw/birnet/birnetutils.h	2006-08-24 16:40:32 UTC (rev 3864)
+++ branches/beast-mingw/birnet/birnetutils.h	2006-08-24 18:13:15 UTC (rev 3865)
@@ -33,7 +33,7 @@
 				       const char           *url_title,
 				       const char           *cookie);
 /* --- cleanup registration --- */
-uint birnet_cleanup_add               (uint                  timeout_ms,
+BirnetUInt birnet_cleanup_add               (BirnetUInt            timeout_ms,
 				       GDestroyNotify        handler,
 				       void                 *data);
 void birnet_cleanup_force_handlers    (void);

Modified: branches/beast-mingw/birnet/birnetutilsxx.cc
===================================================================
--- branches/beast-mingw/birnet/birnetutilsxx.cc	2006-08-24 16:40:32 UTC (rev 3864)
+++ branches/beast-mingw/birnet/birnetutilsxx.cc	2006-08-24 18:13:15 UTC (rev 3865)
@@ -80,10 +80,7 @@
 
   /* initialize random numbers */
   {
-    struct timeval tv;
-    gettimeofday (&tv, NULL);
-    srand48 (tv.tv_usec + (tv.tv_sec << 16));
-    srand (lrand48());
+    srand (g_random_int());
   }
 
   /* initialize sub systems */

Modified: branches/beast-mingw/birnet/configure.inc
===================================================================
--- branches/beast-mingw/birnet/configure.inc	2006-08-24 16:40:32 UTC (rev 3864)
+++ branches/beast-mingw/birnet/configure.inc	2006-08-24 18:13:15 UTC (rev 3865)
@@ -74,7 +74,7 @@
     dnl # libtool doesn't automatically figure that -pthread implies -lpthread
     BIRNET_LIBS=`echo " $BIRNET_GLIB_LIBS" | sed 's/\(-pthread\b\)/-lpthread \1/' `
     BIRNET_LIBS="$BIRNET_LIBS $LIBZ"
-    BIRNET_CFLAGS="$BIRNET_GLIB_CFLAGS"
+    BIRNET_CFLAGS="$BIRNET_GLIB_CFLAGS $LIBZ_CFLAGS"
 
     dnl # --- BIRNET_CFLAGS & BIRNET_LIBS ---
     AC_SUBST(BIRNET_CFLAGS)




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]