Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: runtime/vm/thread_test.cc

Issue 1439483003: - Add an OSThread structure which is the generic TLS structure for all C++ (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address-comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/isolate.h" 6 #include "vm/isolate.h"
7 #include "vm/lockers.h" 7 #include "vm/lockers.h"
8 #include "vm/unit_test.h" 8 #include "vm/unit_test.h"
9 #include "vm/profiler.h" 9 #include "vm/profiler.h"
10 #include "vm/thread_pool.h" 10 #include "vm/thread_pool.h"
(...skipping 20 matching lines...) Expand all
31 // purpose. 31 // purpose.
32 Dart_ShutdownIsolate(); 32 Dart_ShutdownIsolate();
33 delete mutex; 33 delete mutex;
34 } 34 }
35 35
36 36
37 UNIT_TEST_CASE(Monitor) { 37 UNIT_TEST_CASE(Monitor) {
38 // This unit test case needs a running isolate. 38 // This unit test case needs a running isolate.
39 Dart_CreateIsolate( 39 Dart_CreateIsolate(
40 NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL, NULL); 40 NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL, NULL);
41 Thread* thread = Thread::Current(); 41 OSThread* thread = OSThread::Current();
42 // Thread interrupter interferes with this test, disable interrupts. 42 // Thread interrupter interferes with this test, disable interrupts.
43 thread->DisableThreadInterrupts(); 43 thread->DisableThreadInterrupts();
44 Monitor* monitor = new Monitor(); 44 Monitor* monitor = new Monitor();
45 monitor->Enter(); 45 monitor->Enter();
46 monitor->Exit(); 46 monitor->Exit();
47 47
48 const int kNumAttempts = 5; 48 const int kNumAttempts = 5;
49 int attempts = 0; 49 int attempts = 0;
50 while (attempts < kNumAttempts) { 50 while (attempts < kNumAttempts) {
51 MonitorLocker ml(monitor); 51 MonitorLocker ml(monitor);
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 } 403 }
404 } 404 }
405 } 405 }
406 406
407 407
408 TEST_CASE(ThreadIterator_Count) { 408 TEST_CASE(ThreadIterator_Count) {
409 intptr_t thread_count_0 = 0; 409 intptr_t thread_count_0 = 0;
410 intptr_t thread_count_1 = 0; 410 intptr_t thread_count_1 = 0;
411 411
412 { 412 {
413 ThreadIterator ti; 413 OSThreadIterator ti;
414 while (ti.HasNext()) { 414 while (ti.HasNext()) {
415 Thread* thread = ti.Next(); 415 OSThread* thread = ti.Next();
416 EXPECT(thread != NULL); 416 EXPECT(thread != NULL);
417 thread_count_0++; 417 thread_count_0++;
418 } 418 }
419 } 419 }
420 420
421 { 421 {
422 ThreadIterator ti; 422 OSThreadIterator ti;
423 while (ti.HasNext()) { 423 while (ti.HasNext()) {
424 Thread* thread = ti.Next(); 424 OSThread* thread = ti.Next();
425 EXPECT(thread != NULL); 425 EXPECT(thread != NULL);
426 thread_count_1++; 426 thread_count_1++;
427 } 427 }
428 } 428 }
429 429
430 EXPECT(thread_count_0 > 0); 430 EXPECT(thread_count_0 > 0);
431 EXPECT(thread_count_1 > 0); 431 EXPECT(thread_count_1 > 0);
432 EXPECT(thread_count_0 >= thread_count_1); 432 EXPECT(thread_count_0 >= thread_count_1);
433 } 433 }
434 434
435 435
436 TEST_CASE(ThreadIterator_FindSelf) { 436 TEST_CASE(ThreadIterator_FindSelf) {
437 Thread* current = Thread::Current(); 437 OSThread* current = OSThread::Current();
438 EXPECT(Thread::IsThreadInList(current->join_id())); 438 EXPECT(OSThread::IsThreadInList(current->join_id()));
439 } 439 }
440 440
441 441
442 struct ThreadIteratorTestParams { 442 struct ThreadIteratorTestParams {
443 ThreadId spawned_thread_join_id; 443 ThreadId spawned_thread_join_id;
444 Monitor* monitor; 444 Monitor* monitor;
445 }; 445 };
446 446
447 447
448 void ThreadIteratorTestMain(uword parameter) { 448 void ThreadIteratorTestMain(uword parameter) {
449 Thread::EnsureInit();
450 ThreadIteratorTestParams* params = 449 ThreadIteratorTestParams* params =
451 reinterpret_cast<ThreadIteratorTestParams*>(parameter); 450 reinterpret_cast<ThreadIteratorTestParams*>(parameter);
452 Thread* thread = Thread::Current(); 451 OSThread* thread = OSThread::Current();
453 EXPECT(thread != NULL); 452 EXPECT(thread != NULL);
454 453
455 MonitorLocker ml(params->monitor); 454 MonitorLocker ml(params->monitor);
456 params->spawned_thread_join_id = thread->join_id(); 455 params->spawned_thread_join_id = thread->join_id();
457 EXPECT(params->spawned_thread_join_id != OSThread::kInvalidThreadJoinId); 456 EXPECT(params->spawned_thread_join_id != OSThread::kInvalidThreadJoinId);
458 EXPECT(Thread::IsThreadInList(thread->join_id())); 457 EXPECT(OSThread::IsThreadInList(thread->join_id()));
459 ml.Notify(); 458 ml.Notify();
460 } 459 }
461 460
462 461
463 // NOTE: This test case also verifies that known TLS destructors are called 462 // NOTE: This test case also verifies that known TLS destructors are called
464 // on Windows. See |OnDartThreadExit| in os_thread_win.cc for more details. 463 // on Windows. See |OnDartThreadExit| in os_thread_win.cc for more details.
465 TEST_CASE(ThreadIterator_AddFindRemove) { 464 TEST_CASE(ThreadIterator_AddFindRemove) {
466 ThreadIteratorTestParams params; 465 ThreadIteratorTestParams params;
467 params.spawned_thread_join_id = OSThread::kInvalidThreadJoinId; 466 params.spawned_thread_join_id = OSThread::kInvalidThreadJoinId;
468 params.monitor = new Monitor(); 467 params.monitor = new Monitor();
469 468
470 { 469 {
471 MonitorLocker ml(params.monitor); 470 MonitorLocker ml(params.monitor);
472 EXPECT(params.spawned_thread_join_id == OSThread::kInvalidThreadJoinId); 471 EXPECT(params.spawned_thread_join_id == OSThread::kInvalidThreadJoinId);
473 // Spawn thread and wait to receive the thread join id. 472 // Spawn thread and wait to receive the thread join id.
474 OSThread::Start(ThreadIteratorTestMain, reinterpret_cast<uword>(&params)); 473 OSThread::Start("ThreadIteratorTest",
474 ThreadIteratorTestMain,
475 reinterpret_cast<uword>(&params));
475 while (params.spawned_thread_join_id == OSThread::kInvalidThreadJoinId) { 476 while (params.spawned_thread_join_id == OSThread::kInvalidThreadJoinId) {
476 ml.Wait(); 477 ml.Wait();
477 } 478 }
478 EXPECT(params.spawned_thread_join_id != OSThread::kInvalidThreadJoinId); 479 EXPECT(params.spawned_thread_join_id != OSThread::kInvalidThreadJoinId);
479 // Join thread. 480 // Join thread.
480 OSThread::Join(params.spawned_thread_join_id); 481 OSThread::Join(params.spawned_thread_join_id);
481 } 482 }
482 483
483 EXPECT(!Thread::IsThreadInList(params.spawned_thread_join_id)) 484 EXPECT(!OSThread::IsThreadInList(params.spawned_thread_join_id))
484 485
485 delete params.monitor; 486 delete params.monitor;
486 } 487 }
487 488
488 489
489 // Test rendezvous of: 490 // Test rendezvous of:
490 // - helpers in VM code, and 491 // - helpers in VM code, and
491 // - main thread in VM code, 492 // - main thread in VM code,
492 // organized by 493 // organized by
493 // - main thread, and 494 // - main thread, and
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 isolate->thread_registry()->CheckSafepoint(); 580 isolate->thread_registry()->CheckSafepoint();
580 MonitorLocker ml(&done_monitor); 581 MonitorLocker ml(&done_monitor);
581 if (done) { 582 if (done) {
582 break; 583 break;
583 } 584 }
584 } 585 }
585 } 586 }
586 } 587 }
587 588
588 } // namespace dart 589 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698