blob: ed902ab43f186d57fd1217cd13428659b862bd37 [file] [log] [blame]
Carl Shapirob5573532011-07-12 18:22:59 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07003#include "thread.h"
Carl Shapirob5573532011-07-12 18:22:59 -07004
Ian Rogersb033c752011-07-20 12:22:35 -07005#include <pthread.h>
6#include <sys/mman.h>
Carl Shapirob5573532011-07-12 18:22:59 -07007#include <algorithm>
Elliott Hugheseb4f6142011-07-15 17:43:51 -07008#include <cerrno>
Carl Shapirob5573532011-07-12 18:22:59 -07009#include <list>
Carl Shapirob5573532011-07-12 18:22:59 -070010
Elliott Hughesa5b897e2011-08-16 11:33:06 -070011#include "class_linker.h"
Ian Rogers408f79a2011-08-23 18:22:33 -070012#include "heap.h"
Elliott Hughesc5f7c912011-08-18 14:00:42 -070013#include "jni_internal.h"
Elliott Hughesa5b897e2011-08-16 11:33:06 -070014#include "object.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070015#include "runtime.h"
16#include "utils.h"
buzbee54330722011-08-23 16:46:55 -070017#include "runtime_support.h"
Carl Shapirob5573532011-07-12 18:22:59 -070018
19namespace art {
20
Elliott Hughese27955c2011-08-26 15:21:24 -070021/* desktop Linux needs a little help with gettid() */
22#if !defined(HAVE_ANDROID_OS)
23#define __KERNEL__
24# include <linux/unistd.h>
25#ifdef _syscall0
26_syscall0(pid_t, gettid)
27#else
28pid_t gettid() { return syscall(__NR_gettid);}
29#endif
30#undef __KERNEL__
31#endif
32
Carl Shapirob5573532011-07-12 18:22:59 -070033pthread_key_t Thread::pthread_key_self_;
34
buzbee3ea4ec52011-08-22 17:37:19 -070035void Thread::InitFunctionPointers() {
buzbee54330722011-08-23 16:46:55 -070036#if defined(__arm__)
37 pShlLong = art_shl_long;
38 pShrLong = art_shr_long;
39 pUshrLong = art_ushr_long;
buzbee7b1b86d2011-08-26 18:59:10 -070040 pIdiv = __aeabi_idiv;
41 pIdivmod = __aeabi_idivmod;
42 pI2f = __aeabi_i2f;
43 pF2iz = __aeabi_f2iz;
44 pD2f = __aeabi_d2f;
45 pF2d = __aeabi_f2d;
46 pD2iz = __aeabi_d2iz;
47 pL2f = __aeabi_l2f;
48 pL2d = __aeabi_l2d;
49 pFadd = __aeabi_fadd;
50 pFsub = __aeabi_fsub;
51 pFdiv = __aeabi_fdiv;
52 pFmul = __aeabi_fmul;
53 pFmodf = fmodf;
54 pDadd = __aeabi_dadd;
55 pDsub = __aeabi_dsub;
56 pDdiv = __aeabi_ddiv;
57 pDmul = __aeabi_dmul;
58 pFmod = fmod;
59 pArtF2l = artF2L;
60 pArtD2l = artD2L;
61 pLdivmod = __aeabi_ldivmod;
buzbee54330722011-08-23 16:46:55 -070062#endif
buzbee3ea4ec52011-08-22 17:37:19 -070063 pArtAllocArrayByClass = Array::Alloc;
64 pMemcpy = memcpy;
buzbeee6d61962011-08-27 11:58:19 -070065 pArtHandleFillArrayDataNoThrow = artHandleFillArrayDataNoThrow;
buzbee3ea4ec52011-08-22 17:37:19 -070066#if 0
buzbee3ea4ec52011-08-22 17:37:19 -070067bool (Thread::*pArtUnlockObject)(struct Thread*, struct Object*);
68bool (Thread::*pArtCanPutArrayElementNoThrow)(const struct ClassObject*,
69 const struct ClassObject*);
70int (Thread::*pArtInstanceofNonTrivialNoThrow)
71 (const struct ClassObject*, const struct ClassObject*);
72int (Thread::*pArtInstanceofNonTrivial) (const struct ClassObject*,
73 const struct ClassObject*);
74struct Method* (Thread::*pArtFindInterfaceMethodInCache)(ClassObject*, uint32_t,
75 const struct Method*, struct DvmDex*);
76bool (Thread::*pArtUnlockObjectNoThrow)(struct Thread*, struct Object*);
77void (Thread::*pArtLockObjectNoThrow)(struct Thread*, struct Object*);
78struct Object* (Thread::*pArtAllocObjectNoThrow)(struct ClassObject*, int);
79void (Thread::*pArtThrowException)(struct Thread*, struct Object*);
80bool (Thread::*pArtHandleFillArrayDataNoThrow)(struct ArrayObject*, const uint16_t*);
81#endif
82}
83
Carl Shapirob5573532011-07-12 18:22:59 -070084Mutex* Mutex::Create(const char* name) {
85 Mutex* mu = new Mutex(name);
86 int result = pthread_mutex_init(&mu->lock_impl_, NULL);
Ian Rogersb033c752011-07-20 12:22:35 -070087 CHECK_EQ(0, result);
Carl Shapirob5573532011-07-12 18:22:59 -070088 return mu;
89}
90
91void Mutex::Lock() {
92 int result = pthread_mutex_lock(&lock_impl_);
93 CHECK_EQ(result, 0);
94 SetOwner(Thread::Current());
95}
96
97bool Mutex::TryLock() {
98 int result = pthread_mutex_lock(&lock_impl_);
99 if (result == EBUSY) {
100 return false;
101 } else {
102 CHECK_EQ(result, 0);
103 SetOwner(Thread::Current());
104 return true;
105 }
106}
107
108void Mutex::Unlock() {
109 CHECK(GetOwner() == Thread::Current());
110 int result = pthread_mutex_unlock(&lock_impl_);
111 CHECK_EQ(result, 0);
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700112 SetOwner(NULL);
Carl Shapirob5573532011-07-12 18:22:59 -0700113}
114
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700115void Frame::Next() {
116 byte* next_sp = reinterpret_cast<byte*>(sp_) +
Shih-wei Liaod11af152011-08-23 16:02:11 -0700117 GetMethod()->GetFrameSizeInBytes();
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700118 sp_ = reinterpret_cast<const Method**>(next_sp);
119}
120
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700121uintptr_t Frame::GetPC() const {
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700122 byte* pc_addr = reinterpret_cast<byte*>(sp_) +
Shih-wei Liaod11af152011-08-23 16:02:11 -0700123 GetMethod()->GetReturnPcOffsetInBytes();
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700124 return *reinterpret_cast<uintptr_t*>(pc_addr);
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700125}
126
127const Method* Frame::NextMethod() const {
128 byte* next_sp = reinterpret_cast<byte*>(sp_) +
Shih-wei Liaod11af152011-08-23 16:02:11 -0700129 GetMethod()->GetFrameSizeInBytes();
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700130 return reinterpret_cast<const Method*>(next_sp);
131}
132
Carl Shapiro61e019d2011-07-14 16:53:09 -0700133void* ThreadStart(void *arg) {
Elliott Hughes53b61312011-08-12 18:28:20 -0700134 UNIMPLEMENTED(FATAL);
Carl Shapirob5573532011-07-12 18:22:59 -0700135 return NULL;
136}
137
Brian Carlstromb765be02011-08-17 23:54:10 -0700138Thread* Thread::Create(const Runtime* runtime) {
139 size_t stack_size = runtime->GetStackSize();
Carl Shapiro61e019d2011-07-14 16:53:09 -0700140
141 Thread* new_thread = new Thread;
Ian Rogers176f59c2011-07-20 13:14:11 -0700142 new_thread->InitCpu();
Carl Shapiro61e019d2011-07-14 16:53:09 -0700143
144 pthread_attr_t attr;
Elliott Hughese27955c2011-08-26 15:21:24 -0700145 errno = pthread_attr_init(&attr);
146 if (errno != 0) {
147 PLOG(FATAL) << "pthread_attr_init failed";
148 }
Carl Shapiro61e019d2011-07-14 16:53:09 -0700149
Elliott Hughese27955c2011-08-26 15:21:24 -0700150 errno = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
151 if (errno != 0) {
152 PLOG(FATAL) << "pthread_attr_setdetachstate(PTHREAD_CREATE_DETACHED) failed";
153 }
Carl Shapiro61e019d2011-07-14 16:53:09 -0700154
Elliott Hughese27955c2011-08-26 15:21:24 -0700155 errno = pthread_attr_setstacksize(&attr, stack_size);
156 if (errno != 0) {
157 PLOG(FATAL) << "pthread_attr_setstacksize(" << stack_size << ") failed";
158 }
Carl Shapiro61e019d2011-07-14 16:53:09 -0700159
Elliott Hughese27955c2011-08-26 15:21:24 -0700160 errno = pthread_create(&new_thread->handle_, &attr, ThreadStart, new_thread);
161 if (errno != 0) {
162 PLOG(FATAL) << "pthread_create failed";
163 }
164
165 errno = pthread_attr_destroy(&attr);
166 if (errno != 0) {
167 PLOG(FATAL) << "pthread_attr_destroy failed";
168 }
Carl Shapiro61e019d2011-07-14 16:53:09 -0700169
170 return new_thread;
171}
172
Elliott Hughes515a5bc2011-08-17 11:08:34 -0700173Thread* Thread::Attach(const Runtime* runtime) {
Carl Shapiro61e019d2011-07-14 16:53:09 -0700174 Thread* thread = new Thread;
Ian Rogers176f59c2011-07-20 13:14:11 -0700175 thread->InitCpu();
Carl Shapiro61e019d2011-07-14 16:53:09 -0700176
177 thread->handle_ = pthread_self();
178
179 thread->state_ = kRunnable;
180
Elliott Hughesa5780da2011-07-17 11:39:39 -0700181 errno = pthread_setspecific(Thread::pthread_key_self_, thread);
182 if (errno != 0) {
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700183 PLOG(FATAL) << "pthread_setspecific failed";
Elliott Hughesa5780da2011-07-17 11:39:39 -0700184 }
185
Elliott Hughes75770752011-08-24 17:52:38 -0700186 thread->jni_env_ = new JNIEnvExt(thread, runtime->GetJavaVM());
Elliott Hughes330304d2011-08-12 14:28:05 -0700187
Carl Shapiro61e019d2011-07-14 16:53:09 -0700188 return thread;
189}
190
Elliott Hughese27955c2011-08-26 15:21:24 -0700191pid_t Thread::GetTid() const {
192 return gettid();
193}
194
Carl Shapirob5573532011-07-12 18:22:59 -0700195static void ThreadExitCheck(void* arg) {
196 LG << "Thread exit check";
197}
198
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700199bool Thread::Startup() {
Carl Shapirob5573532011-07-12 18:22:59 -0700200 // Allocate a TLS slot.
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700201 errno = pthread_key_create(&Thread::pthread_key_self_, ThreadExitCheck);
202 if (errno != 0) {
Elliott Hugheseb4f6142011-07-15 17:43:51 -0700203 PLOG(WARNING) << "pthread_key_create failed";
Carl Shapirob5573532011-07-12 18:22:59 -0700204 return false;
205 }
206
207 // Double-check the TLS slot allocation.
208 if (pthread_getspecific(pthread_key_self_) != NULL) {
Elliott Hugheseb4f6142011-07-15 17:43:51 -0700209 LOG(WARNING) << "newly-created pthread TLS slot is not NULL";
Carl Shapirob5573532011-07-12 18:22:59 -0700210 return false;
211 }
212
213 // TODO: initialize other locks and condition variables
214
215 return true;
216}
217
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700218void Thread::Shutdown() {
219 errno = pthread_key_delete(Thread::pthread_key_self_);
220 if (errno != 0) {
221 PLOG(WARNING) << "pthread_key_delete failed";
222 }
223}
224
225Thread::~Thread() {
226 delete jni_env_;
227}
228
Ian Rogers408f79a2011-08-23 18:22:33 -0700229size_t Thread::NumSirtReferences() {
Ian Rogersa8cd9f42011-08-19 16:43:41 -0700230 size_t count = 0;
Ian Rogers408f79a2011-08-23 18:22:33 -0700231 for (StackIndirectReferenceTable* cur = top_sirt_; cur; cur = cur->Link()) {
Ian Rogersa8cd9f42011-08-19 16:43:41 -0700232 count += cur->NumberOfReferences();
233 }
234 return count;
235}
236
Ian Rogers408f79a2011-08-23 18:22:33 -0700237bool Thread::SirtContains(jobject obj) {
238 Object** sirt_entry = reinterpret_cast<Object**>(obj);
239 for (StackIndirectReferenceTable* cur = top_sirt_; cur; cur = cur->Link()) {
Ian Rogersa8cd9f42011-08-19 16:43:41 -0700240 size_t num_refs = cur->NumberOfReferences();
Ian Rogers408f79a2011-08-23 18:22:33 -0700241 // A SIRT should always have a jobject/jclass as a native method is passed
242 // in a this pointer or a class
243 DCHECK_GT(num_refs, 0u);
244 if ((&cur->References()[0] >= sirt_entry) &&
245 (sirt_entry <= (&cur->References()[num_refs-1]))) {
Ian Rogersa8cd9f42011-08-19 16:43:41 -0700246 return true;
247 }
248 }
249 return false;
250}
251
Ian Rogers408f79a2011-08-23 18:22:33 -0700252Object* Thread::DecodeJObject(jobject obj) {
253 // TODO: Only allowed to hold Object* when in the runnable state
254 // DCHECK(state_ == kRunnable);
255 if (obj == NULL) {
256 return NULL;
257 }
258 IndirectRef ref = reinterpret_cast<IndirectRef>(obj);
259 IndirectRefKind kind = GetIndirectRefKind(ref);
260 Object* result;
261 switch (kind) {
262 case kLocal:
263 {
Elliott Hughes69f5bc62011-08-24 09:26:14 -0700264 IndirectReferenceTable& locals = jni_env_->locals;
Ian Rogers408f79a2011-08-23 18:22:33 -0700265 result = locals.Get(ref);
266 break;
267 }
268 case kGlobal:
269 {
270 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
271 IndirectReferenceTable& globals = vm->globals;
272 MutexLock mu(vm->globals_lock);
273 result = globals.Get(ref);
274 break;
275 }
276 case kWeakGlobal:
277 {
278 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
279 IndirectReferenceTable& weak_globals = vm->weak_globals;
280 MutexLock mu(vm->weak_globals_lock);
281 result = weak_globals.Get(ref);
282 if (result == kClearedJniWeakGlobal) {
283 // This is a special case where it's okay to return NULL.
284 return NULL;
285 }
286 break;
287 }
288 case kSirtOrInvalid:
289 default:
290 // TODO: make stack indirect reference table lookup more efficient
291 // Check if this is a local reference in the SIRT
292 if (SirtContains(obj)) {
293 result = *reinterpret_cast<Object**>(obj); // Read from SIRT
294 } else if (false /*gDvmJni.workAroundAppJniBugs*/) { // TODO
295 // Assume an invalid local reference is actually a direct pointer.
296 result = reinterpret_cast<Object*>(obj);
297 } else {
298 LOG(FATAL) << "Invalid indirect reference " << obj;
299 result = reinterpret_cast<Object*>(kInvalidIndirectRefObject);
300 }
301 }
302
303 if (result == NULL) {
304 LOG(FATAL) << "JNI ERROR (app bug): use of deleted " << kind << ": "
305 << obj;
306 }
307 Heap::VerifyObject(result);
308 return result;
309}
310
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700311// TODO: Replaces trace.method and trace.pc with IntArray nad
312// ObjectArray<Method>.
313Thread::InternalStackTrace* Thread::GetStackTrace(uint16_t length) {
314 Frame frame = Thread::Current()->GetTopOfStack();
315 InternalStackTrace *traces = new InternalStackTrace[length];
316 for (uint16_t i = 0; i < length && frame.HasNext(); ++i, frame.Next()) {
317 traces[i].method = frame.GetMethod();
318 traces[i].pc = frame.GetPC();
319 }
320 return traces;
321}
322
323ObjectArray<StackTraceElement>* Thread::GetStackTraceElement(uint16_t length, InternalStackTrace *raw_trace) {
324 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
325 ObjectArray<StackTraceElement>* java_traces = class_linker->AllocStackTraceElementArray(length);
326
327 for (uint16_t i = 0; i < length; ++i) {
328 // Prepare parameter for StackTraceElement(String cls, String method, String file, int line)
329 const Method* method = raw_trace[i].method;
330 const Class* klass = method->GetDeclaringClass();
331 const DexFile& dex_file = class_linker->FindDexFile(klass->GetDexCache());
332 String* readable_descriptor = String::AllocFromModifiedUtf8(PrettyDescriptor(klass->GetDescriptor()).c_str());
333
334 StackTraceElement* obj =
335 StackTraceElement::Alloc(readable_descriptor,
336 method->GetName(), String::AllocFromModifiedUtf8(klass->source_file_),
337 dex_file.GetLineNumFromPC(method, method->ToDexPC(raw_trace[i].pc)));
338 java_traces->Set(i, obj);
339 }
340 return java_traces;
341}
342
Elliott Hughese5b0dc82011-08-23 09:59:02 -0700343void Thread::ThrowNewException(const char* exception_class_descriptor, const char* fmt, ...) {
Elliott Hughes37f7a402011-08-22 18:56:01 -0700344 std::string msg;
Elliott Hughesa5b897e2011-08-16 11:33:06 -0700345 va_list args;
346 va_start(args, fmt);
Elliott Hughes37f7a402011-08-22 18:56:01 -0700347 StringAppendV(&msg, fmt, args);
Elliott Hughesa5b897e2011-08-16 11:33:06 -0700348 va_end(args);
Elliott Hughes37f7a402011-08-22 18:56:01 -0700349
Elliott Hughese5b0dc82011-08-23 09:59:02 -0700350 // Convert "Ljava/lang/Exception;" into JNI-style "java/lang/Exception".
351 CHECK(exception_class_descriptor[0] == 'L');
352 std::string descriptor(exception_class_descriptor + 1);
353 CHECK(descriptor[descriptor.length() - 1] == ';');
354 descriptor.erase(descriptor.length() - 1);
355
356 JNIEnv* env = GetJniEnv();
357 jclass exception_class = env->FindClass(descriptor.c_str());
358 CHECK(exception_class != NULL) << "descriptor=\"" << descriptor << "\"";
359 int rc = env->ThrowNew(exception_class, msg.c_str());
360 CHECK_EQ(rc, JNI_OK);
Elliott Hughesa5b897e2011-08-16 11:33:06 -0700361}
362
Elliott Hughes79082e32011-08-25 12:07:32 -0700363void Thread::ThrowOutOfMemoryError() {
364 UNIMPLEMENTED(FATAL);
365}
366
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700367Frame Thread::FindExceptionHandler(void* throw_pc, void** handler_pc) {
368 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
369 DCHECK(class_linker != NULL);
370
371 Frame cur_frame = GetTopOfStack();
372 for (int unwind_depth = 0; ; unwind_depth++) {
373 const Method* cur_method = cur_frame.GetMethod();
374 DexCache* dex_cache = cur_method->GetDeclaringClass()->GetDexCache();
375 const DexFile& dex_file = class_linker->FindDexFile(dex_cache);
376
377 void* handler_addr = FindExceptionHandlerInMethod(cur_method,
378 throw_pc,
379 dex_file,
380 class_linker);
381 if (handler_addr) {
382 *handler_pc = handler_addr;
383 return cur_frame;
384 } else {
385 // Check if we are at the last frame
386 if (cur_frame.HasNext()) {
387 cur_frame.Next();
388 } else {
389 // Either at the top of stack or next frame is native.
390 break;
391 }
392 }
393 }
394 *handler_pc = NULL;
395 return Frame();
396}
397
398void* Thread::FindExceptionHandlerInMethod(const Method* method,
399 void* throw_pc,
400 const DexFile& dex_file,
401 ClassLinker* class_linker) {
Elliott Hughese5b0dc82011-08-23 09:59:02 -0700402 Throwable* exception_obj = exception_;
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700403 exception_ = NULL;
404
405 intptr_t dex_pc = -1;
406 const DexFile::CodeItem* code_item = dex_file.GetCodeItem(method->code_off_);
407 DexFile::CatchHandlerIterator iter;
408 for (iter = dex_file.dexFindCatchHandler(*code_item,
409 method->ToDexPC(reinterpret_cast<intptr_t>(throw_pc)));
410 !iter.HasNext();
411 iter.Next()) {
412 Class* klass = class_linker->FindSystemClass(dex_file.dexStringByTypeIdx(iter.Get().type_idx_));
413 DCHECK(klass != NULL);
414 if (exception_obj->InstanceOf(klass)) {
415 dex_pc = iter.Get().address_;
416 break;
417 }
418 }
419
420 exception_ = exception_obj;
421 if (iter.HasNext()) {
422 return NULL;
423 } else {
424 return reinterpret_cast<void*>( method->ToNativePC(dex_pc) );
425 }
426}
427
Ian Rogersb033c752011-07-20 12:22:35 -0700428static const char* kStateNames[] = {
429 "New",
430 "Runnable",
431 "Blocked",
432 "Waiting",
433 "TimedWaiting",
434 "Native",
435 "Terminated",
436};
437std::ostream& operator<<(std::ostream& os, const Thread::State& state) {
438 if (state >= Thread::kNew && state <= Thread::kTerminated) {
439 os << kStateNames[state-Thread::kNew];
440 } else {
441 os << "State[" << static_cast<int>(state) << "]";
442 }
443 return os;
444}
445
Elliott Hughes330304d2011-08-12 14:28:05 -0700446std::ostream& operator<<(std::ostream& os, const Thread& thread) {
447 os << "Thread[" << &thread
Elliott Hughese27955c2011-08-26 15:21:24 -0700448 << ",pthread_t=" << thread.GetImpl()
449 << ",tid=" << thread.GetTid()
450 << ",id=" << thread.GetId()
451 << ",state=" << thread.GetState() << "]";
Elliott Hughes330304d2011-08-12 14:28:05 -0700452 return os;
453}
454
Carl Shapiro61e019d2011-07-14 16:53:09 -0700455ThreadList* ThreadList::Create() {
456 return new ThreadList;
457}
458
Carl Shapirob5573532011-07-12 18:22:59 -0700459ThreadList::ThreadList() {
460 lock_ = Mutex::Create("ThreadList::Lock");
461}
462
463ThreadList::~ThreadList() {
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700464 if (Contains(Thread::Current())) {
465 Runtime::Current()->DetachCurrentThread();
466 }
467
468 // All threads should have exited and unregistered when we
Carl Shapirob5573532011-07-12 18:22:59 -0700469 // reach this point. This means that all daemon threads had been
470 // shutdown cleanly.
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700471 // TODO: dump ThreadList if non-empty.
472 CHECK_EQ(list_.size(), 0U);
473
Carl Shapirob5573532011-07-12 18:22:59 -0700474 delete lock_;
475 lock_ = NULL;
476}
477
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700478bool ThreadList::Contains(Thread* thread) {
479 return find(list_.begin(), list_.end(), thread) != list_.end();
480}
481
Carl Shapirob5573532011-07-12 18:22:59 -0700482void ThreadList::Register(Thread* thread) {
483 MutexLock mu(lock_);
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700484 CHECK(!Contains(thread));
Carl Shapirob5573532011-07-12 18:22:59 -0700485 list_.push_front(thread);
486}
487
488void ThreadList::Unregister(Thread* thread) {
489 MutexLock mu(lock_);
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700490 CHECK(Contains(thread));
Carl Shapirob5573532011-07-12 18:22:59 -0700491 list_.remove(thread);
492}
493
Carl Shapirob5573532011-07-12 18:22:59 -0700494} // namespace