Changeset 295740 in webkit
- Timestamp:
- Jun 22, 2022, 11:35:44 AM (4 years ago)
- Location:
- trunk/Source
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/wtf/cocoa/MemoryPressureHandlerCocoa.mm
r285648 r295740 50 50 } 51 51 52 static dispatch_source_t memoryPressureEventSource = nullptr; 53 static dispatch_source_t timerEventSource = nullptr; 52 static OSObjectPtr<dispatch_source_t>& memoryPressureEventSource() 53 { 54 static NeverDestroyed<OSObjectPtr<dispatch_source_t>> source; 55 return source.get(); 56 } 57 58 static OSObjectPtr<dispatch_source_t>& timerEventSource() 59 { 60 static NeverDestroyed<OSObjectPtr<dispatch_source_t>> source; 61 return source.get(); 62 } 63 54 64 static int notifyTokens[3]; 55 65 … … 67 77 void MemoryPressureHandler::install() 68 78 { 69 if (m_installed || timerEventSource )79 if (m_installed || timerEventSource()) 70 80 return; 71 81 72 82 dispatch_async(m_dispatchQueue.get(), ^{ 73 83 auto memoryStatusFlags = DISPATCH_MEMORYPRESSURE_NORMAL | DISPATCH_MEMORYPRESSURE_WARN | DISPATCH_MEMORYPRESSURE_CRITICAL | DISPATCH_MEMORYPRESSURE_PROC_LIMIT_WARN | DISPATCH_MEMORYPRESSURE_PROC_LIMIT_CRITICAL; 74 memoryPressureEventSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYPRESSURE, 0, memoryStatusFlags, m_dispatchQueue.get());75 76 dispatch_source_set_event_handler(memoryPressureEventSource , ^{77 auto status = dispatch_source_get_data(memoryPressureEventSource );84 memoryPressureEventSource() = adoptOSObject(dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYPRESSURE, 0, memoryStatusFlags, m_dispatchQueue.get())); 85 86 dispatch_source_set_event_handler(memoryPressureEventSource().get(), ^{ 87 auto status = dispatch_source_get_data(memoryPressureEventSource().get()); 78 88 switch (status) { 79 89 // VM pressure events. … … 102 112 RELEASE_LOG(MemoryPressure, "Received memory pressure event %lu vm pressure %d", status, isUnderMemoryPressure()); 103 113 }); 104 dispatch_resume(memoryPressureEventSource );114 dispatch_resume(memoryPressureEventSource().get()); 105 115 }); 106 116 … … 141 151 142 152 dispatch_async(m_dispatchQueue.get(), ^{ 143 if (memoryPressureEventSource ) {144 dispatch_source_cancel(memoryPressureEventSource );145 memoryPressureEventSource = nullptr;153 if (memoryPressureEventSource()) { 154 dispatch_source_cancel(memoryPressureEventSource().get()); 155 memoryPressureEventSource() = nullptr; 146 156 } 147 157 148 if (timerEventSource ) {149 dispatch_source_cancel(timerEventSource );150 timerEventSource = nullptr;158 if (timerEventSource()) { 159 dispatch_source_cancel(timerEventSource().get()); 160 timerEventSource() = nullptr; 151 161 } 152 162 }); … … 161 171 { 162 172 dispatch_async(m_dispatchQueue.get(), ^{ 163 timerEventSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, m_dispatchQueue.get());164 if (timerEventSource ) {165 dispatch_set_context(timerEventSource , this);173 timerEventSource() = adoptOSObject(dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, m_dispatchQueue.get())); 174 if (timerEventSource()) { 175 dispatch_set_context(timerEventSource().get(), this); 166 176 // FIXME: The final argument `s_minimumHoldOffTime.seconds()` seems wrong. 167 177 // https://bugs.webkit.org/show_bug.cgi?id=183277 168 dispatch_source_set_timer(timerEventSource , dispatch_time(DISPATCH_TIME_NOW, seconds.seconds() * NSEC_PER_SEC), DISPATCH_TIME_FOREVER, s_minimumHoldOffTime.seconds());169 dispatch_source_set_event_handler(timerEventSource , ^{170 if (timerEventSource ) {171 dispatch_source_cancel(timerEventSource );172 timerEventSource = nullptr;178 dispatch_source_set_timer(timerEventSource().get(), dispatch_time(DISPATCH_TIME_NOW, seconds.seconds() * NSEC_PER_SEC), DISPATCH_TIME_FOREVER, s_minimumHoldOffTime.seconds()); 179 dispatch_source_set_event_handler(timerEventSource().get(), ^{ 180 if (timerEventSource().get()) { 181 dispatch_source_cancel(timerEventSource().get()); 182 timerEventSource() = nullptr; 173 183 } 174 184 MemoryPressureHandler::singleton().install(); 175 185 }); 176 dispatch_resume(timerEventSource );186 dispatch_resume(timerEventSource().get()); 177 187 } 178 188 }); -
trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm
r295270 r295740 159 159 { 160 160 static NeverDestroyed<OSObjectPtr<os_transaction_t>> globalTransaction; 161 static NeverDestroyed<OSObjectPtr<dispatch_source_t>> globalSource; 161 162 162 163 // Because we don't use RunningBoard on macOS, we leak an OS transaction to control the lifetime of our XPC … … 168 169 static dispatch_once_t flag; 169 170 dispatch_once(&flag, ^{ 170 auto sigTermSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM, 0, dispatch_get_main_queue());171 dispatch_source_set_event_handler( sigTermSource, ^{171 globalSource.get() = adoptOSObject(dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM, 0, dispatch_get_main_queue())); 172 dispatch_source_set_event_handler(globalSource.get().get(), ^{ 172 173 exit(0); 173 174 }); 174 dispatch_resume( sigTermSource);175 dispatch_resume(globalSource.get().get()); 175 176 }); 176 177
Note:
See TracChangeset
for help on using the changeset viewer.