Files
sdk/runtime/vm/native_message_handler.cc
T
sgjesse@google.com 42b70dcddb Change the thread interface in runtime/platform and use it starting all threads
The platform thread interface (dart::thread) is now refactored to an
all static interface as suggested by iposva@ and asiva@. Use this
interface for running all threads in the VM.

R=ager@google.com, iposva@google.com

BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com//9141005

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3830 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-02 08:59:26 +00:00

71 lines
1.9 KiB
C++

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/native_message_handler.h"
#include "vm/isolate.h"
#include "vm/message.h"
#include "vm/thread.h"
namespace dart {
NativeMessageHandler::NativeMessageHandler(const char* name,
Dart_NativeMessageHandler func)
: name_(strdup(name)),
func_(func) {
// A NativeMessageHandler always has one live port.
increment_live_ports();
}
NativeMessageHandler::~NativeMessageHandler() {
free(name_);
}
#if defined(DEBUG)
void NativeMessageHandler::CheckAccess() {
ASSERT(Isolate::Current() == NULL);
}
#endif
static void RunWorker(uword parameter) {
NativeMessageHandler* handler =
reinterpret_cast<NativeMessageHandler*>(parameter);
#if defined(DEBUG)
handler->CheckAccess();
#endif
while (handler->HasLivePorts()) {
Message* message = handler->queue()->Dequeue(0);
if (message != NULL) {
if (message->priority() >= Message::kOOBPriority) {
// TODO(turnidge): Out of band messages will not go through
// the regular message handler. Instead they will be
// dispatched to special vm code. Implement.
UNIMPLEMENTED();
}
// TODO(sgjesse): Once CMessageReader::ReadObject is committed,
// use that here and pass the resulting data object to the
// handler instead.
(*handler->func())(message->dest_port(),
message->reply_port(),
message->data());
delete message;
}
}
}
void NativeMessageHandler::StartWorker() {
int result = Thread::Start(RunWorker, reinterpret_cast<uword>(this));
if (result != 0) {
FATAL1("Failed to start native message handler worker thread %d", result);
}
}
} // namespace dart