Dead
[official-gcc.git] / gomp-20050608-branch / libjava / gnu / gcj / runtime / natFinalizerThread.cc
blobec1846baf6acd2c377dad2e0a3867b24fa93d776
1 // natFinalizerThread.cc - Implementation of FinalizerThread native methods.
3 /* Copyright (C) 2001, 2004 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
11 #include <config.h>
13 #include <gcj/cni.h>
14 #include <jvm.h>
16 #include <gnu/gcj/runtime/FinalizerThread.h>
18 #include <java-threads.h>
20 static _Jv_Mutex_t mutex;
21 static _Jv_ConditionVariable_t condition;
23 // Initialize lock & condition variable.
24 void
25 gnu::gcj::runtime::FinalizerThread::init ()
27 _Jv_MutexInit (&mutex);
28 _Jv_CondInit (&condition);
31 // This is called by the GC when a finalizer is ready to be
32 // run. It sets a flag and wakes up the finalizer thread. Note
33 // that this MUST NOT aquire any Java lock, as this could result in
34 // the hash synchronization code being re-entered: the synchronization
35 // code itself might need to allocate. See PR 16478.
36 void
37 gnu::gcj::runtime::FinalizerThread::finalizerReady ()
39 #ifdef __JV_NO_THREADS__
40 _Jv_RunFinalizers ();
41 #else
42 _Jv_MutexLock (&mutex);
43 finalizer_ready = true;
44 _Jv_CondNotify (&condition, &mutex);
45 _Jv_MutexUnlock (&mutex);
46 #endif
49 // Main loop for the finalizer thread.
50 void
51 gnu::gcj::runtime::FinalizerThread::run ()
53 while (true)
55 _Jv_MutexLock (&mutex);
56 if (! finalizer_ready)
57 _Jv_CondWait (&condition, &mutex, 0, 0);
58 finalizer_ready = false;
59 _Jv_MutexUnlock (&mutex);
60 _Jv_RunFinalizers ();