1294 MutexLockerEx lock(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
1295 _next = _the_list._head;
1296 OrderAccess::release_store(&_the_list._head, this);
1297 }
1298
1299 void NonJavaThread::remove_from_the_list() {
1300 MutexLockerEx lock(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
1301 NonJavaThread* volatile* p = &_the_list._head;
1302 for (NonJavaThread* t = *p; t != NULL; p = &t->_next, t = *p) {
1303 if (t == this) {
1304 *p = this->_next;
1305 // Wait for any in-progress iterators. Concurrent synchronize is
1306 // not allowed, so do it while holding the list lock.
1307 _the_list._protect.synchronize();
1308 break;
1309 }
1310 }
1311 }
1312
1313 void NonJavaThread::pre_run() {
1314 assert(BarrierSet::barrier_set() != NULL, "invariant");
1315 add_to_the_list();
1316
1317 // This is slightly odd in that NamedThread is a subclass, but
1318 // in fact name() is defined in Thread
1319 assert(this->name() != NULL, "thread name was not set before it was started");
1320 this->set_native_thread_name(this->name());
1321 }
1322
1323 void NonJavaThread::post_run() {
1324 JFR_ONLY(Jfr::on_thread_exit(this);)
1325 remove_from_the_list();
1326 // Ensure thread-local-storage is cleared before termination.
1327 Thread::clear_thread_current();
1328 }
1329
1330 // NamedThread -- non-JavaThread subclasses with multiple
1331 // uniquely named instances should derive from this.
1332 NamedThread::NamedThread() :
1333 NonJavaThread(),
1334 _name(NULL),
1335 _processed_thread(NULL),
1336 _gc_id(GCId::undefined())
1337 {}
1338
1339 NamedThread::~NamedThread() {
1340 if (_name != NULL) {
1341 FREE_C_HEAP_ARRAY(char, _name);
1342 _name = NULL;
1343 }
1344 }
|
1294 MutexLockerEx lock(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
1295 _next = _the_list._head;
1296 OrderAccess::release_store(&_the_list._head, this);
1297 }
1298
1299 void NonJavaThread::remove_from_the_list() {
1300 MutexLockerEx lock(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
1301 NonJavaThread* volatile* p = &_the_list._head;
1302 for (NonJavaThread* t = *p; t != NULL; p = &t->_next, t = *p) {
1303 if (t == this) {
1304 *p = this->_next;
1305 // Wait for any in-progress iterators. Concurrent synchronize is
1306 // not allowed, so do it while holding the list lock.
1307 _the_list._protect.synchronize();
1308 break;
1309 }
1310 }
1311 }
1312
1313 void NonJavaThread::pre_run() {
1314 // Initialize BarrierSet-related data before adding to list.
1315 assert(BarrierSet::barrier_set() != NULL, "invariant");
1316 BarrierSet::barrier_set()->on_thread_attach(this);
1317 add_to_the_list();
1318
1319 // This is slightly odd in that NamedThread is a subclass, but
1320 // in fact name() is defined in Thread
1321 assert(this->name() != NULL, "thread name was not set before it was started");
1322 this->set_native_thread_name(this->name());
1323 }
1324
1325 void NonJavaThread::post_run() {
1326 JFR_ONLY(Jfr::on_thread_exit(this);)
1327 // Clean up BarrierSet data before removing from list.
1328 BarrierSet::barrier_set()->on_thread_detach(this);
1329 remove_from_the_list();
1330 // Ensure thread-local-storage is cleared before termination.
1331 Thread::clear_thread_current();
1332 }
1333
1334 // NamedThread -- non-JavaThread subclasses with multiple
1335 // uniquely named instances should derive from this.
1336 NamedThread::NamedThread() :
1337 NonJavaThread(),
1338 _name(NULL),
1339 _processed_thread(NULL),
1340 _gc_id(GCId::undefined())
1341 {}
1342
1343 NamedThread::~NamedThread() {
1344 if (_name != NULL) {
1345 FREE_C_HEAP_ARRAY(char, _name);
1346 _name = NULL;
1347 }
1348 }
|