diff options
| author | YAMAMOTO Mitsuharu | 2008-03-29 00:45:38 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2008-03-29 00:45:38 +0000 |
| commit | d15a962285c371182faf16b10978e637fb2a01df (patch) | |
| tree | ae672fd85c1495b80ff34ac1ae0045e765139c5b /src | |
| parent | 882cbf8ea542d7951ea231c078ee024a2312b381 (diff) | |
| download | emacs-d15a962285c371182faf16b10978e637fb2a01df.tar.gz emacs-d15a962285c371182faf16b10978e637fb2a01df.zip | |
(xrm_get_preference_database): Remove BLOCK_INPUT.
[TARGET_API_MAC_CARBON] (cfdate_to_lisp): Obtain microsec value.
Use kCFAbsoluteTimeIntervalSince1970.
(wakeup_from_rne_enabled_p) [MAC_OSX]: Remove variable.
(ENABLE_WAKEUP_FROM_RNE, DISABLE_WAKEUP_FROM_RNE) [MAC_OSX]:
Remove macros.
[MAC_OSX] (socket_callback): Do nothing.
[MAC_OSX] (select_and_poll_event): Use CFRunLoopRunInMode instead of
ReceiveNextEvent.
[MAC_OSX] (sys_select): Likewise. Don't set context as argument to
socket_callback.
(mac_wakeup_from_rne) [MAC_OSX]: Do nothing.
Diffstat (limited to 'src')
| -rw-r--r-- | src/mac.c | 126 |
1 files changed, 69 insertions, 57 deletions
| @@ -79,6 +79,7 @@ static ComponentInstance as_scripting_component; | |||
| 79 | /* The single script context used for all script executions. */ | 79 | /* The single script context used for all script executions. */ |
| 80 | static OSAID as_script_context; | 80 | static OSAID as_script_context; |
| 81 | 81 | ||
| 82 | #ifndef MAC_OSX | ||
| 82 | #if TARGET_API_MAC_CARBON | 83 | #if TARGET_API_MAC_CARBON |
| 83 | static int wakeup_from_rne_enabled_p = 0; | 84 | static int wakeup_from_rne_enabled_p = 0; |
| 84 | #define ENABLE_WAKEUP_FROM_RNE (wakeup_from_rne_enabled_p = 1) | 85 | #define ENABLE_WAKEUP_FROM_RNE (wakeup_from_rne_enabled_p = 1) |
| @@ -87,6 +88,7 @@ static int wakeup_from_rne_enabled_p = 0; | |||
| 87 | #define ENABLE_WAKEUP_FROM_RNE 0 | 88 | #define ENABLE_WAKEUP_FROM_RNE 0 |
| 88 | #define DISABLE_WAKEUP_FROM_RNE 0 | 89 | #define DISABLE_WAKEUP_FROM_RNE 0 |
| 89 | #endif | 90 | #endif |
| 91 | #endif | ||
| 90 | 92 | ||
| 91 | #ifndef MAC_OSX | 93 | #ifndef MAC_OSX |
| 92 | static OSErr posix_pathname_to_fsspec P_ ((const char *, FSSpec *)); | 94 | static OSErr posix_pathname_to_fsspec P_ ((const char *, FSSpec *)); |
| @@ -1127,18 +1129,15 @@ Lisp_Object | |||
| 1127 | cfdate_to_lisp (date) | 1129 | cfdate_to_lisp (date) |
| 1128 | CFDateRef date; | 1130 | CFDateRef date; |
| 1129 | { | 1131 | { |
| 1130 | static const CFGregorianDate epoch_gdate = {1970, 1, 1, 0, 0, 0.0}; | 1132 | CFTimeInterval sec; |
| 1131 | static CFAbsoluteTime epoch = 0.0, sec; | 1133 | int high, low, microsec; |
| 1132 | int high, low; | ||
| 1133 | |||
| 1134 | if (epoch == 0.0) | ||
| 1135 | epoch = CFGregorianDateGetAbsoluteTime (epoch_gdate, NULL); | ||
| 1136 | 1134 | ||
| 1137 | sec = CFDateGetAbsoluteTime (date) - epoch; | 1135 | sec = CFDateGetAbsoluteTime (date) + kCFAbsoluteTimeIntervalSince1970; |
| 1138 | high = sec / 65536.0; | 1136 | high = sec / 65536.0; |
| 1139 | low = sec - high * 65536.0; | 1137 | low = sec - high * 65536.0; |
| 1138 | microsec = (sec - floor (sec)) * 1000000.0; | ||
| 1140 | 1139 | ||
| 1141 | return list3 (make_number (high), make_number (low), make_number (0)); | 1140 | return list3 (make_number (high), make_number (low), make_number (microsec)); |
| 1142 | } | 1141 | } |
| 1143 | 1142 | ||
| 1144 | 1143 | ||
| @@ -1826,8 +1825,6 @@ xrm_get_preference_database (application) | |||
| 1826 | 1825 | ||
| 1827 | GCPRO3 (database, quarks, value); | 1826 | GCPRO3 (database, quarks, value); |
| 1828 | 1827 | ||
| 1829 | BLOCK_INPUT; | ||
| 1830 | |||
| 1831 | app_id = kCFPreferencesCurrentApplication; | 1828 | app_id = kCFPreferencesCurrentApplication; |
| 1832 | if (application) | 1829 | if (application) |
| 1833 | { | 1830 | { |
| @@ -1879,8 +1876,6 @@ xrm_get_preference_database (application) | |||
| 1879 | CFRelease (key_set); | 1876 | CFRelease (key_set); |
| 1880 | CFRelease (app_id); | 1877 | CFRelease (app_id); |
| 1881 | 1878 | ||
| 1882 | UNBLOCK_INPUT; | ||
| 1883 | |||
| 1884 | UNGCPRO; | 1879 | UNGCPRO; |
| 1885 | 1880 | ||
| 1886 | return database; | 1881 | return database; |
| @@ -4994,8 +4989,8 @@ extern int noninteractive; | |||
| 4994 | SELECT_TIMEOUT_THRESHOLD_RUNLOOP seconds). | 4989 | SELECT_TIMEOUT_THRESHOLD_RUNLOOP seconds). |
| 4995 | -> Create CFSocket for each socket and add it into the current | 4990 | -> Create CFSocket for each socket and add it into the current |
| 4996 | event RunLoop so that the current event loop gets quit when | 4991 | event RunLoop so that the current event loop gets quit when |
| 4997 | the socket becomes ready. Then ReceiveNextEvent can wait for | 4992 | the socket becomes ready. Then CFRunLoopRunInMode can wait |
| 4998 | both kinds of inputs. | 4993 | for both kinds of inputs. |
| 4999 | 4. Otherwise. | 4994 | 4. Otherwise. |
| 5000 | -> Periodically poll the window input channel while repeatedly | 4995 | -> Periodically poll the window input channel while repeatedly |
| 5001 | executing `select' with a short timeout | 4996 | executing `select' with a short timeout |
| @@ -5024,12 +5019,6 @@ socket_callback (s, type, address, data, info) | |||
| 5024 | const void *data; | 5019 | const void *data; |
| 5025 | void *info; | 5020 | void *info; |
| 5026 | { | 5021 | { |
| 5027 | int fd = CFSocketGetNative (s); | ||
| 5028 | SELECT_TYPE *ofds = (SELECT_TYPE *)info; | ||
| 5029 | |||
| 5030 | if ((type == kCFSocketReadCallBack && FD_ISSET (fd, &ofds[0])) | ||
| 5031 | || (type == kCFSocketConnectCallBack && FD_ISSET (fd, &ofds[1]))) | ||
| 5032 | QuitEventLoop (GetCurrentEventLoop ()); | ||
| 5033 | } | 5022 | } |
| 5034 | #endif /* SELECT_USE_CFSOCKET */ | 5023 | #endif /* SELECT_USE_CFSOCKET */ |
| 5035 | 5024 | ||
| @@ -5039,42 +5028,64 @@ select_and_poll_event (nfds, rfds, wfds, efds, timeout) | |||
| 5039 | SELECT_TYPE *rfds, *wfds, *efds; | 5028 | SELECT_TYPE *rfds, *wfds, *efds; |
| 5040 | EMACS_TIME *timeout; | 5029 | EMACS_TIME *timeout; |
| 5041 | { | 5030 | { |
| 5042 | OSStatus err = noErr; | 5031 | int timedout_p = 0; |
| 5043 | int r = 0; | 5032 | int r = 0; |
| 5033 | EMACS_TIME select_timeout; | ||
| 5034 | EventTimeout timeoutval = | ||
| 5035 | (timeout | ||
| 5036 | ? (EMACS_SECS (*timeout) * kEventDurationSecond | ||
| 5037 | + EMACS_USECS (*timeout) * kEventDurationMicrosecond) | ||
| 5038 | : kEventDurationForever); | ||
| 5039 | SELECT_TYPE orfds, owfds, oefds; | ||
| 5044 | 5040 | ||
| 5045 | /* Try detect_input_pending before ReceiveNextEvent in the same | 5041 | if (timeout == NULL) |
| 5042 | { | ||
| 5043 | if (rfds) orfds = *rfds; | ||
| 5044 | if (wfds) owfds = *wfds; | ||
| 5045 | if (efds) oefds = *efds; | ||
| 5046 | } | ||
| 5047 | |||
| 5048 | /* Try detect_input_pending before CFRunLoopRunInMode in the same | ||
| 5046 | BLOCK_INPUT block, in case that some input has already been read | 5049 | BLOCK_INPUT block, in case that some input has already been read |
| 5047 | asynchronously. */ | 5050 | asynchronously. */ |
| 5048 | BLOCK_INPUT; | 5051 | BLOCK_INPUT; |
| 5049 | ENABLE_WAKEUP_FROM_RNE; | 5052 | while (1) |
| 5050 | if (!detect_input_pending ()) | ||
| 5051 | { | 5053 | { |
| 5052 | EMACS_TIME select_timeout; | 5054 | if (detect_input_pending ()) |
| 5053 | EventTimeout timeoutval = | 5055 | break; |
| 5054 | (timeout | ||
| 5055 | ? (EMACS_SECS (*timeout) * kEventDurationSecond | ||
| 5056 | + EMACS_USECS (*timeout) * kEventDurationMicrosecond) | ||
| 5057 | : kEventDurationForever); | ||
| 5058 | 5056 | ||
| 5059 | EMACS_SET_SECS_USECS (select_timeout, 0, 0); | 5057 | EMACS_SET_SECS_USECS (select_timeout, 0, 0); |
| 5060 | r = select (nfds, rfds, wfds, efds, &select_timeout); | 5058 | r = select (nfds, rfds, wfds, efds, &select_timeout); |
| 5059 | if (r != 0) | ||
| 5060 | break; | ||
| 5061 | |||
| 5061 | if (timeoutval == 0.0) | 5062 | if (timeoutval == 0.0) |
| 5062 | err = eventLoopTimedOutErr; | 5063 | timedout_p = 1; |
| 5063 | else if (r == 0) | 5064 | else |
| 5064 | { | 5065 | { |
| 5065 | #if USE_CG_DRAWING | 5066 | #if USE_CG_DRAWING |
| 5066 | mac_prepare_for_quickdraw (NULL); | 5067 | mac_prepare_for_quickdraw (NULL); |
| 5067 | #endif | 5068 | #endif |
| 5068 | err = ReceiveNextEvent (0, NULL, timeoutval, | 5069 | if (CFRunLoopRunInMode (kCFRunLoopDefaultMode, |
| 5069 | kEventLeaveInQueue, NULL); | 5070 | timeoutval >= 0 ? timeoutval : 100000, true) |
| 5071 | == kCFRunLoopRunTimedOut) | ||
| 5072 | timedout_p = 1; | ||
| 5070 | } | 5073 | } |
| 5074 | |||
| 5075 | if (timeout == NULL && timedout_p) | ||
| 5076 | { | ||
| 5077 | if (rfds) *rfds = orfds; | ||
| 5078 | if (wfds) *wfds = owfds; | ||
| 5079 | if (efds) *efds = oefds; | ||
| 5080 | } | ||
| 5081 | else | ||
| 5082 | break; | ||
| 5071 | } | 5083 | } |
| 5072 | DISABLE_WAKEUP_FROM_RNE; | ||
| 5073 | UNBLOCK_INPUT; | 5084 | UNBLOCK_INPUT; |
| 5074 | 5085 | ||
| 5075 | if (r != 0) | 5086 | if (r != 0) |
| 5076 | return r; | 5087 | return r; |
| 5077 | else if (err == noErr) | 5088 | else if (!timedout_p) |
| 5078 | { | 5089 | { |
| 5079 | /* Pretend that `select' is interrupted by a signal. */ | 5090 | /* Pretend that `select' is interrupted by a signal. */ |
| 5080 | detect_input_pending (); | 5091 | detect_input_pending (); |
| @@ -5128,25 +5139,25 @@ sys_select (nfds, rfds, wfds, efds, timeout) | |||
| 5128 | SELECT_TYPE *rfds, *wfds, *efds; | 5139 | SELECT_TYPE *rfds, *wfds, *efds; |
| 5129 | EMACS_TIME *timeout; | 5140 | EMACS_TIME *timeout; |
| 5130 | { | 5141 | { |
| 5131 | OSStatus err = noErr; | 5142 | int timedout_p = 0; |
| 5132 | int r; | 5143 | int r; |
| 5133 | EMACS_TIME select_timeout; | 5144 | EMACS_TIME select_timeout; |
| 5134 | static SELECT_TYPE ofds[3]; | 5145 | SELECT_TYPE orfds, owfds, oefds; |
| 5135 | 5146 | ||
| 5136 | if (inhibit_window_system || noninteractive | 5147 | if (inhibit_window_system || noninteractive |
| 5137 | || nfds < 1 || rfds == NULL || !FD_ISSET (0, rfds)) | 5148 | || nfds < 1 || rfds == NULL || !FD_ISSET (0, rfds)) |
| 5138 | return select (nfds, rfds, wfds, efds, timeout); | 5149 | return select (nfds, rfds, wfds, efds, timeout); |
| 5139 | 5150 | ||
| 5140 | FD_CLR (0, rfds); | 5151 | FD_CLR (0, rfds); |
| 5141 | ofds[0] = *rfds; | 5152 | orfds = *rfds; |
| 5142 | 5153 | ||
| 5143 | if (wfds) | 5154 | if (wfds) |
| 5144 | ofds[1] = *wfds; | 5155 | owfds = *wfds; |
| 5145 | else | 5156 | else |
| 5146 | FD_ZERO (&ofds[1]); | 5157 | FD_ZERO (&owfds); |
| 5147 | 5158 | ||
| 5148 | if (efds) | 5159 | if (efds) |
| 5149 | ofds[2] = *efds; | 5160 | oefds = *efds; |
| 5150 | else | 5161 | else |
| 5151 | { | 5162 | { |
| 5152 | EventTimeout timeoutval = | 5163 | EventTimeout timeoutval = |
| @@ -5174,25 +5185,23 @@ sys_select (nfds, rfds, wfds, efds, timeout) | |||
| 5174 | if (r != 0 || timeoutval == 0.0) | 5185 | if (r != 0 || timeoutval == 0.0) |
| 5175 | return r; | 5186 | return r; |
| 5176 | 5187 | ||
| 5177 | *rfds = ofds[0]; | 5188 | *rfds = orfds; |
| 5178 | if (wfds) | 5189 | if (wfds) |
| 5179 | *wfds = ofds[1]; | 5190 | *wfds = owfds; |
| 5180 | 5191 | ||
| 5181 | #if SELECT_USE_CFSOCKET | 5192 | #if SELECT_USE_CFSOCKET |
| 5182 | if (timeoutval > 0 && timeoutval <= SELECT_TIMEOUT_THRESHOLD_RUNLOOP) | 5193 | if (timeoutval > 0 && timeoutval <= SELECT_TIMEOUT_THRESHOLD_RUNLOOP) |
| 5183 | goto poll_periodically; | 5194 | goto poll_periodically; |
| 5184 | 5195 | ||
| 5185 | /* Try detect_input_pending before ReceiveNextEvent in the same | 5196 | /* Try detect_input_pending before CFRunLoopRunInMode in the |
| 5186 | BLOCK_INPUT block, in case that some input has already been | 5197 | same BLOCK_INPUT block, in case that some input has already |
| 5187 | read asynchronously. */ | 5198 | been read asynchronously. */ |
| 5188 | BLOCK_INPUT; | 5199 | BLOCK_INPUT; |
| 5189 | ENABLE_WAKEUP_FROM_RNE; | ||
| 5190 | if (!detect_input_pending ()) | 5200 | if (!detect_input_pending ()) |
| 5191 | { | 5201 | { |
| 5192 | int minfd, fd; | 5202 | int minfd, fd; |
| 5193 | CFRunLoopRef runloop = | 5203 | CFRunLoopRef runloop = |
| 5194 | (CFRunLoopRef) GetCFRunLoopFromEventLoop (GetCurrentEventLoop ()); | 5204 | (CFRunLoopRef) GetCFRunLoopFromEventLoop (GetCurrentEventLoop ()); |
| 5195 | static const CFSocketContext context = {0, ofds, NULL, NULL, NULL}; | ||
| 5196 | static CFMutableDictionaryRef sources; | 5205 | static CFMutableDictionaryRef sources; |
| 5197 | 5206 | ||
| 5198 | if (sources == NULL) | 5207 | if (sources == NULL) |
| @@ -5222,7 +5231,7 @@ sys_select (nfds, rfds, wfds, efds, timeout) | |||
| 5222 | CFSocketCreateWithNative (NULL, fd, | 5231 | CFSocketCreateWithNative (NULL, fd, |
| 5223 | (kCFSocketReadCallBack | 5232 | (kCFSocketReadCallBack |
| 5224 | | kCFSocketConnectCallBack), | 5233 | | kCFSocketConnectCallBack), |
| 5225 | socket_callback, &context); | 5234 | socket_callback, NULL); |
| 5226 | 5235 | ||
| 5227 | if (socket == NULL) | 5236 | if (socket == NULL) |
| 5228 | continue; | 5237 | continue; |
| @@ -5240,8 +5249,10 @@ sys_select (nfds, rfds, wfds, efds, timeout) | |||
| 5240 | #if USE_CG_DRAWING | 5249 | #if USE_CG_DRAWING |
| 5241 | mac_prepare_for_quickdraw (NULL); | 5250 | mac_prepare_for_quickdraw (NULL); |
| 5242 | #endif | 5251 | #endif |
| 5243 | err = ReceiveNextEvent (0, NULL, timeoutval, | 5252 | if (CFRunLoopRunInMode (kCFRunLoopDefaultMode, |
| 5244 | kEventLeaveInQueue, NULL); | 5253 | timeoutval >= 0 ? timeoutval : 100000, true) |
| 5254 | == kCFRunLoopRunTimedOut) | ||
| 5255 | timedout_p = 1; | ||
| 5245 | 5256 | ||
| 5246 | for (fd = minfd; fd < nfds; fd++) | 5257 | for (fd = minfd; fd < nfds; fd++) |
| 5247 | if (FD_ISSET (fd, rfds) || (wfds && FD_ISSET (fd, wfds))) | 5258 | if (FD_ISSET (fd, rfds) || (wfds && FD_ISSET (fd, wfds))) |
| @@ -5253,10 +5264,9 @@ sys_select (nfds, rfds, wfds, efds, timeout) | |||
| 5253 | CFRunLoopRemoveSource (runloop, source, kCFRunLoopDefaultMode); | 5264 | CFRunLoopRemoveSource (runloop, source, kCFRunLoopDefaultMode); |
| 5254 | } | 5265 | } |
| 5255 | } | 5266 | } |
| 5256 | DISABLE_WAKEUP_FROM_RNE; | ||
| 5257 | UNBLOCK_INPUT; | 5267 | UNBLOCK_INPUT; |
| 5258 | 5268 | ||
| 5259 | if (err == noErr || err == eventLoopQuitErr) | 5269 | if (!timedout_p) |
| 5260 | { | 5270 | { |
| 5261 | EMACS_SET_SECS_USECS (select_timeout, 0, 0); | 5271 | EMACS_SET_SECS_USECS (select_timeout, 0, 0); |
| 5262 | return select_and_poll_event (nfds, rfds, wfds, efds, | 5272 | return select_and_poll_event (nfds, rfds, wfds, efds, |
| @@ -5292,11 +5302,11 @@ sys_select (nfds, rfds, wfds, efds, timeout) | |||
| 5292 | if (r != 0) | 5302 | if (r != 0) |
| 5293 | return r; | 5303 | return r; |
| 5294 | 5304 | ||
| 5295 | *rfds = ofds[0]; | 5305 | *rfds = orfds; |
| 5296 | if (wfds) | 5306 | if (wfds) |
| 5297 | *wfds = ofds[1]; | 5307 | *wfds = owfds; |
| 5298 | if (efds) | 5308 | if (efds) |
| 5299 | *efds = ofds[2]; | 5309 | *efds = oefds; |
| 5300 | 5310 | ||
| 5301 | if (timeout) | 5311 | if (timeout) |
| 5302 | { | 5312 | { |
| @@ -5461,10 +5471,12 @@ init_mac_osx_environment () | |||
| 5461 | void | 5471 | void |
| 5462 | mac_wakeup_from_rne () | 5472 | mac_wakeup_from_rne () |
| 5463 | { | 5473 | { |
| 5474 | #ifndef MAC_OSX | ||
| 5464 | if (wakeup_from_rne_enabled_p) | 5475 | if (wakeup_from_rne_enabled_p) |
| 5465 | /* Post a harmless event so as to wake up from | 5476 | /* Post a harmless event so as to wake up from |
| 5466 | ReceiveNextEvent. */ | 5477 | ReceiveNextEvent. */ |
| 5467 | mac_post_mouse_moved_event (); | 5478 | mac_post_mouse_moved_event (); |
| 5479 | #endif | ||
| 5468 | } | 5480 | } |
| 5469 | #endif | 5481 | #endif |
| 5470 | 5482 | ||