OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009 Google Inc. All rights reserved. | 3 * Copyright (C) 2009 Google Inc. All rights reserved. |
4 * Copyright (C) 2009 Torch Mobile, Inc. All rights reserved. | 4 * Copyright (C) 2009 Torch Mobile, Inc. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * | 9 * |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 #include "wtf/MathExtras.h" | 100 #include "wtf/MathExtras.h" |
101 #include "wtf/OwnPtr.h" | 101 #include "wtf/OwnPtr.h" |
102 #include "wtf/PassOwnPtr.h" | 102 #include "wtf/PassOwnPtr.h" |
103 #include "wtf/RandomNumberSeed.h" | 103 #include "wtf/RandomNumberSeed.h" |
104 #include "wtf/WTFThreadData.h" | 104 #include "wtf/WTFThreadData.h" |
105 | 105 |
106 #if !USE(PTHREADS) && OS(WINDOWS) | 106 #if !USE(PTHREADS) && OS(WINDOWS) |
107 #include "ThreadSpecific.h" | 107 #include "ThreadSpecific.h" |
108 #endif | 108 #endif |
109 | 109 |
| 110 #include <errno.h> |
110 #include <process.h> | 111 #include <process.h> |
111 | 112 |
112 #if HAVE(ERRNO_H) | |
113 #include <errno.h> | |
114 #endif | |
115 | |
116 namespace WTF { | 113 namespace WTF { |
117 | 114 |
118 // MS_VC_EXCEPTION, THREADNAME_INFO, and setThreadNameInternal all come from <ht
tp://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx>. | 115 // MS_VC_EXCEPTION, THREADNAME_INFO, and setThreadNameInternal all come from <ht
tp://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx>. |
119 static const DWORD MS_VC_EXCEPTION = 0x406D1388; | 116 static const DWORD MS_VC_EXCEPTION = 0x406D1388; |
120 | 117 |
121 #pragma pack(push, 8) | 118 #pragma pack(push, 8) |
122 typedef struct tagTHREADNAME_INFO { | 119 typedef struct tagTHREADNAME_INFO { |
123 DWORD dwType; // must be 0x1000 | 120 DWORD dwType; // must be 0x1000 |
124 LPCSTR szName; // pointer to name (in user addr space) | 121 LPCSTR szName; // pointer to name (in user addr space) |
125 DWORD dwThreadID; // thread ID (-1=caller thread) | 122 DWORD dwThreadID; // thread ID (-1=caller thread) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 return 0; | 213 return 0; |
217 } | 214 } |
218 | 215 |
219 ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con
st char* threadName) | 216 ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con
st char* threadName) |
220 { | 217 { |
221 unsigned threadIdentifier = 0; | 218 unsigned threadIdentifier = 0; |
222 ThreadIdentifier threadID = 0; | 219 ThreadIdentifier threadID = 0; |
223 OwnPtr<ThreadFunctionInvocation> invocation = adoptPtr(new ThreadFunctionInv
ocation(entryPoint, data)); | 220 OwnPtr<ThreadFunctionInvocation> invocation = adoptPtr(new ThreadFunctionInv
ocation(entryPoint, data)); |
224 HANDLE threadHandle = reinterpret_cast<HANDLE>(_beginthreadex(0, 0, wtfThrea
dEntryPoint, invocation.get(), 0, &threadIdentifier)); | 221 HANDLE threadHandle = reinterpret_cast<HANDLE>(_beginthreadex(0, 0, wtfThrea
dEntryPoint, invocation.get(), 0, &threadIdentifier)); |
225 if (!threadHandle) { | 222 if (!threadHandle) { |
226 #if !HAVE(ERRNO_H) | |
227 LOG_ERROR("Failed to create thread at entry point %p with data %p.", ent
ryPoint, data); | |
228 #else | |
229 LOG_ERROR("Failed to create thread at entry point %p with data %p: %ld",
entryPoint, data, errno); | 223 LOG_ERROR("Failed to create thread at entry point %p with data %p: %ld",
entryPoint, data, errno); |
230 #endif | |
231 return 0; | 224 return 0; |
232 } | 225 } |
233 | 226 |
234 // The thread will take ownership of invocation. | 227 // The thread will take ownership of invocation. |
235 ThreadFunctionInvocation* leakedInvocation = invocation.leakPtr(); | 228 ThreadFunctionInvocation* leakedInvocation = invocation.leakPtr(); |
236 UNUSED_PARAM(leakedInvocation); | 229 UNUSED_PARAM(leakedInvocation); |
237 | 230 |
238 threadID = static_cast<ThreadIdentifier>(threadIdentifier); | 231 threadID = static_cast<ThreadIdentifier>(threadIdentifier); |
239 storeThreadHandleByIdentifier(threadIdentifier, threadHandle); | 232 storeThreadHandleByIdentifier(threadIdentifier, threadHandle); |
240 | 233 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 // Time is too far in the future (and would overflow unsigned long) - wait f
orever. | 491 // Time is too far in the future (and would overflow unsigned long) - wait f
orever. |
499 if (absoluteTime - currentTime > static_cast<double>(INT_MAX) / 1000.0) | 492 if (absoluteTime - currentTime > static_cast<double>(INT_MAX) / 1000.0) |
500 return INFINITE; | 493 return INFINITE; |
501 | 494 |
502 return static_cast<DWORD>((absoluteTime - currentTime) * 1000.0); | 495 return static_cast<DWORD>((absoluteTime - currentTime) * 1000.0); |
503 } | 496 } |
504 | 497 |
505 } // namespace WTF | 498 } // namespace WTF |
506 | 499 |
507 #endif // OS(WINDOWS) | 500 #endif // OS(WINDOWS) |
OLD | NEW |