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

Side by Side Diff: webkit/port/bindings/v8/Threading.cpp

Issue 17246: Add V8 bindings for Worker (Part I). (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 11 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
(Empty)
1 // Copyright (c) 2009, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
31 #include "Threading.h"
32 #undef LOG
33
34 #include "base/message_loop.h"
35 #include "base/task.h"
36
37 namespace WTF {
38
39 struct NewThreadContext {
40 NewThreadContext(ThreadFunction entryPoint, void* data, const char* name)
41 : entryPoint(entryPoint)
42 , data(data)
43 , name(name)
44 { }
45
46 ThreadFunction entryPoint;
47 void* data;
48 std::string name;
49
50 Mutex creationMutex;
51 };
52
53 static void* threadEntryPoint(void* contextData)
54 {
55 NewThreadContext* context = reinterpret_cast<NewThreadContext*>(contextData) ;
56
57 // Block until our creating thread has completed any extra setup work
58 {
59 MutexLocker locker(context->creationMutex);
60 }
61
62 // Run via Chrome's message loop
63 MessageLoop message_loop;
64 message_loop.set_thread_name(context->name);
65 message_loop.PostTask(FROM_HERE,
66 NewRunnableFunction(context->entryPoint, context->data ));
67 message_loop.Run();
68
69 delete context;
70
71 return NULL;
72 }
73
74 ThreadIdentifier createThread(ThreadFunction entryPoint, void* data, const char* name)
75 {
76 NewThreadContext* context = new NewThreadContext(entryPoint, data, name);
77
78 // Prevent the thread body from executing until we've established the thread identifier
79 MutexLocker locker(context->creationMutex);
80
81 return createThreadInternal(threadEntryPoint, context, name);
82 }
83
84 #if PLATFORM(MAC) || PLATFORM(WIN)
85
86 // This function is deprecated but needs to be kept around for backward
87 // compatibility. Use the 3-argument version of createThread above.
88
89 ThreadIdentifier createThread(ThreadFunction entryPoint, void* data)
90 {
91 return createThread(entryPoint, data, 0);
92 }
93 #endif
94
95 } // namespace WTF
OLDNEW
« no previous file with comments | « webkit/port/bindings/scripts/CodeGeneratorV8.pm ('k') | webkit/port/bindings/v8/V8WorkerCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698