This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: rename _Jv_gettimeofday


I'm checking this in.

I've renamed _Jv_gettimeofday to _Jv_platform_gettimeofday.
I've also added a platform initialization call and changed prims.cc to
use it.

I think we should adopt this naming convention for the platform API.
And, as much as possible we should avoid things like `#if WIN32' in
the code.

There are still a couple uses of WIN32 in natSystem.cc and
natRuntime.cc.  These could easily be replaced.

Adam, does win32.cc really compile?
It references java classes but doesn't include cni.h or anything like
that.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* prims.cc (_Jv_CreateJavaVM): Call _Jv_platform_initialize.
	* win32.cc (win32_exception_handler): Now static.
	* include/win32.h (_Jv_platform_initialize): Declare.
	(win32_exception_handler): Don't declare.
	* java/lang/natSystem.cc (currentTimeMillis): Use
	_Jv_platform_gettimeofday.
	* posix.cc (_Jv_platform_gettimeofday): Renamed.
	(_Jv_select): Use new name.
	(_Jv_platform_initialize): New function.
	* include/posix.h (_Jv_platform_gettimeofday): Renamed from
	_Jv_gettimeofday.
	(_Jv_platform_initialize): Declare.

Index: posix.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/posix.cc,v
retrieving revision 1.2
diff -u -r1.2 posix.cc
--- posix.cc 2001/02/13 18:44:51 1.2
+++ posix.cc 2002/02/07 18:58:34
@@ -1,6 +1,6 @@
 // posix.cc -- Helper functions for POSIX-flavored OSs.
 
-/* Copyright (C) 2000, 2001  Free Software Foundation
+/* Copyright (C) 2000, 2001, 2002  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -13,6 +13,7 @@
 #include "posix.h"
 
 #include <errno.h>
+#include <signal.h>
 
 #include <jvm.h>
 #include <java/lang/Thread.h>
@@ -24,7 +25,7 @@
 
 // gettimeofday implementation.
 void
-_Jv_gettimeofday (struct timeval *tv)
+_Jv_platform_gettimeofday (struct timeval *tv)
 {
 #if defined (HAVE_GETTIMEOFDAY)
   gettimeofday (tv, NULL);
@@ -47,6 +48,22 @@
 #endif
 }
 
+// Platform-specific VM initialization.
+void
+_Jv_platform_initialize (void)
+{
+#if defined (HAVE_SIGACTION)
+  // We only want this on POSIX systems.
+  struct sigaction act;
+  act.sa_handler = SIG_IGN;
+  sigemptyset (&act.sa_mask);
+  act.sa_flags = 0;
+  sigaction (SIGPIPE, &act, NULL);
+#else
+  signal (SIGPIPE, SIG_IGN);
+#endif
+}
+
 // A wrapper for select() which ignores EINTR.
 int
 _Jv_select (int n, fd_set *readfds, fd_set  *writefds,
@@ -57,7 +74,7 @@
   struct timeval end, delay;
   if (timeout)
     {
-      _Jv_gettimeofday (&end);
+      _Jv_platform_gettimeofday (&end);
       end.tv_usec += timeout->tv_usec;
       if (end.tv_usec >= 1000000)
 	{
@@ -87,7 +104,7 @@
       struct timeval after;
       if (timeout)
 	{
-	  _Jv_gettimeofday (&after);
+	  _Jv_platform_gettimeofday (&after);
 	  // Now compute new timeout argument.
 	  delay.tv_usec = end.tv_usec - after.tv_usec;
 	  delay.tv_sec = end.tv_sec - after.tv_sec;
Index: prims.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/prims.cc,v
retrieving revision 1.70
diff -u -r1.70 prims.cc
--- prims.cc 2002/02/07 05:26:40 1.70
+++ prims.cc 2002/02/07 18:58:35
@@ -1,6 +1,6 @@
 // prims.cc - Code for core of runtime environment.
 
-/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -928,23 +928,7 @@
   LTDL_SET_PRELOADED_SYMBOLS ();
 #endif
 
-#ifdef WIN32
-  // Initialise winsock for networking
-  WSADATA data;
-  if (WSAStartup (MAKEWORD (1, 1), &data))
-      MessageBox (NULL, "Error initialising winsock library.", "Error", MB_OK | MB_ICONEXCLAMATION);
-  // Install exception handler
-  SetUnhandledExceptionFilter (win32_exception_handler);
-#elif defined(HAVE_SIGACTION)
-  // We only want this on POSIX systems.
-  struct sigaction act;
-  act.sa_handler = SIG_IGN;
-  sigemptyset (&act.sa_mask);
-  act.sa_flags = 0;
-  sigaction (SIGPIPE, &act, NULL);
-#else
-  signal (SIGPIPE, SIG_IGN);
-#endif
+  _Jv_platform_initialize ();
 
   _Jv_JNI_Init ();
 
Index: win32.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/win32.cc,v
retrieving revision 1.1
diff -u -r1.1 win32.cc
--- win32.cc 2002/02/07 05:26:41 1.1
+++ win32.cc 2002/02/07 18:58:35
@@ -9,9 +9,10 @@
 details.  */
 
 #include <config.h>
-#include <windows.h>
 
-LONG CALLBACK
+#include "platform.h"
+
+static LONG CALLBACK
 win32_exception_handler (LPEXCEPTION_POINTERS e)
 {
   if (e->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
@@ -20,4 +21,17 @@
     throw new java::lang::ArithmeticException;
   else
     return EXCEPTION_CONTINUE_SEARCH;
+}
+
+// Platform-specific VM initialization.
+void
+_Jv_platform_initialize (void)
+{
+  // Initialise winsock for networking
+  WSADATA data;
+  if (WSAStartup (MAKEWORD (1, 1), &data))
+    MessageBox (NULL, "Error initialising winsock library.", "Error",
+		MB_OK | MB_ICONEXCLAMATION);
+  // Install exception handler
+  SetUnhandledExceptionFilter (win32_exception_handler);
 }
Index: include/posix.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/posix.h,v
retrieving revision 1.2
diff -u -r1.2 posix.h
--- include/posix.h 2001/08/01 17:53:00 1.2
+++ include/posix.h 2002/02/07 18:58:36
@@ -1,6 +1,6 @@
 // posix.h -- Helper functions for POSIX-flavored OSs.
 
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2002  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -29,4 +29,5 @@
 #endif
 
 extern int _Jv_select (int n, fd_set *, fd_set *, fd_set *, struct timeval *);
-extern void _Jv_gettimeofday (struct timeval *);
+extern void _Jv_platform_gettimeofday (struct timeval *);
+extern void _Jv_platform_initialize (void);
Index: include/win32.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/win32.h,v
retrieving revision 1.1
diff -u -r1.1 win32.h
--- include/win32.h 2002/02/07 05:26:42 1.1
+++ include/win32.h 2002/02/07 18:58:36
@@ -17,6 +17,6 @@
 #undef __INSIDE_CYGWIN__
 #include <winsock.h>
 
-LONG CALLBACK win32_exception_handler (LPEXCEPTION_POINTERS e);
+extern void _Jv_platform_initialize (void);
 
 #endif /* __JV_WIN32_H__ */
Index: java/lang/natSystem.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natSystem.cc,v
retrieving revision 1.46
diff -u -r1.46 natSystem.cc
--- java/lang/natSystem.cc 2002/02/07 03:24:03 1.46
+++ java/lang/natSystem.cc 2002/02/07 18:58:37
@@ -159,7 +159,7 @@
 java::lang::System::currentTimeMillis (void)
 {
   struct timeval tv;
-  _Jv_gettimeofday (&tv);
+  _Jv_platform_gettimeofday (&tv);
   return (jlong) tv.tv_sec * 1000 + tv.tv_usec / 1000;
 }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]