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

Side by Side Diff: runtime/vm/native_message_handler.cc

Issue 9924015: Use the ThreadPool for all isolates and native ports. Previously, (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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
« no previous file with comments | « runtime/vm/native_message_handler.h ('k') | runtime/vm/port.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/native_message_handler.h" 5 #include "vm/native_message_handler.h"
6 6
7 #include "vm/dart_api_message.h" 7 #include "vm/dart_api_message.h"
8 #include "vm/isolate.h" 8 #include "vm/isolate.h"
9 #include "vm/message.h" 9 #include "vm/message.h"
10 #include "vm/snapshot.h" 10 #include "vm/snapshot.h"
(...skipping 23 matching lines...) Expand all
34 34
35 35
36 static uint8_t* zone_allocator( 36 static uint8_t* zone_allocator(
37 uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 37 uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
38 ApiZone* zone = ApiNativeScope::Current()->zone(); 38 ApiZone* zone = ApiNativeScope::Current()->zone();
39 return reinterpret_cast<uint8_t*>( 39 return reinterpret_cast<uint8_t*>(
40 zone->Reallocate(reinterpret_cast<uword>(ptr), old_size, new_size)); 40 zone->Reallocate(reinterpret_cast<uword>(ptr), old_size, new_size));
41 } 41 }
42 42
43 43
44 static void RunWorker(uword parameter) { 44 bool NativeMessageHandler::HandleMessage(Message* message) {
45 NativeMessageHandler* handler = 45 if (message->IsOOB()) {
46 reinterpret_cast<NativeMessageHandler*>(parameter); 46 // We currently do not use OOB messages for native ports.
47 #if defined(DEBUG) 47 UNREACHABLE();
48 handler->CheckAccess(); 48 }
49 #endif 49 // Enter a native scope for handling the message. This will create a
50 // zone for allocating the objects for decoding the message.
51 ApiNativeScope scope;
50 52
51 while (handler->HasLivePorts()) { 53 int32_t length = reinterpret_cast<int32_t*>(
52 Message* message = handler->queue()->Dequeue(0); 54 message->data())[Snapshot::kLengthIndex];
53 if (message != NULL) { 55 ApiMessageReader reader(message->data() + Snapshot::kHeaderSize,
54 if (message->priority() >= Message::kOOBPriority) { 56 length,
55 // TODO(turnidge): Out of band messages will not go through 57 zone_allocator);
56 // the regular message handler. Instead they will be 58 Dart_CObject* object = reader.ReadMessage();
57 // dispatched to special vm code. Implement. 59 (*func())(message->dest_port(), message->reply_port(), object);
58 UNIMPLEMENTED(); 60 delete message;
59 } 61 return true;
60 // Enter a native scope for handling the message. This will create a
61 // zone for allocating the objects for decoding the message.
62 ApiNativeScope scope;
63
64 int32_t length = reinterpret_cast<int32_t*>(
65 message->data())[Snapshot::kLengthIndex];
66 ApiMessageReader reader(message->data() + Snapshot::kHeaderSize,
67 length,
68 zone_allocator);
69 Dart_CObject* object = reader.ReadMessage();
70 (*handler->func())(message->dest_port(),
71 message->reply_port(),
72 object);
73 delete message;
74 }
75 }
76 } 62 }
77 63
78
79 void NativeMessageHandler::StartWorker() {
80 int result = Thread::Start(RunWorker, reinterpret_cast<uword>(this));
81 if (result != 0) {
82 FATAL1("Failed to start native message handler worker thread %d", result);
83 }
84 }
85
86
87 } // namespace dart 64 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/native_message_handler.h ('k') | runtime/vm/port.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698