Files
android_development/ndk/sources/android/libportable/arch-mips/poll.c
Pete Delaney 2928edfab9 [MIPS] Tighten up code to fit within 100 characters lines.
File poll.c had a wide line and the reason for the asymmetric
mapping of the event flags wasn't obvious on my reviewing
this code. Seemed to justify adding some clarification.

Both signal.c and socket.c were using lengthy function names
for Portable <--> Native mappings. Switch to the newer *_ntop()
style in wide files and made the ALOGV() messages more useful.

Also changed mapping of portable SIGSTKFLT to native SIGEMT
while editing a wide line in the signal.c file.  MIPS has no
SIGSTKFLT signal, nor ARM a signal SIGEMT. Using SIGEMT as a
proxy for SIGSTKFLT_PORTABLE for Lib-Portable applications.
This makes the signal mapping reversible during signal handling.

Fixed ALOGV() Entry/Exit brackets to match.

Change-Id: I9a91992e67ab24322db608424bf69c47fad8e18d
Signed-off-by: Pete Delaney <piet.delaney@imgtec.com>
Signed-off-by: Chris Dearman <chris.dearman@imgtec.com>
Signed-off-by: Paul Lind <paul.lind@imgtec.com>
2013-02-20 20:01:15 -08:00

125 lines
4.5 KiB
C

/*
* Copyright 2012, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <poll.h>
#include <poll_portable.h>
/*
*_XOPEN_SOURCE added the ability to not only poll for data coming in or out
* but now also the ability to poll for high priority input and output. Though
* the normal priority is equivalent to the original I/O it was assigned new bits:
* POLLIN Equivalent to POLLRDNORM
* POLLOUT Equivalent to POLLWRNORM
*
* The Linux kernel sets both POLLIN and POLLRDNORM when data is available and sets
* both POLLOUT and POLLWRNORM when data can be written; so the new priority BAND bits
* just supplement the meaning of the prior POLLIN and POLLOUT bits as well as the
* new POLLRDNORM and POLLWRNORM bits.
*
* The DECNet Protocol can set the poll in priority flag, POLLRDBAND.
* ATM as well as a whole bunch of other protocols can set the poll out priority flag,
* POLLWRBAND.
*
* MIPS and SPARC likely assigned the new XOPEN poll out event flags in UNIX well before
* UNIX was ported to X86. It appears that Intel chose different bits and that was
* established by Linus as the the generic case and later also chosen by ARM.
*
* POLLWRNORM:0x100 - MIPS used POLLOUT:0x0004, which is equivalent in meaning.
*
* POLLWRBAND:0x200 - MIPS used 0x0100. which is POLLWRNORM:0x100.
*
* Summary:
* ========
* Both Normal and Priority flags can be mapped to MIPS flags (left to right below).
* Only the Priority poll out flag can be mapped back to portable because MIPS
* is using the same number as POLLOUT for POLLWRNORM (right to left below).
*
* ARM/GENERIC/PORTABLE MIPS
* ==================== ======
* POLLIN 0x0001 0x0001
* POLLPRI 0x0002 0x0002
* POLLOUT 0x0004 <-----+ 0x0004
* POLLERR 0x0008 \ 0x0008
* POLLHUP 0x0010 \ 0x0010
* POLLNVAL 0x0020 \ 0x0020
* POLLRDNORM 0x0040 \ 0x0040
* POLLRDBAND 0x0080 \ 0x0080
* POLLWRNORM 0x0100 -----------+<----> 0x0004
* POLLWRBAND 0x0200 <-----------------> 0x0100
* POLLMSG 0x0400 0x0400
* POLLREMOVE 0x1000 0x1000
* POLLRDHUP 0x2000 0x2000
*
* The loss of the high priority notice for the polling
* of output data is likely minor as it was only being used
* in DECNet. Also, the poll system call and device poll
* implementations processes POLLOUT and POLLWRNORM event
* flags the same.
*/
#if POLLWRNORM_PORTABLE==POLLWRNORM
#error Bad build environment
#endif
static inline short mips_change_portable_events(short portable_events)
{
/* MIPS has different POLLWRNORM and POLLWRBAND. */
if (portable_events & POLLWRNORM_PORTABLE) {
portable_events &= ~POLLWRNORM_PORTABLE;
portable_events |= POLLWRNORM;
}
if (portable_events & POLLWRBAND_PORTABLE) {
portable_events &= ~POLLWRBAND_PORTABLE;
portable_events |= POLLWRBAND;
}
return portable_events;
}
static inline short change_mips_events(short mips_events)
{
/*
* MIPS POLLWRNORM equals MIPS POLLOUT, which is the same as POLLOUT_PORTABLE;
* so we just map POLLWRBAND to POLLWRBAND_PORTABLE.
*/
if (mips_events & POLLWRBAND) {
mips_events &= ~POLLWRBAND;
mips_events |= POLLWRBAND_PORTABLE;
}
return mips_events;
}
extern int poll(struct pollfd *, nfds_t, long);
int poll_portable(struct pollfd *fds, nfds_t nfds, long timeout)
{
nfds_t i;
int ret;
for (i = 0; i < nfds; i++)
fds->events = mips_change_portable_events(fds->events);
ret = poll(fds, nfds, timeout);
for (i = 0; i < nfds; i++) {
fds->events = change_mips_events(fds->events);
fds->revents = change_mips_events(fds->revents);
}
return ret;
}