@@ -46,32 +46,6 @@ namespace snmalloc
4646 }
4747
4848 public:
49- PALWindows ()
50- {
51- // No error handling here - if this doesn't work, then we will just
52- // consume more memory. There's nothing sensible that we could do in
53- // error handling. We also leak both the low memory notification object
54- // handle and the wait object handle. We'll need them until the program
55- // exits, so there's little point doing anything else.
56- //
57- // We only try to register once. If this fails, give up. Even if we
58- // create multiple PAL objects, we don't want to get more than one
59- // callback.
60- if (!registered_for_notifications.exchange (true ))
61- {
62- lowMemoryObject =
63- CreateMemoryResourceNotification (LowMemoryResourceNotification);
64- HANDLE waitObject;
65- RegisterWaitForSingleObject (
66- &waitObject,
67- lowMemoryObject,
68- low_memory,
69- nullptr ,
70- INFINITE,
71- WT_EXECUTEDEFAULT);
72- }
73- }
74-
7549 /* *
7650 * Bitmap of PalFeatures flags indicating the optional features that this
7751 * PAL supports. This PAL supports low-memory notifications.
@@ -105,6 +79,29 @@ namespace snmalloc
10579 static void
10680 register_for_low_memory_callback (PalNotificationObject* callback)
10781 {
82+ // No error handling here - if this doesn't work, then we will just
83+ // consume more memory. There's nothing sensible that we could do in
84+ // error handling. We also leak both the low memory notification object
85+ // handle and the wait object handle. We'll need them until the program
86+ // exits, so there's little point doing anything else.
87+ //
88+ // We only try to register once. If this fails, give up. Even if we
89+ // create multiple PAL objects, we don't want to get more than one
90+ // callback.
91+ if (!registered_for_notifications.exchange (true ))
92+ {
93+ lowMemoryObject =
94+ CreateMemoryResourceNotification (LowMemoryResourceNotification);
95+ HANDLE waitObject;
96+ RegisterWaitForSingleObject (
97+ &waitObject,
98+ lowMemoryObject,
99+ low_memory,
100+ nullptr ,
101+ INFINITE,
102+ WT_EXECUTEDEFAULT);
103+ }
104+
108105 low_memory_callbacks.register_notification (callback);
109106 }
110107
0 commit comments