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

Side by Side Diff: src/trusted/debug_stub/posix/thread_impl.cc

Issue 10365028: Debug stub: associate NaClAppThread with IThread (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Created 8 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 #include <stdexcept> 7 #include <stdexcept>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "native_client/src/shared/platform/nacl_log.h" 10 #include "native_client/src/shared/platform/nacl_log.h"
(...skipping 23 matching lines...) Expand all
34 return mutex_; 34 return mutex_;
35 } 35 }
36 36
37 static IThread::ThreadMap_t *ThreadGetMap() { 37 static IThread::ThreadMap_t *ThreadGetMap() {
38 static IThread::ThreadMap_t* map_ = new IThread::ThreadMap_t; 38 static IThread::ThreadMap_t* map_ = new IThread::ThreadMap_t;
39 return map_; 39 return map_;
40 } 40 }
41 41
42 class Thread : public IThread { 42 class Thread : public IThread {
43 public: 43 public:
44 explicit Thread(uint32_t id) : ref_(1), id_(id), state_(DEAD) {} 44 Thread(uint32_t id, struct NaClAppThread *natp)
45 : ref_(1), id_(id), natp_(natp), state_(DEAD) {}
45 ~Thread() {} 46 ~Thread() {}
46 47
47 uint32_t GetId() { 48 uint32_t GetId() {
48 return id_; 49 return id_;
49 } 50 }
50 51
51 State GetState() { 52 State GetState() {
52 return state_; 53 return state_;
53 } 54 }
54 55
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 return NACL_SIGNAL_RETURN; 118 return NACL_SIGNAL_RETURN;
118 } else { 119 } else {
119 // Do not attempt to debug crashes in trusted code. 120 // Do not attempt to debug crashes in trusted code.
120 return NACL_SIGNAL_SEARCH; 121 return NACL_SIGNAL_SEARCH;
121 } 122 }
122 } 123 }
123 124
124 private: 125 private:
125 uint32_t ref_; 126 uint32_t ref_;
126 uint32_t id_; 127 uint32_t id_;
128 struct NaClAppThread *natp_;
127 State state_; 129 State state_;
128 struct NaClSignalContext context_; 130 struct NaClSignalContext context_;
129 131
130 friend class IThread; 132 friend class IThread;
131 }; 133 };
132 134
133 // TODO(mseaborn): This is duplicated in the Windows version. 135 IThread* IThread::Create(uint32_t id, struct NaClAppThread* natp) {
Mark Seaborn 2012/05/07 21:56:49 This TODO should be kept with Create(), because it
eaeltsin 2012/05/08 11:10:19 Done.
Mark Seaborn 2012/05/07 21:56:49 '*' spacing style differs between here and above.
eaeltsin 2012/05/08 11:10:19 But if I change this, it will differ from below (w
134 IThread* IThread::Acquire(uint32_t id, bool create) {
135 MutexLock lock(ThreadGetLock()); 136 MutexLock lock(ThreadGetLock());
136 Thread* thread; 137 Thread* thread;
137 ThreadMap_t &map = *ThreadGetMap(); 138 ThreadMap_t &map = *ThreadGetMap();
138 139
139 // Check if we have that thread
140 if (map.count(id)) { 140 if (map.count(id)) {
141 thread = static_cast<Thread*>(map[id]); 141 NaClLog(LOG_ERROR, "IThread::Create: thread 0x%x already exists\n", id);
Mark Seaborn 2012/05/07 21:56:49 This should be LOG_FATAL because the callers are n
eaeltsin 2012/05/08 11:10:19 Done.
142 thread->ref_++; 142 return NULL;
143 return thread;
144 } 143 }
145 144
146 // If not, can we create it? 145 thread = new Thread(id, natp);
147 if (create) { 146 map[id] = thread;
148 // If not add it to the map 147 return thread;
149 thread = new Thread(id);
150 map[id] = thread;
151 return thread;
152 }
153
154 return NULL;
155 } 148 }
156 149
157 // TODO(mseaborn): This is duplicated in the Windows version. 150 // TODO(mseaborn): This is duplicated in the Windows version.
151 IThread* IThread::Acquire(uint32_t id) {
152 MutexLock lock(ThreadGetLock());
153 Thread* thread;
154 ThreadMap_t &map = *ThreadGetMap();
155
156 if (map.count(id) == 0) {
157 NaClLog(LOG_ERROR, "IThread::Acquire: thread 0x%x does not exist\n", id);
Mark Seaborn 2012/05/07 21:56:49 Shouldn't this be LOG_FATAL too? The callers aren
eaeltsin 2012/05/08 11:10:19 Done.
158 return NULL;
159 }
160
161 thread = static_cast<Thread*>(map[id]);
162 thread->ref_++;
163 return thread;
164 }
165
166 // TODO(mseaborn): This is duplicated in the Windows version.
158 void IThread::Release(IThread *ithread) { 167 void IThread::Release(IThread *ithread) {
159 MutexLock lock(ThreadGetLock()); 168 MutexLock lock(ThreadGetLock());
160 Thread* thread = static_cast<Thread*>(ithread); 169 Thread* thread = static_cast<Thread*>(ithread);
161 thread->ref_--; 170 thread->ref_--;
162 171
163 if (thread->ref_ == 0) { 172 if (thread->ref_ == 0) {
164 ThreadGetMap()->erase(thread->id_); 173 ThreadGetMap()->erase(thread->id_);
165 delete static_cast<IThread*>(thread); 174 delete static_cast<IThread*>(thread);
166 } 175 }
167 } 176 }
168 177
169 void IThread::SetExceptionCatch(IThread::CatchFunc_t func, void *cookie) { 178 void IThread::SetExceptionCatch(IThread::CatchFunc_t func, void *cookie) {
170 NaClSignalHandlerAdd(Thread::SignalHandler); 179 NaClSignalHandlerAdd(Thread::SignalHandler);
171 s_CatchFunc = func; 180 s_CatchFunc = func;
172 s_CatchCookie = cookie; 181 s_CatchCookie = cookie;
173 } 182 }
174 183
175 184
176 } // End of port namespace 185 } // End of port namespace
177 186
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698