Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
port.h
Go to the documentation of this file.
1// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
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.
4
5#ifndef RUNTIME_VM_PORT_H_
6#define RUNTIME_VM_PORT_H_
7
8#include <memory>
9
10#include "include/dart_api.h"
11#include "vm/allocation.h"
12#include "vm/globals.h"
13#include "vm/json_stream.h"
14#include "vm/port_set.h"
15#include "vm/random.h"
16
17namespace dart {
18
19class Isolate;
20class Message;
21class MessageHandler;
22class Mutex;
23
24class PortMap : public AllStatic {
25 public:
26 // Allocate a port for the provided handler and return its VM-global id.
27 static Dart_Port CreatePort(MessageHandler* handler);
28
29 // Close the port with id. All pending messages will be dropped.
30 //
31 // Returns true if the port is successfully closed.
32 static bool ClosePort(Dart_Port id,
33 MessageHandler** message_handler = nullptr);
34
35 // Close all the ports for the provided handler.
36 static void ClosePorts(MessageHandler* handler);
37
38 // Enqueues the message in the port with id. Returns false if the port is not
39 // active any longer.
40 //
41 // Claims ownership of 'message'.
42 static bool PostMessage(std::unique_ptr<Message> message,
43 bool before_events = false);
44
45 // Returns the owning Isolate for port 'id'.
46 static Isolate* GetIsolate(Dart_Port id);
47
48 // Returns the origin id for port 'id'.
50
51#if defined(TESTING)
52 static bool PortExists(Dart_Port id);
53 static bool HasPorts(MessageHandler* handler);
54#endif
55
56 // Whether the destination port's isolate is a member of [isolate_group].
58 IsolateGroup* group);
59
60 static void Init();
61 static void Cleanup();
62
64 JSONStream* stream);
65
66 static void DebugDumpForMessageHandler(MessageHandler* handler);
67
68 private:
69 struct Entry : public PortSet<Entry>::Entry {
70 Entry() : handler(nullptr) {}
71
72 MessageHandler* handler;
73 };
74
75 // Allocate a new unique port.
76 static Dart_Port AllocatePort();
77
78 // Lock protecting access to the port map.
79 static Mutex* mutex_;
80
81 static PortSet<Entry>* ports_;
82
83 static Random* prng_;
84};
85
86} // namespace dart
87
88#endif // RUNTIME_VM_PORT_H_
static Dart_Port GetOriginId(Dart_Port id)
Definition port.cc:196
static void DebugDumpForMessageHandler(MessageHandler *handler)
Definition port.cc:305
static Isolate * GetIsolate(Dart_Port id)
Definition port.cc:181
static void PrintPortsForMessageHandler(MessageHandler *handler, JSONStream *stream)
Definition port.cc:280
static bool ClosePort(Dart_Port id, MessageHandler **message_handler=nullptr)
Definition port.cc:90
static void Init()
Definition port.cc:248
static bool IsReceiverInThisIsolateGroupOrClosed(Dart_Port receiver, IsolateGroup *group)
Definition port.cc:228
static void ClosePorts(MessageHandler *handler)
Definition port.cc:128
static void Cleanup()
Definition port.cc:261
static Dart_Port CreatePort(MessageHandler *handler)
Definition port.cc:55
int64_t Dart_Port
Definition dart_api.h:1524
Win32Message message
std::function< void(const T &message, const MessageReply< T > &reply)> MessageHandler
#define PostMessage