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 #if !OS(WINCE) | |
111 #include <process.h> | 110 #include <process.h> |
112 #endif | |
113 | 111 |
114 #if HAVE(ERRNO_H) | 112 #if HAVE(ERRNO_H) |
115 #include <errno.h> | 113 #include <errno.h> |
116 #endif | 114 #endif |
117 | 115 |
118 namespace WTF { | 116 namespace WTF { |
119 | 117 |
120 // MS_VC_EXCEPTION, THREADNAME_INFO, and setThreadNameInternal all come from <ht
tp://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx>. | 118 // MS_VC_EXCEPTION, THREADNAME_INFO, and setThreadNameInternal all come from <ht
tp://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx>. |
121 static const DWORD MS_VC_EXCEPTION = 0x406D1388; | 119 static const DWORD MS_VC_EXCEPTION = 0x406D1388; |
122 | 120 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 #endif | 219 #endif |
222 | 220 |
223 return 0; | 221 return 0; |
224 } | 222 } |
225 | 223 |
226 ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con
st char* threadName) | 224 ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con
st char* threadName) |
227 { | 225 { |
228 unsigned threadIdentifier = 0; | 226 unsigned threadIdentifier = 0; |
229 ThreadIdentifier threadID = 0; | 227 ThreadIdentifier threadID = 0; |
230 OwnPtr<ThreadFunctionInvocation> invocation = adoptPtr(new ThreadFunctionInv
ocation(entryPoint, data)); | 228 OwnPtr<ThreadFunctionInvocation> invocation = adoptPtr(new ThreadFunctionInv
ocation(entryPoint, data)); |
231 #if OS(WINCE) | |
232 // This is safe on WINCE, since CRT is in the core and innately multithreade
d. | |
233 // On desktop Windows, need to use _beginthreadex (not available on WinCE) i
f using any CRT functions | |
234 HANDLE threadHandle = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)wtfThreadEn
tryPoint, invocation.get(), 0, (LPDWORD)&threadIdentifier); | |
235 #else | |
236 HANDLE threadHandle = reinterpret_cast<HANDLE>(_beginthreadex(0, 0, wtfThrea
dEntryPoint, invocation.get(), 0, &threadIdentifier)); | 229 HANDLE threadHandle = reinterpret_cast<HANDLE>(_beginthreadex(0, 0, wtfThrea
dEntryPoint, invocation.get(), 0, &threadIdentifier)); |
237 #endif | |
238 if (!threadHandle) { | 230 if (!threadHandle) { |
239 #if OS(WINCE) | 231 #if !HAVE(ERRNO_H) |
240 LOG_ERROR("Failed to create thread at entry point %p with data %p: %ld",
entryPoint, data, ::GetLastError()); | |
241 #elif !HAVE(ERRNO_H) | |
242 LOG_ERROR("Failed to create thread at entry point %p with data %p.", ent
ryPoint, data); | 232 LOG_ERROR("Failed to create thread at entry point %p with data %p.", ent
ryPoint, data); |
243 #else | 233 #else |
244 LOG_ERROR("Failed to create thread at entry point %p with data %p: %ld",
entryPoint, data, errno); | 234 LOG_ERROR("Failed to create thread at entry point %p with data %p: %ld",
entryPoint, data, errno); |
245 #endif | 235 #endif |
246 return 0; | 236 return 0; |
247 } | 237 } |
248 | 238 |
249 // The thread will take ownership of invocation. | 239 // The thread will take ownership of invocation. |
250 ThreadFunctionInvocation* leakedInvocation = invocation.leakPtr(); | 240 ThreadFunctionInvocation* leakedInvocation = invocation.leakPtr(); |
251 UNUSED_PARAM(leakedInvocation); | 241 UNUSED_PARAM(leakedInvocation); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 // Time is too far in the future (and would overflow unsigned long) - wait f
orever. | 503 // Time is too far in the future (and would overflow unsigned long) - wait f
orever. |
514 if (absoluteTime - currentTime > static_cast<double>(INT_MAX) / 1000.0) | 504 if (absoluteTime - currentTime > static_cast<double>(INT_MAX) / 1000.0) |
515 return INFINITE; | 505 return INFINITE; |
516 | 506 |
517 return static_cast<DWORD>((absoluteTime - currentTime) * 1000.0); | 507 return static_cast<DWORD>((absoluteTime - currentTime) * 1000.0); |
518 } | 508 } |
519 | 509 |
520 } // namespace WTF | 510 } // namespace WTF |
521 | 511 |
522 #endif // OS(WINDOWS) | 512 #endif // OS(WINDOWS) |
OLD | NEW |