Skip to content

Commit bbcc9ba

Browse files
jason-simmonsCommit Queue
authored andcommitted
[dart:io] Update dart::bin::CleanupDartIo and no-SSL mode to support recent changes to IOService
https://dart-review.googlesource.com/c/sdk/+/437160 changed how the IOService port is created. The Flutter engine calls dart::bin::CleanupDartIo during shutdown of the Dart VM. That API now needs to clean up the IOService. This PR also adds support for the IOService port change when building Dart with secure sockets disabled. TEST=building the Flutter engine Change-Id: I2d61713cfbe3feddb7d361605c25229d05dd61a3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438605 Reviewed-by: Alexander Markov <[email protected]> Reviewed-by: Siva Annamalai <[email protected]> Commit-Queue: Jason Simmons <[email protected]>
1 parent 1d5b271 commit bbcc9ba

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

runtime/bin/dart_embedder_api_impl.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
#include "bin/dartutils.h"
88
#include "bin/eventhandler.h"
9+
#if defined(DART_IO_SECURE_SOCKET_DISABLED)
10+
#include "bin/io_service_no_ssl.h"
11+
#else // defined(DART_IO_SECURE_SOCKET_DISABLED)
912
#include "bin/io_service.h"
13+
#endif // defined(DART_IO_SECURE_SOCKET_DISABLED)
1014
#include "bin/isolate_data.h"
1115
#include "bin/process.h"
1216
#include "bin/secure_socket_filter.h"

runtime/bin/dart_io_api_impl.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
#include "bin/directory.h"
99
#include "bin/eventhandler.h"
1010
#include "bin/io_natives.h"
11+
#if defined(DART_IO_SECURE_SOCKET_DISABLED)
12+
#include "bin/io_service_no_ssl.h"
13+
#else // defined(DART_IO_SECURE_SOCKET_DISABLED)
14+
#include "bin/io_service.h"
15+
#endif // defined(DART_IO_SECURE_SOCKET_DISABLED)
1116
#include "bin/platform.h"
1217
#include "bin/process.h"
1318
#if !defined(DART_IO_SECURE_SOCKET_DISABLED)
@@ -36,6 +41,7 @@ void CleanupDartIo() {
3641
SSLFilter::Cleanup();
3742
#endif
3843
Process::Cleanup();
44+
IOService::Cleanup();
3945
}
4046

4147
void SetSystemTempDirectory(const char* system_temp) {

runtime/bin/io_service_no_ssl.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,22 @@ void IOServiceCallback(Dart_Port dest_port_id, Dart_CObject* message) {
5353
}
5454

5555
intptr_t IOService::max_concurrency_ = 32;
56+
std::atomic<Dart_Port> IOService::port_ = ILLEGAL_PORT;
5657

5758
Dart_Port IOService::GetServicePort() {
58-
return Dart_NewConcurrentNativePort("IOService", IOServiceCallback,
59-
max_concurrency_);
59+
Dart_Port port = port_;
60+
if (port == ILLEGAL_PORT) {
61+
port = Dart_NewConcurrentNativePort("IOService", IOServiceCallback,
62+
max_concurrency_);
63+
Dart_Port expected = ILLEGAL_PORT;
64+
if (!port_.compare_exchange_strong(expected, port)) {
65+
// Lost the initialization race. Use the winner's port and close our port.
66+
// The winner's port is eventually implicitly closed by VM shutdown.
67+
Dart_CloseNativePort(port);
68+
return expected;
69+
}
70+
}
71+
return port;
6072
}
6173

6274
void FUNCTION_NAME(IOService_NewServicePort)(Dart_NativeArguments args) {

runtime/bin/io_service_no_ssl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#error "io_service_no_ssl.h can only be included on builds with IO enabled"
1010
#endif
1111

12+
#include <atomic>
13+
1214
#include "bin/builtin.h"
1315
#include "bin/utils.h"
1416

@@ -70,12 +72,14 @@ class IOService {
7072
enum { IO_SERVICE_REQUEST_LIST(DECLARE_REQUEST) };
7173

7274
static Dart_Port GetServicePort();
75+
static void Cleanup() { port_ = ILLEGAL_PORT; }
7376

7477
static intptr_t max_concurrency() { return max_concurrency_; }
7578
static void set_max_concurrency(intptr_t value) { max_concurrency_ = value; }
7679

7780
private:
7881
static intptr_t max_concurrency_;
82+
static std::atomic<Dart_Port> port_;
7983

8084
DISALLOW_ALLOCATION();
8185
DISALLOW_IMPLICIT_CONSTRUCTORS(IOService);

0 commit comments

Comments
 (0)