Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 3 | #include "thread.h" |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 4 | |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 5 | #include <pthread.h> |
| 6 | #include <sys/mman.h> |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 7 | #include <algorithm> |
Elliott Hughes | eb4f614 | 2011-07-15 17:43:51 -0700 | [diff] [blame] | 8 | #include <cerrno> |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 9 | #include <list> |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 10 | |
Elliott Hughes | a5b897e | 2011-08-16 11:33:06 -0700 | [diff] [blame] | 11 | #include "class_linker.h" |
Elliott Hughes | c5f7c91 | 2011-08-18 14:00:42 -0700 | [diff] [blame] | 12 | #include "jni_internal.h" |
Elliott Hughes | a5b897e | 2011-08-16 11:33:06 -0700 | [diff] [blame] | 13 | #include "object.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 14 | #include "runtime.h" |
| 15 | #include "utils.h" |
buzbee | 5433072 | 2011-08-23 16:46:55 -0700 | [diff] [blame^] | 16 | #include "runtime_support.h" |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 17 | |
| 18 | namespace art { |
| 19 | |
| 20 | pthread_key_t Thread::pthread_key_self_; |
| 21 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 22 | void Thread::InitFunctionPointers() { |
buzbee | 5433072 | 2011-08-23 16:46:55 -0700 | [diff] [blame^] | 23 | #if defined(__arm__) |
| 24 | pShlLong = art_shl_long; |
| 25 | pShrLong = art_shr_long; |
| 26 | pUshrLong = art_ushr_long; |
| 27 | #endif |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 28 | pArtAllocArrayByClass = Array::Alloc; |
| 29 | pMemcpy = memcpy; |
| 30 | #if 0 |
| 31 | //void* (Thread::*pMemcpy)(void*, const void*, size_t) /* = memcpy*/ ; |
| 32 | float (Thread::*pI2f)(int); |
| 33 | int (Thread::*pF2iz)(float); |
| 34 | float (Thread::*pD2f)(double); |
| 35 | double (Thread::*pF2d)(float); |
| 36 | double (Thread::*pI2d)(int); |
| 37 | int (Thread::*pD2iz)(double); |
| 38 | float (Thread::*pL2f)(long); |
| 39 | double (Thread::*pL2d)(long); |
| 40 | long long (Thread::*pArtF2l)(float); |
| 41 | long long (Thread::*pArtD2l)(double); |
| 42 | float (Thread::*pFadd)(float, float); |
| 43 | float (Thread::*pFsub)(float, float); |
| 44 | float (Thread::*pFdiv)(float, float); |
| 45 | float (Thread::*pFmul)(float, float); |
| 46 | float (Thread::*pFmodf)(float, float); |
| 47 | double (Thread::*pDadd)(double, double); |
| 48 | double (Thread::*pDsub)(double, double); |
| 49 | double (Thread::*pDdiv)(double, double); |
| 50 | double (Thread::*pDmul)(double, double); |
| 51 | double (Thread::*pFmod)(double, double); |
| 52 | int (Thread::*pIdivmod)(int, int); |
| 53 | int (Thread::*pIdiv)(int, int); |
| 54 | long long (Thread::*pLdivmod)(long long, long long); |
| 55 | bool (Thread::*pArtUnlockObject)(struct Thread*, struct Object*); |
| 56 | bool (Thread::*pArtCanPutArrayElementNoThrow)(const struct ClassObject*, |
| 57 | const struct ClassObject*); |
| 58 | int (Thread::*pArtInstanceofNonTrivialNoThrow) |
| 59 | (const struct ClassObject*, const struct ClassObject*); |
| 60 | int (Thread::*pArtInstanceofNonTrivial) (const struct ClassObject*, |
| 61 | const struct ClassObject*); |
| 62 | struct Method* (Thread::*pArtFindInterfaceMethodInCache)(ClassObject*, uint32_t, |
| 63 | const struct Method*, struct DvmDex*); |
| 64 | bool (Thread::*pArtUnlockObjectNoThrow)(struct Thread*, struct Object*); |
| 65 | void (Thread::*pArtLockObjectNoThrow)(struct Thread*, struct Object*); |
| 66 | struct Object* (Thread::*pArtAllocObjectNoThrow)(struct ClassObject*, int); |
| 67 | void (Thread::*pArtThrowException)(struct Thread*, struct Object*); |
| 68 | bool (Thread::*pArtHandleFillArrayDataNoThrow)(struct ArrayObject*, const uint16_t*); |
| 69 | #endif |
| 70 | } |
| 71 | |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 72 | Mutex* Mutex::Create(const char* name) { |
| 73 | Mutex* mu = new Mutex(name); |
| 74 | int result = pthread_mutex_init(&mu->lock_impl_, NULL); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 75 | CHECK_EQ(0, result); |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 76 | return mu; |
| 77 | } |
| 78 | |
| 79 | void Mutex::Lock() { |
| 80 | int result = pthread_mutex_lock(&lock_impl_); |
| 81 | CHECK_EQ(result, 0); |
| 82 | SetOwner(Thread::Current()); |
| 83 | } |
| 84 | |
| 85 | bool Mutex::TryLock() { |
| 86 | int result = pthread_mutex_lock(&lock_impl_); |
| 87 | if (result == EBUSY) { |
| 88 | return false; |
| 89 | } else { |
| 90 | CHECK_EQ(result, 0); |
| 91 | SetOwner(Thread::Current()); |
| 92 | return true; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | void Mutex::Unlock() { |
| 97 | CHECK(GetOwner() == Thread::Current()); |
| 98 | int result = pthread_mutex_unlock(&lock_impl_); |
| 99 | CHECK_EQ(result, 0); |
Elliott Hughes | f4c21c9 | 2011-08-19 17:31:31 -0700 | [diff] [blame] | 100 | SetOwner(NULL); |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Shih-wei Liao | 1a18c8c | 2011-08-14 17:47:36 -0700 | [diff] [blame] | 103 | void Frame::Next() { |
| 104 | byte* next_sp = reinterpret_cast<byte*>(sp_) + |
| 105 | GetMethod()->GetFrameSize(); |
| 106 | sp_ = reinterpret_cast<const Method**>(next_sp); |
| 107 | } |
| 108 | |
| 109 | void* Frame::GetPC() const { |
| 110 | byte* pc_addr = reinterpret_cast<byte*>(sp_) + |
Ian Rogers | 762400c | 2011-08-23 12:14:16 -0700 | [diff] [blame] | 111 | GetMethod()->GetReturnPcOffset(); |
Shih-wei Liao | 1a18c8c | 2011-08-14 17:47:36 -0700 | [diff] [blame] | 112 | return reinterpret_cast<void*>(pc_addr); |
| 113 | } |
| 114 | |
| 115 | const Method* Frame::NextMethod() const { |
| 116 | byte* next_sp = reinterpret_cast<byte*>(sp_) + |
| 117 | GetMethod()->GetFrameSize(); |
| 118 | return reinterpret_cast<const Method*>(next_sp); |
| 119 | } |
| 120 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 121 | void* ThreadStart(void *arg) { |
Elliott Hughes | 53b6131 | 2011-08-12 18:28:20 -0700 | [diff] [blame] | 122 | UNIMPLEMENTED(FATAL); |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 123 | return NULL; |
| 124 | } |
| 125 | |
Brian Carlstrom | b765be0 | 2011-08-17 23:54:10 -0700 | [diff] [blame] | 126 | Thread* Thread::Create(const Runtime* runtime) { |
| 127 | size_t stack_size = runtime->GetStackSize(); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 128 | scoped_ptr<MemMap> stack(MemMap::Map(stack_size, PROT_READ | PROT_WRITE)); |
Brian Carlstrom | b765be0 | 2011-08-17 23:54:10 -0700 | [diff] [blame] | 129 | if (stack == NULL) { |
| 130 | LOG(FATAL) << "failed to allocate thread stack"; |
| 131 | // notreached |
| 132 | return NULL; |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | Thread* new_thread = new Thread; |
Ian Rogers | 176f59c | 2011-07-20 13:14:11 -0700 | [diff] [blame] | 136 | new_thread->InitCpu(); |
Brian Carlstrom | b765be0 | 2011-08-17 23:54:10 -0700 | [diff] [blame] | 137 | new_thread->stack_.reset(stack.release()); |
| 138 | // Since stacks are assumed to grown downward the base is the limit and the limit is the base. |
| 139 | new_thread->stack_limit_ = stack->GetAddress(); |
| 140 | new_thread->stack_base_ = stack->GetLimit(); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 141 | |
| 142 | pthread_attr_t attr; |
| 143 | int result = pthread_attr_init(&attr); |
| 144 | CHECK_EQ(result, 0); |
| 145 | |
| 146 | result = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 147 | CHECK_EQ(result, 0); |
| 148 | |
| 149 | pthread_t handle; |
| 150 | result = pthread_create(&handle, &attr, ThreadStart, new_thread); |
| 151 | CHECK_EQ(result, 0); |
| 152 | |
| 153 | result = pthread_attr_destroy(&attr); |
| 154 | CHECK_EQ(result, 0); |
| 155 | |
| 156 | return new_thread; |
| 157 | } |
| 158 | |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 159 | Thread* Thread::Attach(const Runtime* runtime) { |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 160 | Thread* thread = new Thread; |
Ian Rogers | 176f59c | 2011-07-20 13:14:11 -0700 | [diff] [blame] | 161 | thread->InitCpu(); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 162 | thread->stack_limit_ = reinterpret_cast<byte*>(-1); // TODO: getrlimit |
| 163 | uintptr_t addr = reinterpret_cast<uintptr_t>(&thread); // TODO: ask pthreads |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 164 | uintptr_t stack_base = RoundUp(addr, kPageSize); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 165 | thread->stack_base_ = reinterpret_cast<byte*>(stack_base); |
| 166 | // TODO: set the stack size |
| 167 | |
| 168 | thread->handle_ = pthread_self(); |
| 169 | |
| 170 | thread->state_ = kRunnable; |
| 171 | |
Elliott Hughes | a5780da | 2011-07-17 11:39:39 -0700 | [diff] [blame] | 172 | errno = pthread_setspecific(Thread::pthread_key_self_, thread); |
| 173 | if (errno != 0) { |
| 174 | PLOG(FATAL) << "pthread_setspecific failed"; |
| 175 | } |
| 176 | |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 177 | JavaVMExt* vm = runtime->GetJavaVM(); |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 178 | CHECK(vm != NULL); |
| 179 | bool check_jni = vm->check_jni; |
| 180 | thread->jni_env_ = reinterpret_cast<JNIEnv*>(new JNIEnvExt(thread, check_jni)); |
Elliott Hughes | 330304d | 2011-08-12 14:28:05 -0700 | [diff] [blame] | 181 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 182 | return thread; |
| 183 | } |
| 184 | |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 185 | static void ThreadExitCheck(void* arg) { |
| 186 | LG << "Thread exit check"; |
| 187 | } |
| 188 | |
| 189 | bool Thread::Init() { |
| 190 | // Allocate a TLS slot. |
| 191 | if (pthread_key_create(&Thread::pthread_key_self_, ThreadExitCheck) != 0) { |
Elliott Hughes | eb4f614 | 2011-07-15 17:43:51 -0700 | [diff] [blame] | 192 | PLOG(WARNING) << "pthread_key_create failed"; |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 193 | return false; |
| 194 | } |
| 195 | |
| 196 | // Double-check the TLS slot allocation. |
| 197 | if (pthread_getspecific(pthread_key_self_) != NULL) { |
Elliott Hughes | eb4f614 | 2011-07-15 17:43:51 -0700 | [diff] [blame] | 198 | LOG(WARNING) << "newly-created pthread TLS slot is not NULL"; |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 199 | return false; |
| 200 | } |
| 201 | |
| 202 | // TODO: initialize other locks and condition variables |
| 203 | |
| 204 | return true; |
| 205 | } |
| 206 | |
Ian Rogers | a8cd9f4 | 2011-08-19 16:43:41 -0700 | [diff] [blame] | 207 | size_t Thread::NumShbHandles() { |
| 208 | size_t count = 0; |
| 209 | for (StackHandleBlock* cur = top_shb_; cur; cur = cur->Link()) { |
| 210 | count += cur->NumberOfReferences(); |
| 211 | } |
| 212 | return count; |
| 213 | } |
| 214 | |
| 215 | bool Thread::ShbContains(jobject obj) { |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 216 | Object** shb_entry = reinterpret_cast<Object**>(obj); |
Ian Rogers | a8cd9f4 | 2011-08-19 16:43:41 -0700 | [diff] [blame] | 217 | for (StackHandleBlock* cur = top_shb_; cur; cur = cur->Link()) { |
| 218 | size_t num_refs = cur->NumberOfReferences(); |
| 219 | DCHECK_GT(num_refs, 0u); // A SHB should always have a jobject/jclass |
| 220 | if ((&cur->Handles()[0] >= shb_entry) && |
| 221 | (shb_entry <= (&cur->Handles()[num_refs-1]))) { |
| 222 | return true; |
| 223 | } |
| 224 | } |
| 225 | return false; |
| 226 | } |
| 227 | |
Elliott Hughes | e5b0dc8 | 2011-08-23 09:59:02 -0700 | [diff] [blame] | 228 | void Thread::ThrowNewException(const char* exception_class_descriptor, const char* fmt, ...) { |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 229 | std::string msg; |
Elliott Hughes | a5b897e | 2011-08-16 11:33:06 -0700 | [diff] [blame] | 230 | va_list args; |
| 231 | va_start(args, fmt); |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 232 | StringAppendV(&msg, fmt, args); |
Elliott Hughes | a5b897e | 2011-08-16 11:33:06 -0700 | [diff] [blame] | 233 | va_end(args); |
Elliott Hughes | 37f7a40 | 2011-08-22 18:56:01 -0700 | [diff] [blame] | 234 | |
Elliott Hughes | e5b0dc8 | 2011-08-23 09:59:02 -0700 | [diff] [blame] | 235 | // Convert "Ljava/lang/Exception;" into JNI-style "java/lang/Exception". |
| 236 | CHECK(exception_class_descriptor[0] == 'L'); |
| 237 | std::string descriptor(exception_class_descriptor + 1); |
| 238 | CHECK(descriptor[descriptor.length() - 1] == ';'); |
| 239 | descriptor.erase(descriptor.length() - 1); |
| 240 | |
| 241 | JNIEnv* env = GetJniEnv(); |
| 242 | jclass exception_class = env->FindClass(descriptor.c_str()); |
| 243 | CHECK(exception_class != NULL) << "descriptor=\"" << descriptor << "\""; |
| 244 | int rc = env->ThrowNew(exception_class, msg.c_str()); |
| 245 | CHECK_EQ(rc, JNI_OK); |
Elliott Hughes | a5b897e | 2011-08-16 11:33:06 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Shih-wei Liao | 1a18c8c | 2011-08-14 17:47:36 -0700 | [diff] [blame] | 248 | Frame Thread::FindExceptionHandler(void* throw_pc, void** handler_pc) { |
| 249 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 250 | DCHECK(class_linker != NULL); |
| 251 | |
| 252 | Frame cur_frame = GetTopOfStack(); |
| 253 | for (int unwind_depth = 0; ; unwind_depth++) { |
| 254 | const Method* cur_method = cur_frame.GetMethod(); |
| 255 | DexCache* dex_cache = cur_method->GetDeclaringClass()->GetDexCache(); |
| 256 | const DexFile& dex_file = class_linker->FindDexFile(dex_cache); |
| 257 | |
| 258 | void* handler_addr = FindExceptionHandlerInMethod(cur_method, |
| 259 | throw_pc, |
| 260 | dex_file, |
| 261 | class_linker); |
| 262 | if (handler_addr) { |
| 263 | *handler_pc = handler_addr; |
| 264 | return cur_frame; |
| 265 | } else { |
| 266 | // Check if we are at the last frame |
| 267 | if (cur_frame.HasNext()) { |
| 268 | cur_frame.Next(); |
| 269 | } else { |
| 270 | // Either at the top of stack or next frame is native. |
| 271 | break; |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | *handler_pc = NULL; |
| 276 | return Frame(); |
| 277 | } |
| 278 | |
| 279 | void* Thread::FindExceptionHandlerInMethod(const Method* method, |
| 280 | void* throw_pc, |
| 281 | const DexFile& dex_file, |
| 282 | ClassLinker* class_linker) { |
Elliott Hughes | e5b0dc8 | 2011-08-23 09:59:02 -0700 | [diff] [blame] | 283 | Throwable* exception_obj = exception_; |
Shih-wei Liao | 1a18c8c | 2011-08-14 17:47:36 -0700 | [diff] [blame] | 284 | exception_ = NULL; |
| 285 | |
| 286 | intptr_t dex_pc = -1; |
| 287 | const DexFile::CodeItem* code_item = dex_file.GetCodeItem(method->code_off_); |
| 288 | DexFile::CatchHandlerIterator iter; |
| 289 | for (iter = dex_file.dexFindCatchHandler(*code_item, |
| 290 | method->ToDexPC(reinterpret_cast<intptr_t>(throw_pc))); |
| 291 | !iter.HasNext(); |
| 292 | iter.Next()) { |
| 293 | Class* klass = class_linker->FindSystemClass(dex_file.dexStringByTypeIdx(iter.Get().type_idx_)); |
| 294 | DCHECK(klass != NULL); |
| 295 | if (exception_obj->InstanceOf(klass)) { |
| 296 | dex_pc = iter.Get().address_; |
| 297 | break; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | exception_ = exception_obj; |
| 302 | if (iter.HasNext()) { |
| 303 | return NULL; |
| 304 | } else { |
| 305 | return reinterpret_cast<void*>( method->ToNativePC(dex_pc) ); |
| 306 | } |
| 307 | } |
| 308 | |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 309 | static const char* kStateNames[] = { |
| 310 | "New", |
| 311 | "Runnable", |
| 312 | "Blocked", |
| 313 | "Waiting", |
| 314 | "TimedWaiting", |
| 315 | "Native", |
| 316 | "Terminated", |
| 317 | }; |
| 318 | std::ostream& operator<<(std::ostream& os, const Thread::State& state) { |
| 319 | if (state >= Thread::kNew && state <= Thread::kTerminated) { |
| 320 | os << kStateNames[state-Thread::kNew]; |
| 321 | } else { |
| 322 | os << "State[" << static_cast<int>(state) << "]"; |
| 323 | } |
| 324 | return os; |
| 325 | } |
| 326 | |
Elliott Hughes | 330304d | 2011-08-12 14:28:05 -0700 | [diff] [blame] | 327 | std::ostream& operator<<(std::ostream& os, const Thread& thread) { |
| 328 | os << "Thread[" << &thread |
| 329 | << ",id=" << thread.GetId() |
| 330 | << ",tid=" << thread.GetNativeId() |
| 331 | << ",state=" << thread.GetState() << "]"; |
| 332 | return os; |
| 333 | } |
| 334 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 335 | ThreadList* ThreadList::Create() { |
| 336 | return new ThreadList; |
| 337 | } |
| 338 | |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 339 | ThreadList::ThreadList() { |
| 340 | lock_ = Mutex::Create("ThreadList::Lock"); |
| 341 | } |
| 342 | |
| 343 | ThreadList::~ThreadList() { |
| 344 | // Make sure that all threads have exited and unregistered when we |
| 345 | // reach this point. This means that all daemon threads had been |
| 346 | // shutdown cleanly. |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 347 | CHECK_LE(list_.size(), 1U); |
Carl Shapiro | 7a90959 | 2011-07-24 19:21:59 -0700 | [diff] [blame] | 348 | // TODO: wait for all other threads to unregister |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 349 | CHECK(list_.size() == 0 || list_.front() == Thread::Current()); |
Carl Shapiro | 7a90959 | 2011-07-24 19:21:59 -0700 | [diff] [blame] | 350 | // TODO: detach the current thread |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 351 | delete lock_; |
| 352 | lock_ = NULL; |
| 353 | } |
| 354 | |
| 355 | void ThreadList::Register(Thread* thread) { |
| 356 | MutexLock mu(lock_); |
| 357 | CHECK(find(list_.begin(), list_.end(), thread) == list_.end()); |
| 358 | list_.push_front(thread); |
| 359 | } |
| 360 | |
| 361 | void ThreadList::Unregister(Thread* thread) { |
| 362 | MutexLock mu(lock_); |
| 363 | CHECK(find(list_.begin(), list_.end(), thread) != list_.end()); |
| 364 | list_.remove(thread); |
| 365 | } |
| 366 | |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 367 | } // namespace |