Files
swift-mirror/stdlib/public/stubs/LibcShims.cpp
T
Mike Ash d0017555c7 [Runtime] Faster dynamic exclusivity checking implemented in Swift.
Replace C++ implementation of swift_beginAccess and swift_endAccess with (almost) pure Swift implementation. Helpers remain in C++ for TLS, getting return addresses, and raising a fatal error on violations.

This change also moves the exclusivity access set head from the shared SwiftTLSContext structure to a dedicated TLS key. This improves performance, which is important for exclusivity checking. This is particularly the case where we can inline TLS access with a constant key, as on Darwin ARM64.

The code that bridges exclusivity tracking into Concurrency remains in C++. The new Swift implementation exposes a few helpers for it to use as a replacement for directly manipulating the C++ implementation.

rdar://161122309
2026-01-14 12:23:55 -05:00

55 lines
1.5 KiB
C++

//===--- LibcShims.cpp ----------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#if defined(__APPLE__)
#define _REENTRANT
#include <math.h>
#endif
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <io.h>
#include <stdlib.h>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#if defined(_WIN32)
#include "swift/Runtime/Config.h"
#endif
#include "swift/shims/LibcShims.h"
#if defined(_WIN32)
SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_BEGIN
static void __attribute__((__constructor__))
_swift_stdlib_configure_console_mode(void) {
static UINT uiPrevConsoleCP = GetConsoleOutputCP();
atexit([]() { SetConsoleOutputCP(uiPrevConsoleCP); });
SetConsoleOutputCP(CP_UTF8);
}
SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_END
#endif
SWIFT_RUNTIME_STDLIB_INTERNAL
__swift_size_t _swift_stdlib_fwrite_stdout(const void *ptr,
__swift_size_t size,
__swift_size_t nitems) {
return fwrite(ptr, size, nitems, stdout);
}
SWIFT_RUNTIME_STDLIB_INTERNAL
void _swift_stdlib_fputs_stderr(const char *str) {
fputs(str, stderr);
}