Mercurial > emacs
comparison src/mac.c @ 82782:4a8f2bf9fced
(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.
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> |
---|---|
date | Thu, 23 Aug 2007 08:45:13 +0000 |
parents | d2b18c3b227c |
children | f0c0222ef990 |
comparison
equal
deleted
inserted
replaced
82781:916a16bcfda2 | 82782:4a8f2bf9fced |
---|---|
77 /* An instance of the AppleScript component. */ | 77 /* An instance of the AppleScript component. */ |
78 static ComponentInstance as_scripting_component; | 78 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_OS_X | |
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) |
85 #define DISABLE_WAKEUP_FROM_RNE (wakeup_from_rne_enabled_p = 0) | 86 #define DISABLE_WAKEUP_FROM_RNE (wakeup_from_rne_enabled_p = 0) |
86 #else | 87 #else |
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 |
90 #endif | |
89 #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 *)); |
93 static OSErr fsspec_to_posix_pathname P_ ((const FSSpec *, char *, int)); | 95 static OSErr fsspec_to_posix_pathname P_ ((const FSSpec *, char *, int)); |
5008 CFSocketCallBackType type; | 5010 CFSocketCallBackType type; |
5009 CFDataRef address; | 5011 CFDataRef address; |
5010 const void *data; | 5012 const void *data; |
5011 void *info; | 5013 void *info; |
5012 { | 5014 { |
5013 int fd = CFSocketGetNative (s); | |
5014 SELECT_TYPE *ofds = (SELECT_TYPE *)info; | |
5015 | |
5016 if ((type == kCFSocketReadCallBack && FD_ISSET (fd, &ofds[0])) | |
5017 || (type == kCFSocketConnectCallBack && FD_ISSET (fd, &ofds[1]))) | |
5018 QuitEventLoop (GetCurrentEventLoop ()); | |
5019 } | 5015 } |
5020 #endif /* SELECT_USE_CFSOCKET */ | 5016 #endif /* SELECT_USE_CFSOCKET */ |
5021 | 5017 |
5022 static int | 5018 static int |
5023 select_and_poll_event (nfds, rfds, wfds, efds, timeout) | 5019 select_and_poll_event (nfds, rfds, wfds, efds, timeout) |
5024 int nfds; | 5020 int nfds; |
5025 SELECT_TYPE *rfds, *wfds, *efds; | 5021 SELECT_TYPE *rfds, *wfds, *efds; |
5026 EMACS_TIME *timeout; | 5022 EMACS_TIME *timeout; |
5027 { | 5023 { |
5028 OSStatus err = noErr; | 5024 int timedout_p = 0; |
5029 int r = 0; | 5025 int r = 0; |
5030 | 5026 EMACS_TIME select_timeout; |
5031 /* Try detect_input_pending before ReceiveNextEvent in the same | 5027 EventTimeout timeoutval = |
5028 (timeout | |
5029 ? (EMACS_SECS (*timeout) * kEventDurationSecond | |
5030 + EMACS_USECS (*timeout) * kEventDurationMicrosecond) | |
5031 : kEventDurationForever); | |
5032 | |
5033 /* Try detect_input_pending before CFRunLoopRunInMode in the same | |
5032 BLOCK_INPUT block, in case that some input has already been read | 5034 BLOCK_INPUT block, in case that some input has already been read |
5033 asynchronously. */ | 5035 asynchronously. */ |
5034 BLOCK_INPUT; | 5036 BLOCK_INPUT; |
5035 ENABLE_WAKEUP_FROM_RNE; | 5037 do |
5036 if (!detect_input_pending ()) | 5038 { |
5037 { | 5039 if (detect_input_pending ()) |
5038 EMACS_TIME select_timeout; | 5040 break; |
5039 EventTimeout timeoutval = | |
5040 (timeout | |
5041 ? (EMACS_SECS (*timeout) * kEventDurationSecond | |
5042 + EMACS_USECS (*timeout) * kEventDurationMicrosecond) | |
5043 : kEventDurationForever); | |
5044 | 5041 |
5045 EMACS_SET_SECS_USECS (select_timeout, 0, 0); | 5042 EMACS_SET_SECS_USECS (select_timeout, 0, 0); |
5046 r = select (nfds, rfds, wfds, efds, &select_timeout); | 5043 r = select (nfds, rfds, wfds, efds, &select_timeout); |
5047 if (timeoutval == 0.0) | 5044 if (timeoutval == 0.0) |
5048 err = eventLoopTimedOutErr; | 5045 timedout_p = 1; |
5049 else if (r == 0) | 5046 else if (r == 0) |
5050 { | 5047 { |
5051 #if USE_CG_DRAWING | 5048 #if USE_CG_DRAWING |
5052 mac_prepare_for_quickdraw (NULL); | 5049 mac_prepare_for_quickdraw (NULL); |
5053 #endif | 5050 #endif |
5054 err = ReceiveNextEvent (0, NULL, timeoutval, | 5051 if (CFRunLoopRunInMode (kCFRunLoopDefaultMode, |
5055 kEventLeaveInQueue, NULL); | 5052 timeoutval >= 0 ? timeoutval : 10000.0, true) |
5056 } | 5053 == kCFRunLoopRunTimedOut) |
5057 } | 5054 timedout_p = 1; |
5058 DISABLE_WAKEUP_FROM_RNE; | 5055 } |
5056 } | |
5057 while (timeoutval < 0 && timedout_p); | |
5059 UNBLOCK_INPUT; | 5058 UNBLOCK_INPUT; |
5060 | 5059 |
5061 if (r != 0) | 5060 if (r != 0) |
5062 return r; | 5061 return r; |
5063 else if (err == noErr) | 5062 else if (!timedout_p) |
5064 { | 5063 { |
5065 /* Pretend that `select' is interrupted by a signal. */ | 5064 /* Pretend that `select' is interrupted by a signal. */ |
5066 detect_input_pending (); | 5065 detect_input_pending (); |
5067 errno = EINTR; | 5066 errno = EINTR; |
5068 return -1; | 5067 return -1; |
5075 sys_select (nfds, rfds, wfds, efds, timeout) | 5074 sys_select (nfds, rfds, wfds, efds, timeout) |
5076 int nfds; | 5075 int nfds; |
5077 SELECT_TYPE *rfds, *wfds, *efds; | 5076 SELECT_TYPE *rfds, *wfds, *efds; |
5078 EMACS_TIME *timeout; | 5077 EMACS_TIME *timeout; |
5079 { | 5078 { |
5080 OSStatus err = noErr; | 5079 int timedout_p = 0; |
5081 int r; | 5080 int r; |
5082 EMACS_TIME select_timeout; | 5081 EMACS_TIME select_timeout; |
5083 static SELECT_TYPE ofds[3]; | 5082 SELECT_TYPE orfds, owfds, oefds; |
5084 | 5083 |
5085 if (inhibit_window_system || noninteractive | 5084 if (inhibit_window_system || noninteractive |
5086 || nfds < 1 || rfds == NULL || !FD_ISSET (0, rfds)) | 5085 || nfds < 1 || rfds == NULL || !FD_ISSET (0, rfds)) |
5087 return select (nfds, rfds, wfds, efds, timeout); | 5086 return select (nfds, rfds, wfds, efds, timeout); |
5088 | 5087 |
5089 FD_CLR (0, rfds); | 5088 FD_CLR (0, rfds); |
5090 ofds[0] = *rfds; | 5089 orfds = *rfds; |
5091 | 5090 |
5092 if (wfds) | 5091 if (wfds) |
5093 ofds[1] = *wfds; | 5092 owfds = *wfds; |
5094 else | 5093 else |
5095 FD_ZERO (&ofds[1]); | 5094 FD_ZERO (&owfds); |
5096 | 5095 |
5097 if (efds) | 5096 if (efds) |
5098 ofds[2] = *efds; | 5097 oefds = *efds; |
5099 else | 5098 else |
5100 { | 5099 { |
5101 EventTimeout timeoutval = | 5100 EventTimeout timeoutval = |
5102 (timeout | 5101 (timeout |
5103 ? (EMACS_SECS (*timeout) * kEventDurationSecond | 5102 ? (EMACS_SECS (*timeout) * kEventDurationSecond |
5121 EMACS_SET_SECS_USECS (select_timeout, 0, 0); | 5120 EMACS_SET_SECS_USECS (select_timeout, 0, 0); |
5122 r = select_and_poll_event (nfds, rfds, wfds, efds, &select_timeout); | 5121 r = select_and_poll_event (nfds, rfds, wfds, efds, &select_timeout); |
5123 if (r != 0 || timeoutval == 0.0) | 5122 if (r != 0 || timeoutval == 0.0) |
5124 return r; | 5123 return r; |
5125 | 5124 |
5126 *rfds = ofds[0]; | 5125 *rfds = orfds; |
5127 if (wfds) | 5126 if (wfds) |
5128 *wfds = ofds[1]; | 5127 *wfds = owfds; |
5129 | 5128 |
5130 #if SELECT_USE_CFSOCKET | 5129 #if SELECT_USE_CFSOCKET |
5131 if (timeoutval > 0 && timeoutval <= SELECT_TIMEOUT_THRESHOLD_RUNLOOP) | 5130 if (timeoutval > 0 && timeoutval <= SELECT_TIMEOUT_THRESHOLD_RUNLOOP) |
5132 goto poll_periodically; | 5131 goto poll_periodically; |
5133 | 5132 |
5134 /* Try detect_input_pending before ReceiveNextEvent in the same | 5133 /* Try detect_input_pending before CFRunLoopRunInMode in the |
5135 BLOCK_INPUT block, in case that some input has already been | 5134 same BLOCK_INPUT block, in case that some input has already |
5136 read asynchronously. */ | 5135 been read asynchronously. */ |
5137 BLOCK_INPUT; | 5136 BLOCK_INPUT; |
5138 ENABLE_WAKEUP_FROM_RNE; | |
5139 if (!detect_input_pending ()) | 5137 if (!detect_input_pending ()) |
5140 { | 5138 { |
5141 int minfd, fd; | 5139 int minfd, fd; |
5142 CFRunLoopRef runloop = | 5140 CFRunLoopRef runloop = |
5143 (CFRunLoopRef) GetCFRunLoopFromEventLoop (GetCurrentEventLoop ()); | 5141 (CFRunLoopRef) GetCFRunLoopFromEventLoop (GetCurrentEventLoop ()); |
5144 static const CFSocketContext context = {0, ofds, NULL, NULL, NULL}; | |
5145 static CFMutableDictionaryRef sources; | 5142 static CFMutableDictionaryRef sources; |
5146 | 5143 |
5147 if (sources == NULL) | 5144 if (sources == NULL) |
5148 sources = | 5145 sources = |
5149 CFDictionaryCreateMutable (NULL, 0, NULL, | 5146 CFDictionaryCreateMutable (NULL, 0, NULL, |
5164 { | 5161 { |
5165 CFSocketRef socket = | 5162 CFSocketRef socket = |
5166 CFSocketCreateWithNative (NULL, fd, | 5163 CFSocketCreateWithNative (NULL, fd, |
5167 (kCFSocketReadCallBack | 5164 (kCFSocketReadCallBack |
5168 | kCFSocketConnectCallBack), | 5165 | kCFSocketConnectCallBack), |
5169 socket_callback, &context); | 5166 socket_callback, NULL); |
5170 | 5167 |
5171 if (socket == NULL) | 5168 if (socket == NULL) |
5172 continue; | 5169 continue; |
5173 source = CFSocketCreateRunLoopSource (NULL, socket, 0); | 5170 source = CFSocketCreateRunLoopSource (NULL, socket, 0); |
5174 CFRelease (socket); | 5171 CFRelease (socket); |
5181 } | 5178 } |
5182 | 5179 |
5183 #if USE_CG_DRAWING | 5180 #if USE_CG_DRAWING |
5184 mac_prepare_for_quickdraw (NULL); | 5181 mac_prepare_for_quickdraw (NULL); |
5185 #endif | 5182 #endif |
5186 err = ReceiveNextEvent (0, NULL, timeoutval, | 5183 if (CFRunLoopRunInMode (kCFRunLoopDefaultMode, |
5187 kEventLeaveInQueue, NULL); | 5184 timeoutval >= 0 ? timeoutval : 10000.0, true) |
5185 == kCFRunLoopRunTimedOut) | |
5186 timedout_p = 1; | |
5188 | 5187 |
5189 for (fd = minfd; fd < nfds; fd++) | 5188 for (fd = minfd; fd < nfds; fd++) |
5190 if (FD_ISSET (fd, rfds) || (wfds && FD_ISSET (fd, wfds))) | 5189 if (FD_ISSET (fd, rfds) || (wfds && FD_ISSET (fd, wfds))) |
5191 { | 5190 { |
5192 void *key = (void *) fd; | 5191 void *key = (void *) fd; |
5194 (CFRunLoopSourceRef) CFDictionaryGetValue (sources, key); | 5193 (CFRunLoopSourceRef) CFDictionaryGetValue (sources, key); |
5195 | 5194 |
5196 CFRunLoopRemoveSource (runloop, source, kCFRunLoopDefaultMode); | 5195 CFRunLoopRemoveSource (runloop, source, kCFRunLoopDefaultMode); |
5197 } | 5196 } |
5198 } | 5197 } |
5199 DISABLE_WAKEUP_FROM_RNE; | |
5200 UNBLOCK_INPUT; | 5198 UNBLOCK_INPUT; |
5201 | 5199 |
5202 if (err == noErr || err == eventLoopQuitErr) | 5200 if (!timedout_p) |
5203 { | 5201 { |
5204 EMACS_SET_SECS_USECS (select_timeout, 0, 0); | 5202 EMACS_SET_SECS_USECS (select_timeout, 0, 0); |
5205 return select_and_poll_event (nfds, rfds, wfds, efds, | 5203 return select_and_poll_event (nfds, rfds, wfds, efds, |
5206 &select_timeout); | 5204 &select_timeout); |
5207 } | 5205 } |
5233 select_timeout = remaining_time; | 5231 select_timeout = remaining_time; |
5234 r = select_and_poll_event (nfds, rfds, wfds, efds, &select_timeout); | 5232 r = select_and_poll_event (nfds, rfds, wfds, efds, &select_timeout); |
5235 if (r != 0) | 5233 if (r != 0) |
5236 return r; | 5234 return r; |
5237 | 5235 |
5238 *rfds = ofds[0]; | 5236 *rfds = orfds; |
5239 if (wfds) | 5237 if (wfds) |
5240 *wfds = ofds[1]; | 5238 *wfds = owfds; |
5241 if (efds) | 5239 if (efds) |
5242 *efds = ofds[2]; | 5240 *efds = oefds; |
5243 | 5241 |
5244 if (timeout) | 5242 if (timeout) |
5245 { | 5243 { |
5246 EMACS_GET_TIME (now); | 5244 EMACS_GET_TIME (now); |
5247 EMACS_SUB_TIME (remaining_time, end_time, now); | 5245 EMACS_SUB_TIME (remaining_time, end_time, now); |
5400 | 5398 |
5401 #if TARGET_API_MAC_CARBON | 5399 #if TARGET_API_MAC_CARBON |
5402 void | 5400 void |
5403 mac_wakeup_from_rne () | 5401 mac_wakeup_from_rne () |
5404 { | 5402 { |
5403 #ifndef MAC_OSX | |
5405 if (wakeup_from_rne_enabled_p) | 5404 if (wakeup_from_rne_enabled_p) |
5406 /* Post a harmless event so as to wake up from | 5405 /* Post a harmless event so as to wake up from |
5407 ReceiveNextEvent. */ | 5406 ReceiveNextEvent. */ |
5408 mac_post_mouse_moved_event (); | 5407 mac_post_mouse_moved_event (); |
5408 #endif | |
5409 } | 5409 } |
5410 #endif | 5410 #endif |
5411 | 5411 |
5412 void | 5412 void |
5413 syms_of_mac () | 5413 syms_of_mac () |