* Removed all Id tags.
[cacao.git] / src / toolbox / logging.c
index 9aa257c3325aded56b266018d9093d19f471a37d..de04b1e573aee75d7623e6fe8254701a5b1c4cb8 100644 (file)
@@ -1,6 +1,6 @@
 /* src/toolbox/logging.c - contains logging functions
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
    J. Wenninger, Institut f. Computersprachen - TU Wien
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Reinhard Grafl
-
-   Changes: Christian Thalinger
-
-   $Id: logging.c 4885 2006-05-05 19:21:42Z edwin $
-
 */
 
 
+#include "config.h"
+
 #include <stdio.h>
-#include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include "config.h"
 #include "vm/types.h"
 
 #include "mm/memory.h"
 #include "toolbox/logging.h"
 #include "toolbox/util.h"
 #include "vm/global.h"
-#include "vm/statistics.h"
 
-#if defined(USE_THREADS)
-# if defined(NATIVE_THREADS)
-#  include "threads/native/threads.h"
-# endif
+#if defined(ENABLE_STATISTICS)
+# include "vmcore/statistics.h"
 #endif
 
 
@@ -78,16 +67,41 @@ void log_init(const char *fname)
 
 *******************************************************************************/
 
+/* ATTENTION: Don't include threads-common.h, because we can't
+   bootstrap this file in that case (missing java_lang_Thread.h).
+   Instead we declare threads_get_current_threadobject differently: */
+
+/* #if defined(ENABLE_THREADS) */
+/* # include "threads/threads-common.h" */
+/* #endif */
+
+extern ptrint threads_get_current_tid(void);
+
+
 void log_start(void)
 {
-       if (logfile) {
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-               fprintf(logfile, "[%p] ", (void *) THREADOBJECT);
+#if defined(ENABLE_THREADS)
+       ptrint tid;
+
+       tid = threads_get_current_tid();
 #endif
 
-       } else {
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-               fprintf(stdout, "LOG: [%p] ", (void *) THREADOBJECT);
+       if (logfile) {
+#if defined(ENABLE_THREADS)
+# if SIZEOF_VOID_P == 8
+               fprintf(logfile, "[0x%016lx] ", tid );
+# else
+               fprintf(logfile, "[0x%08x] ", tid);
+# endif
+#endif
+       }
+       else {
+#if defined(ENABLE_THREADS)
+# if SIZEOF_VOID_P == 8
+               fprintf(stdout, "LOG: [0x%016lx] ", tid);
+# else
+               fprintf(stdout, "LOG: [0x%08x] ", tid);
+# endif
 #else
                fputs("LOG: ", stdout);
 #endif
@@ -101,7 +115,7 @@ void log_start(void)
 
 *******************************************************************************/
 
-static void log_vprint(const char *text, va_list ap)
+void log_vprint(const char *text, va_list ap)
 {
        if (logfile)
                vfprintf(logfile, text, ap);
@@ -156,11 +170,11 @@ void log_println(const char *text, ...)
 void log_finish(void)
 {
        if (logfile) {
+               fputs("\n", logfile);
                fflush(logfile);
-
-       else {
+       }
+       else {
                fputs("\n", stdout);
-
                fflush(stdout);
        }
 }
@@ -278,4 +292,5 @@ void log_message_method(const char *msg, methodinfo *m)
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */