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
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.
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.
37 gnu::gcj::runtime::FinalizerThread::finalizerReady ()
39 #ifdef __JV_NO_THREADS__
42 _Jv_MutexLock (&mutex);
43 finalizer_ready = true;
44 _Jv_CondNotify (&condition, &mutex);
45 _Jv_MutexUnlock (&mutex);
49 // Main loop for the finalizer thread.
51 gnu::gcj::runtime::FinalizerThread::run ()
55 _Jv_MutexLock (&mutex);
56 if (! finalizer_ready)
57 _Jv_CondWait (&condition, &mutex, 0, 0);
58 finalizer_ready = false;
59 _Jv_MutexUnlock (&mutex);