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

Side by Side Diff: runtime/vm/port.h

Issue 456983002: Refactor isolate startup code in preparation for making isolate spawning more truly non-blocking. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 4 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/object.cc ('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) 2011, the Dart project authors. Please see the AUTHORS 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 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 #ifndef VM_PORT_H_ 5 #ifndef VM_PORT_H_
6 #define VM_PORT_H_ 6 #define VM_PORT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "vm/allocation.h" 9 #include "vm/allocation.h"
10 #include "vm/globals.h" 10 #include "vm/globals.h"
11 #include "vm/random.h" 11 #include "vm/random.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 class Isolate; 15 class Isolate;
16 class Message; 16 class Message;
17 class MessageHandler; 17 class MessageHandler;
18 class Mutex; 18 class Mutex;
19 class PortMapTestPeer; 19 class PortMapTestPeer;
20 20
21 class PortMap: public AllStatic { 21 class PortMap: public AllStatic {
22 public: 22 public:
23 enum PortState {
24 kNewPort = 0, // a newly allocated port
25 kLivePort = 1, // a regular port (has a ReceivePort)
26 kControlPort = 2, // a special control port (has a ReceivePort)
27 };
28
23 // Allocate a port for the provided handler and return its VM-global id. 29 // Allocate a port for the provided handler and return its VM-global id.
24 static Dart_Port CreatePort(MessageHandler* handler); 30 static Dart_Port CreatePort(MessageHandler* handler);
25 31
26 // Indicates that a port has had a ReceivePort created for it at the 32 // Indicates that a port has had a ReceivePort created for it at the
27 // dart language level. The port remains live until it is closed. 33 // dart language level. The port remains live until it is closed.
28 static void SetLive(Dart_Port id); 34 static void SetPortState(Dart_Port id, PortState kind);
29 35
30 // Close the port with id. All pending messages will be dropped. 36 // Close the port with id. All pending messages will be dropped.
31 // 37 //
32 // Returns true if the port is successfully closed. 38 // Returns true if the port is successfully closed.
33 static bool ClosePort(Dart_Port id); 39 static bool ClosePort(Dart_Port id);
34 40
35 // Close all the ports for the provided handler. 41 // Close all the ports for the provided handler.
36 static void ClosePorts(MessageHandler* handler); 42 static void ClosePorts(MessageHandler* handler);
37 43
38 // Enqueues the message in the port with id. Returns false if the port is not 44 // Enqueues the message in the port with id. Returns false if the port is not
(...skipping 13 matching lines...) Expand all
52 private: 58 private:
53 friend class dart::PortMapTestPeer; 59 friend class dart::PortMapTestPeer;
54 60
55 // Mapping between port numbers and handlers. 61 // Mapping between port numbers and handlers.
56 // 62 //
57 // Free entries have id == 0 and handler == NULL. Deleted entries 63 // Free entries have id == 0 and handler == NULL. Deleted entries
58 // have id == 0 and handler == deleted_entry_. 64 // have id == 0 and handler == deleted_entry_.
59 typedef struct { 65 typedef struct {
60 Dart_Port port; 66 Dart_Port port;
61 MessageHandler* handler; 67 MessageHandler* handler;
62 bool live; 68 PortState state;
63 } Entry; 69 } Entry;
64 70
71 static const char* PortStateString(PortState state);
72
65 // Allocate a new unique port. 73 // Allocate a new unique port.
66 static Dart_Port AllocatePort(); 74 static Dart_Port AllocatePort();
67 75
68 static bool IsActivePort(Dart_Port id); 76 static bool IsActivePort(Dart_Port id);
69 static bool IsLivePort(Dart_Port id); 77 static bool IsLivePort(Dart_Port id);
70 78
71 static intptr_t FindPort(Dart_Port port); 79 static intptr_t FindPort(Dart_Port port);
72 static void Rehash(intptr_t new_capacity); 80 static void Rehash(intptr_t new_capacity);
73 81
74 static void MaintainInvariants(); 82 static void MaintainInvariants();
75 83
76 // Lock protecting access to the port map. 84 // Lock protecting access to the port map.
77 static Mutex* mutex_; 85 static Mutex* mutex_;
78 86
79 // Hashmap of ports. 87 // Hashmap of ports.
80 static Entry* map_; 88 static Entry* map_;
81 static MessageHandler* deleted_entry_; 89 static MessageHandler* deleted_entry_;
82 static intptr_t capacity_; 90 static intptr_t capacity_;
83 static intptr_t used_; 91 static intptr_t used_;
84 static intptr_t deleted_; 92 static intptr_t deleted_;
85 93
86 static Random* prng_; 94 static Random* prng_;
87 }; 95 };
88 96
89 } // namespace dart 97 } // namespace dart
90 98
91 #endif // VM_PORT_H_ 99 #endif // VM_PORT_H_
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/port.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698