From 4cd3283046090736ef32259fb5d38c9ba944d12f Mon Sep 17 00:00:00 2001 From: Chao-Ying Fu Date: Tue, 21 Aug 2012 15:27:38 -0700 Subject: [PATCH] Support poll for MIPS. Change-Id: I1299817ea06c9f9ff5701dce0c6166370ef9e87d --- ndk/sources/android/libportable/Android.mk | 1 + .../android/libportable/arch-mips/poll.c | 68 +++++++++++++++++++ .../common/include/poll_portable.h | 37 ++++++++++ 3 files changed, 106 insertions(+) create mode 100644 ndk/sources/android/libportable/arch-mips/poll.c create mode 100644 ndk/sources/android/libportable/common/include/poll_portable.h diff --git a/ndk/sources/android/libportable/Android.mk b/ndk/sources/android/libportable/Android.mk index a4f5a6c1c..c6823c0c4 100644 --- a/ndk/sources/android/libportable/Android.mk +++ b/ndk/sources/android/libportable/Android.mk @@ -35,6 +35,7 @@ libportable_arch_src_files += \ arch-mips/stat.c \ arch-mips/statfs.c \ arch-mips/open.c \ + arch-mips/poll.c \ arch-mips/socket.c \ arch-mips/sockopt.c \ arch-mips/fcntl.c \ diff --git a/ndk/sources/android/libportable/arch-mips/poll.c b/ndk/sources/android/libportable/arch-mips/poll.c new file mode 100644 index 000000000..955c094ad --- /dev/null +++ b/ndk/sources/android/libportable/arch-mips/poll.c @@ -0,0 +1,68 @@ +/* + * 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 +#include + +#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 POLLOUT that is the same as POLLOUT_PORTABLE, so we just update POLLWRBNAD_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; +} diff --git a/ndk/sources/android/libportable/common/include/poll_portable.h b/ndk/sources/android/libportable/common/include/poll_portable.h new file mode 100644 index 000000000..4004d1887 --- /dev/null +++ b/ndk/sources/android/libportable/common/include/poll_portable.h @@ -0,0 +1,37 @@ +/* + * 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. + */ + +#ifndef _POLL_PORTABLE_H_ +#define _POLL_PORTABLE_H_ + +/* Derived from development/ndk/platforms/android-3/arch-arm/include/asm/poll.h */ + +#define POLLIN_PORTABLE 0x0001 +#define POLLPRI_PORTABLE 0x0002 +#define POLLOUT_PORTABLE 0x0004 +#define POLLERR_PORTABLE 0x0008 +#define POLLHUP_PORTABLE 0x0010 +#define POLLNVAL_PORTABLE 0x0020 + +#define POLLRDNORM_PORTABLE 0x0040 +#define POLLRDBAND_PORTABLE 0x0080 +#define POLLWRNORM_PORTABLE 0x0100 +#define POLLWRBAND_PORTABLE 0x0200 +#define POLLMSG_PORTABLE 0x0400 +#define POLLREMOVE_PORTABLE 0x1000 +#define POLLRDHUP_PORTABLE 0x2000 + +#endif /* _POLL_PORTABLE_H_ */