1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef GIN_V8_PLATFORM_THREAD_ISOLATED_ALLOCATOR_H_
6 #define GIN_V8_PLATFORM_THREAD_ISOLATED_ALLOCATOR_H_
8 #include "base/allocator/partition_allocator/src/partition_alloc/partition_alloc_buildflags.h"
10 #if BUILDFLAG(ENABLE_THREAD_ISOLATION)
12 #if !BUILDFLAG(ENABLE_PKEYS)
13 #error Not implemented for non-pkey thread isolation
14 #endif // BUILDFLAG(ENABLE_PKEYS)
16 #include "base/allocator/partition_allocator/src/partition_alloc/partition_alloc.h"
17 #include "gin/gin_export.h"
18 #include "v8/include/v8-platform.h"
22 // This is a wrapper around PartitionAlloc's ThreadIsolated pool that we pass to
24 class GIN_EXPORT ThreadIsolatedAllocator final
25 : public v8::ThreadIsolatedAllocator {
27 ThreadIsolatedAllocator();
28 ~ThreadIsolatedAllocator() override;
30 void Initialize(int pkey);
32 void* Allocate(size_t size) override;
33 void Free(void* object) override;
34 enum Type Type() const override;
36 int Pkey() const override;
39 partition_alloc::PartitionAllocator allocator_;
45 #endif // BUILDFLAG(ENABLE_THREAD_ISOLATION)
47 #endif // GIN_V8_PLATFORM_THREAD_ISOLATED_ALLOCATOR_H_