blob: 4d9386fc7c91d70eb494f82ace0d003e70ac55a1 [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;
65#if 0
buzbee3ea4ec52011-08-22 17:37:19 -070066bool (Thread::*pArtUnlockObject)(struct Thread*, struct Object*);
67bool (Thread::*pArtCanPutArrayElementNoThrow)(const struct ClassObject*,
68 const struct ClassObject*);
69int (Thread::*pArtInstanceofNonTrivialNoThrow)
70 (const struct ClassObject*, const struct ClassObject*);
71int (Thread::*pArtInstanceofNonTrivial) (const struct ClassObject*,
72 const struct ClassObject*);
73struct Method* (Thread::*pArtFindInterfaceMethodInCache)(ClassObject*, uint32_t,
74 const struct Method*, struct DvmDex*);
75bool (Thread::*pArtUnlockObjectNoThrow)(struct Thread*, struct Object*);
76void (Thread::*pArtLockObjectNoThrow)(struct Thread*, struct Object*);
77struct Object* (Thread::*pArtAllocObjectNoThrow)(struct ClassObject*, int);
78void (Thread::*pArtThrowException)(struct Thread*, struct Object*);
79bool (Thread::*pArtHandleFillArrayDataNoThrow)(struct ArrayObject*, const uint16_t*);
80#endif
81}
82
Carl Shapirob5573532011-07-12 18:22:59 -070083Mutex* Mutex::Create(const char* name) {
84 Mutex* mu = new Mutex(name);
85 int result = pthread_mutex_init(&mu->lock_impl_, NULL);
Ian Rogersb033c752011-07-20 12:22:35 -070086 CHECK_EQ(0, result);
Carl Shapirob5573532011-07-12 18:22:59 -070087 return mu;
88}
89
90void Mutex::Lock() {
91 int result = pthread_mutex_lock(&lock_impl_);
92 CHECK_EQ(result, 0);
93 SetOwner(Thread::Current());
94}
95
96bool Mutex::TryLock() {
97 int result = pthread_mutex_lock(&lock_impl_);
98 if (result == EBUSY) {
99 return false;
100 } else {
101 CHECK_EQ(result, 0);
102 SetOwner(Thread::Current());
103 return true;
104 }
105}
106
107void Mutex::Unlock() {
108 CHECK(GetOwner() == Thread::Current());
109 int result = pthread_mutex_unlock(&lock_impl_);
110 CHECK_EQ(result, 0);
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700111 SetOwner(NULL);
Carl Shapirob5573532011-07-12 18:22:59 -0700112}
113
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700114void Frame::Next() {
115 byte* next_sp = reinterpret_cast<byte*>(sp_) +
Shih-wei Liaod11af152011-08-23 16:02:11 -0700116 GetMethod()->GetFrameSizeInBytes();
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700117 sp_ = reinterpret_cast<const Method**>(next_sp);
118}
119
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700120uintptr_t Frame::GetPC() const {
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700121 byte* pc_addr = reinterpret_cast<byte*>(sp_) +
Shih-wei Liaod11af152011-08-23 16:02:11 -0700122 GetMethod()->GetReturnPcOffsetInBytes();
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700123 return *reinterpret_cast<uintptr_t*>(pc_addr);
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700124}
125
126const Method* Frame::NextMethod() const {
127 byte* next_sp = reinterpret_cast<byte*>(sp_) +
Shih-wei Liaod11af152011-08-23 16:02:11 -0700128 GetMethod()->GetFrameSizeInBytes();
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700129 return reinterpret_cast<const Method*>(next_sp);
130}
131
Carl Shapiro61e019d2011-07-14 16:53:09 -0700132void* ThreadStart(void *arg) {
Elliott Hughes53b61312011-08-12 18:28:20 -0700133 UNIMPLEMENTED(FATAL);
Carl Shapirob5573532011-07-12 18:22:59 -0700134 return NULL;
135}
136
Brian Carlstromb765be02011-08-17 23:54:10 -0700137Thread* Thread::Create(const Runtime* runtime) {
138 size_t stack_size = runtime->GetStackSize();
Carl Shapiro61e019d2011-07-14 16:53:09 -0700139
140 Thread* new_thread = new Thread;
Ian Rogers176f59c2011-07-20 13:14:11 -0700141 new_thread->InitCpu();
Carl Shapiro61e019d2011-07-14 16:53:09 -0700142
143 pthread_attr_t attr;
Elliott Hughese27955c2011-08-26 15:21:24 -0700144 errno = pthread_attr_init(&attr);
145 if (errno != 0) {
146 PLOG(FATAL) << "pthread_attr_init failed";
147 }
Carl Shapiro61e019d2011-07-14 16:53:09 -0700148
Elliott Hughese27955c2011-08-26 15:21:24 -0700149 errno = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
150 if (errno != 0) {
151 PLOG(FATAL) << "pthread_attr_setdetachstate(PTHREAD_CREATE_DETACHED) failed";
152 }
Carl Shapiro61e019d2011-07-14 16:53:09 -0700153
Elliott Hughese27955c2011-08-26 15:21:24 -0700154 errno = pthread_attr_setstacksize(&attr, stack_size);
155 if (errno != 0) {
156 PLOG(FATAL) << "pthread_attr_setstacksize(" << stack_size << ") failed";
157 }
Carl Shapiro61e019d2011-07-14 16:53:09 -0700158
Elliott Hughese27955c2011-08-26 15:21:24 -0700159 errno = pthread_create(&new_thread->handle_, &attr, ThreadStart, new_thread);
160 if (errno != 0) {
161 PLOG(FATAL) << "pthread_create failed";
162 }
163
164 errno = pthread_attr_destroy(&attr);
165 if (errno != 0) {
166 PLOG(FATAL) << "pthread_attr_destroy failed";
167 }
Carl Shapiro61e019d2011-07-14 16:53:09 -0700168
169 return new_thread;
170}
171
Elliott Hughes515a5bc2011-08-17 11:08:34 -0700172Thread* Thread::Attach(const Runtime* runtime) {
Carl Shapiro61e019d2011-07-14 16:53:09 -0700173 Thread* thread = new Thread;
Ian Rogers176f59c2011-07-20 13:14:11 -0700174 thread->InitCpu();
Carl Shapiro61e019d2011-07-14 16:53:09 -0700175
176 thread->handle_ = pthread_self();
177
178 thread->state_ = kRunnable;
179
Elliott Hughesa5780da2011-07-17 11:39:39 -0700180 errno = pthread_setspecific(Thread::pthread_key_self_, thread);
181 if (errno != 0) {
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700182 PLOG(FATAL) << "pthread_setspecific failed";
Elliott Hughesa5780da2011-07-17 11:39:39 -0700183 }
184
Elliott Hughes75770752011-08-24 17:52:38 -0700185 thread->jni_env_ = new JNIEnvExt(thread, runtime->GetJavaVM());
Elliott Hughes330304d2011-08-12 14:28:05 -0700186
Carl Shapiro61e019d2011-07-14 16:53:09 -0700187 return thread;
188}
189
Elliott Hughese27955c2011-08-26 15:21:24 -0700190pid_t Thread::GetTid() const {
191 return gettid();
192}
193
Carl Shapirob5573532011-07-12 18:22:59 -0700194static void ThreadExitCheck(void* arg) {
195 LG << "Thread exit check";
196}
197
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700198bool Thread::Startup() {
Carl Shapirob5573532011-07-12 18:22:59 -0700199 // Allocate a TLS slot.
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700200 errno = pthread_key_create(&Thread::pthread_key_self_, ThreadExitCheck);
201 if (errno != 0) {
Elliott Hugheseb4f6142011-07-15 17:43:51 -0700202 PLOG(WARNING) << "pthread_key_create failed";
Carl Shapirob5573532011-07-12 18:22:59 -0700203 return false;
204 }
205
206 // Double-check the TLS slot allocation.
207 if (pthread_getspecific(pthread_key_self_) != NULL) {
Elliott Hugheseb4f6142011-07-15 17:43:51 -0700208 LOG(WARNING) << "newly-created pthread TLS slot is not NULL";
Carl Shapirob5573532011-07-12 18:22:59 -0700209 return false;
210 }
211
212 // TODO: initialize other locks and condition variables
213
214 return true;
215}
216
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700217void Thread::Shutdown() {
218 errno = pthread_key_delete(Thread::pthread_key_self_);
219 if (errno != 0) {
220 PLOG(WARNING) << "pthread_key_delete failed";
221 }
222}
223
224Thread::~Thread() {
225 delete jni_env_;
226}
227
Ian Rogers408f79a2011-08-23 18:22:33 -0700228size_t Thread::NumSirtReferences() {
Ian Rogersa8cd9f42011-08-19 16:43:41 -0700229 size_t count = 0;
Ian Rogers408f79a2011-08-23 18:22:33 -0700230 for (StackIndirectReferenceTable* cur = top_sirt_; cur; cur = cur->Link()) {
Ian Rogersa8cd9f42011-08-19 16:43:41 -0700231 count += cur->NumberOfReferences();
232 }
233 return count;
234}
235
Ian Rogers408f79a2011-08-23 18:22:33 -0700236bool Thread::SirtContains(jobject obj) {
237 Object** sirt_entry = reinterpret_cast<Object**>(obj);
238 for (StackIndirectReferenceTable* cur = top_sirt_; cur; cur = cur->Link()) {
Ian Rogersa8cd9f42011-08-19 16:43:41 -0700239 size_t num_refs = cur->NumberOfReferences();
Ian Rogers408f79a2011-08-23 18:22:33 -0700240 // A SIRT should always have a jobject/jclass as a native method is passed
241 // in a this pointer or a class
242 DCHECK_GT(num_refs, 0u);
243 if ((&cur->References()[0] >= sirt_entry) &&
244 (sirt_entry <= (&cur->References()[num_refs-1]))) {
Ian Rogersa8cd9f42011-08-19 16:43:41 -0700245 return true;
246 }
247 }
248 return false;
249}
250
Ian Rogers408f79a2011-08-23 18:22:33 -0700251Object* Thread::DecodeJObject(jobject obj) {
252 // TODO: Only allowed to hold Object* when in the runnable state
253 // DCHECK(state_ == kRunnable);
254 if (obj == NULL) {
255 return NULL;
256 }
257 IndirectRef ref = reinterpret_cast<IndirectRef>(obj);
258 IndirectRefKind kind = GetIndirectRefKind(ref);
259 Object* result;
260 switch (kind) {
261 case kLocal:
262 {
Elliott Hughes69f5bc62011-08-24 09:26:14 -0700263 IndirectReferenceTable& locals = jni_env_->locals;
Ian Rogers408f79a2011-08-23 18:22:33 -0700264 result = locals.Get(ref);
265 break;
266 }
267 case kGlobal:
268 {
269 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
270 IndirectReferenceTable& globals = vm->globals;
271 MutexLock mu(vm->globals_lock);
272 result = globals.Get(ref);
273 break;
274 }
275 case kWeakGlobal:
276 {
277 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
278 IndirectReferenceTable& weak_globals = vm->weak_globals;
279 MutexLock mu(vm->weak_globals_lock);
280 result = weak_globals.Get(ref);
281 if (result == kClearedJniWeakGlobal) {
282 // This is a special case where it's okay to return NULL.
283 return NULL;
284 }
285 break;
286 }
287 case kSirtOrInvalid:
288 default:
289 // TODO: make stack indirect reference table lookup more efficient
290 // Check if this is a local reference in the SIRT
291 if (SirtContains(obj)) {
292 result = *reinterpret_cast<Object**>(obj); // Read from SIRT
293 } else if (false /*gDvmJni.workAroundAppJniBugs*/) { // TODO
294 // Assume an invalid local reference is actually a direct pointer.
295 result = reinterpret_cast<Object*>(obj);
296 } else {
297 LOG(FATAL) << "Invalid indirect reference " << obj;
298 result = reinterpret_cast<Object*>(kInvalidIndirectRefObject);
299 }
300 }
301
302 if (result == NULL) {
303 LOG(FATAL) << "JNI ERROR (app bug): use of deleted " << kind << ": "
304 << obj;
305 }
306 Heap::VerifyObject(result);
307 return result;
308}
309
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700310// TODO: Replaces trace.method and trace.pc with IntArray nad
311// ObjectArray<Method>.
312Thread::InternalStackTrace* Thread::GetStackTrace(uint16_t length) {
313 Frame frame = Thread::Current()->GetTopOfStack();
314 InternalStackTrace *traces = new InternalStackTrace[length];
315 for (uint16_t i = 0; i < length && frame.HasNext(); ++i, frame.Next()) {
316 traces[i].method = frame.GetMethod();
317 traces[i].pc = frame.GetPC();
318 }
319 return traces;
320}
321
322ObjectArray<StackTraceElement>* Thread::GetStackTraceElement(uint16_t length, InternalStackTrace *raw_trace) {
323 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
324 ObjectArray<StackTraceElement>* java_traces = class_linker->AllocStackTraceElementArray(length);
325
326 for (uint16_t i = 0; i < length; ++i) {
327 // Prepare parameter for StackTraceElement(String cls, String method, String file, int line)
328 const Method* method = raw_trace[i].method;
329 const Class* klass = method->GetDeclaringClass();
330 const DexFile& dex_file = class_linker->FindDexFile(klass->GetDexCache());
331 String* readable_descriptor = String::AllocFromModifiedUtf8(PrettyDescriptor(klass->GetDescriptor()).c_str());
332
333 StackTraceElement* obj =
334 StackTraceElement::Alloc(readable_descriptor,
335 method->GetName(), String::AllocFromModifiedUtf8(klass->source_file_),
336 dex_file.GetLineNumFromPC(method, method->ToDexPC(raw_trace[i].pc)));
337 java_traces->Set(i, obj);
338 }
339 return java_traces;
340}
341
Elliott Hughese5b0dc82011-08-23 09:59:02 -0700342void Thread::ThrowNewException(const char* exception_class_descriptor, const char* fmt, ...) {
Elliott Hughes37f7a402011-08-22 18:56:01 -0700343 std::string msg;
Elliott Hughesa5b897e2011-08-16 11:33:06 -0700344 va_list args;
345 va_start(args, fmt);
Elliott Hughes37f7a402011-08-22 18:56:01 -0700346 StringAppendV(&msg, fmt, args);
Elliott Hughesa5b897e2011-08-16 11:33:06 -0700347 va_end(args);
Elliott Hughes37f7a402011-08-22 18:56:01 -0700348
Elliott Hughese5b0dc82011-08-23 09:59:02 -0700349 // Convert "Ljava/lang/Exception;" into JNI-style "java/lang/Exception".
350 CHECK(exception_class_descriptor[0] == 'L');
351 std::string descriptor(exception_class_descriptor + 1);
352 CHECK(descriptor[descriptor.length() - 1] == ';');
353 descriptor.erase(descriptor.length() - 1);
354
355 JNIEnv* env = GetJniEnv();
356 jclass exception_class = env->FindClass(descriptor.c_str());
357 CHECK(exception_class != NULL) << "descriptor=\"" << descriptor << "\"";
358 int rc = env->ThrowNew(exception_class, msg.c_str());
359 CHECK_EQ(rc, JNI_OK);
Elliott Hughesa5b897e2011-08-16 11:33:06 -0700360}
361
Elliott Hughes79082e32011-08-25 12:07:32 -0700362void Thread::ThrowOutOfMemoryError() {
363 UNIMPLEMENTED(FATAL);
364}
365
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700366Frame Thread::FindExceptionHandler(void* throw_pc, void** handler_pc) {
367 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
368 DCHECK(class_linker != NULL);
369
370 Frame cur_frame = GetTopOfStack();
371 for (int unwind_depth = 0; ; unwind_depth++) {
372 const Method* cur_method = cur_frame.GetMethod();
373 DexCache* dex_cache = cur_method->GetDeclaringClass()->GetDexCache();
374 const DexFile& dex_file = class_linker->FindDexFile(dex_cache);
375
376 void* handler_addr = FindExceptionHandlerInMethod(cur_method,
377 throw_pc,
378 dex_file,
379 class_linker);
380 if (handler_addr) {
381 *handler_pc = handler_addr;
382 return cur_frame;
383 } else {
384 // Check if we are at the last frame
385 if (cur_frame.HasNext()) {
386 cur_frame.Next();
387 } else {
388 // Either at the top of stack or next frame is native.
389 break;
390 }
391 }
392 }
393 *handler_pc = NULL;
394 return Frame();
395}
396
397void* Thread::FindExceptionHandlerInMethod(const Method* method,
398 void* throw_pc,
399 const DexFile& dex_file,
400 ClassLinker* class_linker) {
Elliott Hughese5b0dc82011-08-23 09:59:02 -0700401 Throwable* exception_obj = exception_;
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700402 exception_ = NULL;
403
404 intptr_t dex_pc = -1;
405 const DexFile::CodeItem* code_item = dex_file.GetCodeItem(method->code_off_);
406 DexFile::CatchHandlerIterator iter;
407 for (iter = dex_file.dexFindCatchHandler(*code_item,
408 method->ToDexPC(reinterpret_cast<intptr_t>(throw_pc)));
409 !iter.HasNext();
410 iter.Next()) {
411 Class* klass = class_linker->FindSystemClass(dex_file.dexStringByTypeIdx(iter.Get().type_idx_));
412 DCHECK(klass != NULL);
413 if (exception_obj->InstanceOf(klass)) {
414 dex_pc = iter.Get().address_;
415 break;
416 }
417 }
418
419 exception_ = exception_obj;
420 if (iter.HasNext()) {
421 return NULL;
422 } else {
423 return reinterpret_cast<void*>( method->ToNativePC(dex_pc) );
424 }
425}
426
Ian Rogersb033c752011-07-20 12:22:35 -0700427static const char* kStateNames[] = {
428 "New",
429 "Runnable",
430 "Blocked",
431 "Waiting",
432 "TimedWaiting",
433 "Native",
434 "Terminated",
435};
436std::ostream& operator<<(std::ostream& os, const Thread::State& state) {
437 if (state >= Thread::kNew && state <= Thread::kTerminated) {
438 os << kStateNames[state-Thread::kNew];
439 } else {
440 os << "State[" << static_cast<int>(state) << "]";
441 }
442 return os;
443}
444
Elliott Hughes330304d2011-08-12 14:28:05 -0700445std::ostream& operator<<(std::ostream& os, const Thread& thread) {
446 os << "Thread[" << &thread
Elliott Hughese27955c2011-08-26 15:21:24 -0700447 << ",pthread_t=" << thread.GetImpl()
448 << ",tid=" << thread.GetTid()
449 << ",id=" << thread.GetId()
450 << ",state=" << thread.GetState() << "]";
Elliott Hughes330304d2011-08-12 14:28:05 -0700451 return os;
452}
453
Carl Shapiro61e019d2011-07-14 16:53:09 -0700454ThreadList* ThreadList::Create() {
455 return new ThreadList;
456}
457
Carl Shapirob5573532011-07-12 18:22:59 -0700458ThreadList::ThreadList() {
459 lock_ = Mutex::Create("ThreadList::Lock");
460}
461
462ThreadList::~ThreadList() {
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700463 if (Contains(Thread::Current())) {
464 Runtime::Current()->DetachCurrentThread();
465 }
466
467 // All threads should have exited and unregistered when we
Carl Shapirob5573532011-07-12 18:22:59 -0700468 // reach this point. This means that all daemon threads had been
469 // shutdown cleanly.
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700470 // TODO: dump ThreadList if non-empty.
471 CHECK_EQ(list_.size(), 0U);
472
Carl Shapirob5573532011-07-12 18:22:59 -0700473 delete lock_;
474 lock_ = NULL;
475}
476
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700477bool ThreadList::Contains(Thread* thread) {
478 return find(list_.begin(), list_.end(), thread) != list_.end();
479}
480
Carl Shapirob5573532011-07-12 18:22:59 -0700481void ThreadList::Register(Thread* thread) {
482 MutexLock mu(lock_);
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700483 CHECK(!Contains(thread));
Carl Shapirob5573532011-07-12 18:22:59 -0700484 list_.push_front(thread);
485}
486
487void ThreadList::Unregister(Thread* thread) {
488 MutexLock mu(lock_);
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700489 CHECK(Contains(thread));
Carl Shapirob5573532011-07-12 18:22:59 -0700490 list_.remove(thread);
491}
492
Carl Shapirob5573532011-07-12 18:22:59 -0700493} // namespace