File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed
stdlib/public/Concurrency Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change 19
19
20
20
#include " TaskPrivate.h"
21
21
#include " swift/Runtime/Concurrency.h"
22
+ #include " swift/Runtime/Debug.h"
22
23
#include < stdlib.h>
24
+ #include < vector>
23
25
24
26
using namespace swift ;
25
27
26
28
namespace {
27
29
28
30
class TaskAllocator {
31
+ // Just keep track of all allocations in a vector so that we can
32
+ // verify stack discipline. We should make sure the allocator
33
+ // implementation strictly verifies allocation order at least
34
+ // until we've stabilized the compiler implementation.
35
+ std::vector<void *> Allocations;
36
+
29
37
public:
30
38
void *alloc (size_t size) {
31
- return malloc (size);
39
+ void *ptr = malloc (size);
40
+ Allocations.push_back (ptr);
41
+ return ptr;
32
42
}
33
43
34
44
void dealloc (void *ptr) {
45
+ if (Allocations.empty () || Allocations.back () != ptr)
46
+ fatalError (0 , " pointer was not the last allocation on this task" );
47
+
48
+ Allocations.pop_back ();
35
49
free (ptr);
36
50
}
37
51
};
@@ -50,7 +64,14 @@ void swift::_swift_task_alloc_initialize(AsyncTask *task) {
50
64
}
51
65
52
66
static TaskAllocator &allocator (AsyncTask *task) {
53
- return reinterpret_cast <TaskAllocator &>(task->AllocatorPrivate );
67
+ if (task)
68
+ return reinterpret_cast <TaskAllocator &>(task->AllocatorPrivate );
69
+
70
+ // FIXME: this fall-back shouldn't be necessary, but it's useful
71
+ // for now, since the current execution tests aren't setting up a task
72
+ // properly.
73
+ static TaskAllocator global;
74
+ return global;
54
75
}
55
76
56
77
void swift::_swift_task_alloc_destroy (AsyncTask *task) {
You can’t perform that action at this time.
0 commit comments