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

Side by Side Diff: src/v8threads.cc

Issue 11970009: Make the Isolate parameter mandatory in Locker and Unlocker classes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased. Added TODO. Created 7 years, 11 months 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 | Annotate | Revision Log
« no previous file with comments | « src/isolate.cc ('k') | test/cctest/cctest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 24 matching lines...) Expand all
35 #include "regexp-stack.h" 35 #include "regexp-stack.h"
36 36
37 namespace v8 { 37 namespace v8 {
38 38
39 39
40 // Track whether this V8 instance has ever called v8::Locker. This allows the 40 // Track whether this V8 instance has ever called v8::Locker. This allows the
41 // API code to verify that the lock is always held when V8 is being entered. 41 // API code to verify that the lock is always held when V8 is being entered.
42 bool Locker::active_ = false; 42 bool Locker::active_ = false;
43 43
44 44
45 // Constructor for the Locker object. Once the Locker is constructed the 45 Locker::Locker() {
46 // current thread will be guaranteed to have the lock for a given isolate. 46 Initialize(i::Isolate::GetDefaultIsolateForLocking());
47 Locker::Locker(v8::Isolate* isolate) 47 }
48 : has_lock_(false), 48
49 top_level_(true), 49
50 isolate_(reinterpret_cast<i::Isolate*>(isolate)) { 50 // Once the Locker is initialized, the current thread will be guaranteed to have
51 if (isolate_ == NULL) { 51 // the lock for a given isolate.
52 isolate_ = i::Isolate::GetDefaultIsolateForLocking(); 52 void Locker::Initialize(v8::Isolate* isolate) {
53 } 53 ASSERT(isolate != NULL);
54 has_lock_= false;
55 top_level_ = true;
56 isolate_ = reinterpret_cast<i::Isolate*>(isolate);
54 // Record that the Locker has been used at least once. 57 // Record that the Locker has been used at least once.
55 active_ = true; 58 active_ = true;
56 // Get the big lock if necessary. 59 // Get the big lock if necessary.
57 if (!isolate_->thread_manager()->IsLockedByCurrentThread()) { 60 if (!isolate_->thread_manager()->IsLockedByCurrentThread()) {
58 isolate_->thread_manager()->Lock(); 61 isolate_->thread_manager()->Lock();
59 has_lock_ = true; 62 has_lock_ = true;
60 63
61 // Make sure that V8 is initialized. Archiving of threads interferes 64 // Make sure that V8 is initialized. Archiving of threads interferes
62 // with deserialization by adding additional root pointers, so we must 65 // with deserialization by adding additional root pointers, so we must
63 // initialize here, before anyone can call ~Locker() or Unlocker(). 66 // initialize here, before anyone can call ~Locker() or Unlocker().
(...skipping 15 matching lines...) Expand all
79 if (isolate_->IsDefaultIsolate()) { 82 if (isolate_->IsDefaultIsolate()) {
80 // This only enters if not yet entered. 83 // This only enters if not yet entered.
81 internal::Isolate::EnterDefaultIsolate(); 84 internal::Isolate::EnterDefaultIsolate();
82 } 85 }
83 } 86 }
84 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); 87 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread());
85 } 88 }
86 89
87 90
88 bool Locker::IsLocked(v8::Isolate* isolate) { 91 bool Locker::IsLocked(v8::Isolate* isolate) {
92 ASSERT(isolate != NULL);
89 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); 93 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
90 if (internal_isolate == NULL) {
91 internal_isolate = i::Isolate::GetDefaultIsolateForLocking();
92 }
93 return internal_isolate->thread_manager()->IsLockedByCurrentThread(); 94 return internal_isolate->thread_manager()->IsLockedByCurrentThread();
94 } 95 }
95 96
96 97
97 bool Locker::IsActive() { 98 bool Locker::IsActive() {
98 return active_; 99 return active_;
99 } 100 }
100 101
101 102
102 Locker::~Locker() { 103 Locker::~Locker() {
103 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); 104 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread());
104 if (has_lock_) { 105 if (has_lock_) {
105 if (isolate_->IsDefaultIsolate()) { 106 if (isolate_->IsDefaultIsolate()) {
106 isolate_->Exit(); 107 isolate_->Exit();
107 } 108 }
108 if (top_level_) { 109 if (top_level_) {
109 isolate_->thread_manager()->FreeThreadResources(); 110 isolate_->thread_manager()->FreeThreadResources();
110 } else { 111 } else {
111 isolate_->thread_manager()->ArchiveThread(); 112 isolate_->thread_manager()->ArchiveThread();
112 } 113 }
113 isolate_->thread_manager()->Unlock(); 114 isolate_->thread_manager()->Unlock();
114 } 115 }
115 } 116 }
116 117
117 118
118 Unlocker::Unlocker(v8::Isolate* isolate) 119 Unlocker::Unlocker() {
119 : isolate_(reinterpret_cast<i::Isolate*>(isolate)) { 120 Initialize(i::Isolate::GetDefaultIsolateForLocking());
120 if (isolate_ == NULL) { 121 }
121 isolate_ = i::Isolate::GetDefaultIsolateForLocking(); 122
122 } 123
124 void Unlocker::Initialize(v8::Isolate* isolate) {
125 ASSERT(isolate != NULL);
126 isolate_ = reinterpret_cast<i::Isolate*>(isolate);
123 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread()); 127 ASSERT(isolate_->thread_manager()->IsLockedByCurrentThread());
124 if (isolate_->IsDefaultIsolate()) { 128 if (isolate_->IsDefaultIsolate()) {
125 isolate_->Exit(); 129 isolate_->Exit();
126 } 130 }
127 isolate_->thread_manager()->ArchiveThread(); 131 isolate_->thread_manager()->ArchiveThread();
128 isolate_->thread_manager()->Unlock(); 132 isolate_->thread_manager()->Unlock();
129 } 133 }
130 134
131 135
132 Unlocker::~Unlocker() { 136 Unlocker::~Unlocker() {
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 void ContextSwitcher::Run() { 476 void ContextSwitcher::Run() {
473 while (keep_going_) { 477 while (keep_going_) {
474 OS::Sleep(sleep_ms_); 478 OS::Sleep(sleep_ms_);
475 isolate()->stack_guard()->Preempt(); 479 isolate()->stack_guard()->Preempt();
476 } 480 }
477 } 481 }
478 482
479 483
480 // Acknowledge the preemption by the receiving thread. 484 // Acknowledge the preemption by the receiving thread.
481 void ContextSwitcher::PreemptionReceived() { 485 void ContextSwitcher::PreemptionReceived() {
482 ASSERT(Locker::IsLocked()); 486 ASSERT(Locker::IsLocked(i::Isolate::GetDefaultIsolateForLocking()));
483 // There is currently no accounting being done for this. But could be in the 487 // There is currently no accounting being done for this. But could be in the
484 // future, which is why we leave this in. 488 // future, which is why we leave this in.
485 } 489 }
486 490
487 491
488 } // namespace internal 492 } // namespace internal
489 } // namespace v8 493 } // namespace v8
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | test/cctest/cctest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698