[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 <alexmarkov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Jason Simmons <jsimmons@google.com>
This commit is contained in:
Jason Simmons
2025-07-07 09:34:35 -07:00
committed by Commit Queue
parent 1d5b271fe0
commit bbcc9babb8
4 changed files with 28 additions and 2 deletions
+4
View File
@@ -6,7 +6,11 @@
#include "bin/dartutils.h"
#include "bin/eventhandler.h"
#if defined(DART_IO_SECURE_SOCKET_DISABLED)
#include "bin/io_service_no_ssl.h"
#else // defined(DART_IO_SECURE_SOCKET_DISABLED)
#include "bin/io_service.h"
#endif // defined(DART_IO_SECURE_SOCKET_DISABLED)
#include "bin/isolate_data.h"
#include "bin/process.h"
#include "bin/secure_socket_filter.h"
+6
View File
@@ -8,6 +8,11 @@
#include "bin/directory.h"
#include "bin/eventhandler.h"
#include "bin/io_natives.h"
#if defined(DART_IO_SECURE_SOCKET_DISABLED)
#include "bin/io_service_no_ssl.h"
#else // defined(DART_IO_SECURE_SOCKET_DISABLED)
#include "bin/io_service.h"
#endif // defined(DART_IO_SECURE_SOCKET_DISABLED)
#include "bin/platform.h"
#include "bin/process.h"
#if !defined(DART_IO_SECURE_SOCKET_DISABLED)
@@ -36,6 +41,7 @@ void CleanupDartIo() {
SSLFilter::Cleanup();
#endif
Process::Cleanup();
IOService::Cleanup();
}
void SetSystemTempDirectory(const char* system_temp) {
+14 -2
View File
@@ -53,10 +53,22 @@ void IOServiceCallback(Dart_Port dest_port_id, Dart_CObject* message) {
}
intptr_t IOService::max_concurrency_ = 32;
std::atomic<Dart_Port> IOService::port_ = ILLEGAL_PORT;
Dart_Port IOService::GetServicePort() {
return Dart_NewConcurrentNativePort("IOService", IOServiceCallback,
max_concurrency_);
Dart_Port port = port_;
if (port == ILLEGAL_PORT) {
port = Dart_NewConcurrentNativePort("IOService", IOServiceCallback,
max_concurrency_);
Dart_Port expected = ILLEGAL_PORT;
if (!port_.compare_exchange_strong(expected, port)) {
// Lost the initialization race. Use the winner's port and close our port.
// The winner's port is eventually implicitly closed by VM shutdown.
Dart_CloseNativePort(port);
return expected;
}
}
return port;
}
void FUNCTION_NAME(IOService_NewServicePort)(Dart_NativeArguments args) {
+4
View File
@@ -9,6 +9,8 @@
#error "io_service_no_ssl.h can only be included on builds with IO enabled"
#endif
#include <atomic>
#include "bin/builtin.h"
#include "bin/utils.h"
@@ -70,12 +72,14 @@ class IOService {
enum { IO_SERVICE_REQUEST_LIST(DECLARE_REQUEST) };
static Dart_Port GetServicePort();
static void Cleanup() { port_ = ILLEGAL_PORT; }
static intptr_t max_concurrency() { return max_concurrency_; }
static void set_max_concurrency(intptr_t value) { max_concurrency_ = value; }
private:
static intptr_t max_concurrency_;
static std::atomic<Dart_Port> port_;
DISALLOW_ALLOCATION();
DISALLOW_IMPLICIT_CONSTRUCTORS(IOService);