File tree Expand file tree Collapse file tree 2 files changed +69
-2
lines changed
stdlib/public/Concurrency Expand file tree Collapse file tree 2 files changed +69
-2
lines changed Original file line number Diff line number Diff line change 17
17
//
18
18
// ===----------------------------------------------------------------------===//
19
19
20
+ #include " TaskPrivate.h"
20
21
#include " swift/Runtime/Concurrency.h"
21
22
#include < stdlib.h>
22
23
23
24
using namespace swift ;
24
25
26
+ namespace {
27
+
28
+ class TaskAllocator {
29
+ public:
30
+ void *alloc (size_t size) {
31
+ return malloc (size);
32
+ }
33
+
34
+ void dealloc (void *ptr) {
35
+ free (ptr);
36
+ }
37
+ };
38
+
39
+ static_assert (sizeof (TaskAllocator) <= sizeof (AsyncTask::AllocatorPrivate),
40
+ " task allocator must fit in allocator-private slot" );
41
+
42
+ static_assert (alignof (TaskAllocator) <= alignof (decltype (AsyncTask::AllocatorPrivate)),
43
+ " task allocator must not be more aligned than "
44
+ " allocator-private slot" );
45
+
46
+ } // end anonymous namespace
47
+
48
+ void swift::_swift_task_alloc_initialize (AsyncTask *task) {
49
+ new (task->AllocatorPrivate ) TaskAllocator ();
50
+ }
51
+
52
+ static TaskAllocator &allocator (AsyncTask *task) {
53
+ return reinterpret_cast <TaskAllocator &>(task->AllocatorPrivate );
54
+ }
55
+
56
+ void swift::_swift_task_alloc_destroy (AsyncTask *task) {
57
+ allocator (task).~TaskAllocator ();
58
+ }
59
+
25
60
void *swift::swift_task_alloc (AsyncTask *task, size_t size) {
26
- return malloc (size);
61
+ return allocator (task). alloc (size);
27
62
}
28
63
29
64
void swift::swift_task_dealloc (AsyncTask *task, void *ptr) {
30
- free (ptr);
65
+ return allocator (task). dealloc (ptr);
31
66
}
Original file line number Diff line number Diff line change
1
+ // ===--- TaskPrivate.h - Concurrency library internal interface -*- C++ -*-===//
2
+ //
3
+ // This source file is part of the Swift.org open source project
4
+ //
5
+ // Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6
+ // Licensed under Apache License v2.0 with Runtime Library Exception
7
+ //
8
+ // See https://swift.org/LICENSE.txt for license information
9
+ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
+ //
11
+ // ===----------------------------------------------------------------------===//
12
+ //
13
+ // Internal functions for the concurrency library.
14
+ //
15
+ // ===----------------------------------------------------------------------===//
16
+
17
+ #ifndef SWIFT_CONCURRENCY_TASKPRIVATE_H
18
+ #define SWIFT_CONCURRENCY_TASKPRIVATE_H
19
+
20
+ namespace swift {
21
+
22
+ class AsyncTask ;
23
+
24
+ // / Initialize the task-local allocator in the given task.
25
+ void _swift_task_alloc_initialize (AsyncTask *task);
26
+
27
+ // / Destsroy the task-local allocator in the given task.
28
+ void _swift_task_alloc_destroy (AsyncTask *task);
29
+
30
+ } // end namespace swift
31
+
32
+ #endif
You can’t perform that action at this time.
0 commit comments