OLD | NEW |
---|---|
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 // This is called during exit, at which point apparently no NSAutoreleasePools | 67 // This is called during exit, at which point apparently no NSAutoreleasePools |
68 // are available; but we might still need them to do cleanup (or we get the | 68 // are available; but we might still need them to do cleanup (or we get the |
69 // "no autoreleasepool in place, just leaking" warning when exiting). | 69 // "no autoreleasepool in place, just leaking" warning when exiting). |
70 ScopedAutoreleasePool pool; | 70 ScopedAutoreleasePool pool; |
71 #endif | 71 #endif |
72 UnwrapCurrentThread(); | 72 UnwrapCurrentThread(); |
73 pthread_key_delete(key_); | 73 pthread_key_delete(key_); |
74 } | 74 } |
75 | 75 |
76 Thread *ThreadManager::CurrentThread() { | 76 Thread *ThreadManager::CurrentThread() { |
77 return static_cast<Thread *>(pthread_getspecific(key_)); | 77 return static_cast<Thread *>(pthread_getspecific(key_)); |
tommi (sloooow) - chröme
2012/02/28 21:32:18
nit: looks like all the casts in this file to Thre
Ronghua Wu (Left Chromium)
2012/02/28 23:16:57
True, but trying not to involve too much changes i
| |
78 } | 78 } |
79 | 79 |
80 void ThreadManager::SetCurrentThread(Thread *thread) { | 80 void ThreadManager::SetCurrentThread(Thread *thread) { |
81 pthread_setspecific(key_, thread); | 81 pthread_setspecific(key_, thread); |
82 } | 82 } |
83 #endif | 83 #endif |
84 | 84 |
85 #ifdef WIN32 | 85 #ifdef WIN32 |
86 ThreadManager::ThreadManager() { | 86 ThreadManager::ThreadManager() { |
87 key_ = TlsAlloc(); | 87 key_ = TlsAlloc(); |
88 WrapCurrentThread(); | |
89 } | 88 } |
90 | 89 |
91 ThreadManager::~ThreadManager() { | 90 ThreadManager::~ThreadManager() { |
92 UnwrapCurrentThread(); | 91 UnwrapCurrentThread(); |
93 TlsFree(key_); | 92 TlsFree(key_); |
94 } | 93 } |
95 | 94 |
96 Thread *ThreadManager::CurrentThread() { | 95 Thread *ThreadManager::CurrentThread() { |
97 return static_cast<Thread *>(TlsGetValue(key_)); | 96 return static_cast<Thread *>(TlsGetValue(key_)); |
98 } | 97 } |
(...skipping 20 matching lines...) Expand all Loading... | |
119 t->UnwrapCurrent(); | 118 t->UnwrapCurrent(); |
120 delete t; | 119 delete t; |
121 } | 120 } |
122 } | 121 } |
123 | 122 |
124 struct ThreadInit { | 123 struct ThreadInit { |
125 Thread* thread; | 124 Thread* thread; |
126 Runnable* runnable; | 125 Runnable* runnable; |
127 }; | 126 }; |
128 | 127 |
128 Thread::Thread() | |
129 : MessageQueue() { | |
130 Construct(); | |
131 } | |
132 | |
129 Thread::Thread(SocketServer* ss) | 133 Thread::Thread(SocketServer* ss) |
130 : MessageQueue(ss), | 134 : MessageQueue(ss) { |
131 priority_(PRIORITY_NORMAL), | 135 Construct(); |
132 started_(false), | 136 } |
133 has_sends_(false), | 137 |
138 void Thread::Construct() { | |
139 priority_ = PRIORITY_NORMAL; | |
140 started_ = false; | |
141 has_sends_ = false; | |
134 #if defined(WIN32) | 142 #if defined(WIN32) |
135 thread_(NULL), | 143 thread_ = NULL; |
136 #endif | 144 #endif |
137 owned_(true), | 145 owned_ = true; |
138 delete_self_when_complete_(false) { | 146 delete_self_when_complete_ = false; |
139 SetName("Thread", this); // default name | 147 SetName("Thread", this); // default name |
140 } | 148 } |
141 | 149 |
142 Thread::~Thread() { | 150 Thread::~Thread() { |
143 Stop(); | 151 Stop(); |
144 if (active_) | 152 if (active_) |
145 Clear(NULL); | 153 Clear(NULL); |
146 } | 154 } |
147 | 155 |
148 bool Thread::SleepMs(int milliseconds) { | 156 bool Thread::SleepMs(int milliseconds) { |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 if (SUCCEEDED(hr)) { | 552 if (SUCCEEDED(hr)) { |
545 Thread::Run(); | 553 Thread::Run(); |
546 CoUninitialize(); | 554 CoUninitialize(); |
547 } else { | 555 } else { |
548 LOG(LS_ERROR) << "CoInitialize failed, hr=" << hr; | 556 LOG(LS_ERROR) << "CoInitialize failed, hr=" << hr; |
549 } | 557 } |
550 } | 558 } |
551 #endif | 559 #endif |
552 | 560 |
553 } // namespace talk_base | 561 } // namespace talk_base |
OLD | NEW |