add epoll implementation to libwine_port (take 3)
Mike McCormack
mike at codeweavers.com
Tue Oct 19 03:55:29 CDT 2004
A few more changes after consulting with Alexandre.
ChangeLog:
* add epoll implementation to libwine_port
-------------- next part --------------
Index: server/fd.c
===================================================================
RCS file: /home/wine/wine/server/fd.c,v
retrieving revision 1.27
diff -u -r1.27 fd.c
--- server/fd.c 23 Sep 2004 04:48:24 -0000 1.27
+++ server/fd.c 19 Oct 2004 07:09:05 -0000
@@ -54,10 +54,6 @@
#include "winreg.h"
#include "winternl.h"
-#if defined(HAVE_SYS_EPOLL_H) && defined(HAVE_EPOLL_CREATE)
-# define USE_EPOLL
-#endif
-
/* Because of the stupid Posix locking semantics, we need to keep
* track of all file descriptors referencing a given file, and not
* close a single one until all the locks are gone (sigh).
@@ -246,8 +242,6 @@
static int allocated_users; /* count of allocated entries in the array */
static struct fd **freelist; /* list of free entries in the array */
-#ifdef USE_EPOLL
-
static int epoll_fd;
static struct epoll_event *epoll_events;
@@ -289,15 +283,6 @@
}
}
-#else /* USE_EPOLL */
-
-static inline void set_fd_epoll_events( struct fd *fd, int user, int events )
-{
-}
-
-#endif /* USE_EPOLL */
-
-
/* add a user in the poll array and return its index, or -1 on failure */
static int add_poll_user( struct fd *fd )
{
@@ -325,7 +310,7 @@
}
poll_users = newusers;
pollfd = newpoll;
-#ifdef USE_EPOLL
+
if (!allocated_users) epoll_fd = epoll_create( new_count );
if (epoll_fd != -1)
{
@@ -334,7 +319,7 @@
return -1;
epoll_events = new_events;
}
-#endif
+
allocated_users = new_count;
}
ret = nb_users++;
@@ -353,13 +338,12 @@
assert( user >= 0 );
assert( poll_users[user] == fd );
-#ifdef USE_EPOLL
if (epoll_fd != -1 && pollfd[user].fd != -1)
{
struct epoll_event dummy;
epoll_ctl( epoll_fd, EPOLL_CTL_DEL, fd->unix_fd, &dummy );
}
-#endif
+
pollfd[user].fd = -1;
pollfd[user].events = 0;
pollfd[user].revents = 0;
@@ -420,7 +404,6 @@
{
int i, ret, timeout;
-#ifdef USE_EPOLL
assert( POLLIN == EPOLLIN );
assert( POLLOUT == EPOLLOUT );
assert( POLLERR == EPOLLERR );
@@ -453,7 +436,6 @@
}
}
/* fall through to normal poll loop */
-#endif /* USE_EPOLL */
while (active_users)
{
Index: libs/port/Makefile.in
===================================================================
RCS file: /home/wine/wine/libs/port/Makefile.in,v
retrieving revision 1.12
diff -u -r1.12 Makefile.in
--- libs/port/Makefile.in 7 Oct 2004 04:25:05 -0000 1.12
+++ libs/port/Makefile.in 19 Oct 2004 07:09:05 -0000
@@ -7,6 +7,7 @@
MODULE = libwine_port.a
C_SRCS = \
+ epoll.c \
fstatvfs.c \
futimes.c \
getopt.c \
Index: include/wine/port.h
===================================================================
RCS file: /home/wine/wine/include/wine/port.h,v
retrieving revision 1.62
diff -u -r1.62 port.h
--- include/wine/port.h 11 Oct 2004 20:22:06 -0000 1.62
+++ include/wine/port.h 19 Oct 2004 07:09:05 -0000
@@ -43,6 +43,9 @@
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
/****************************************************************
@@ -252,6 +255,31 @@
*/
#ifndef NO_LIBWINE_PORT
+
+#ifndef HAVE_SYS_EPOLL_H
+
+enum EPOLL_EVENTS
+{
+ EPOLLIN = 0x001,
+ EPOLLPRI = 0x002,
+ EPOLLOUT = 0x004,
+ EPOLLERR = 0x008,
+ EPOLLHUP = 0x010
+};
+
+typedef union epoll_data {
+ void *ptr;
+ int fd;
+ __uint32_t u32;
+ __uint64_t u64;
+} epoll_data_t;
+
+struct epoll_event {
+ __uint32_t events;
+ epoll_data_t data;
+};
+
+#endif
#ifndef HAVE_FSTATVFS
int fstatvfs( int fd, struct statvfs *buf );
--- /dev/null 1994-07-18 08:46:18.000000000 +0900
+++ libs/port/epoll.c 2004-10-19 13:26:03.000000000 +0900
@@ -0,0 +1,105 @@
+/*
+ * epoll syscall implementation
+ *
+ * Copyright (C) 2004 The Free Software Foundation, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#ifdef HAVE_SYS_EPOLL_H
+#include <sys/epoll.h>
+#endif
+#include <errno.h>
+#ifdef HAVE_SYS_ERRNO_H
+#include <sys/errno.h>
+#endif
+
+#ifndef HAVE_EPOLL_CREATE
+
+#ifdef linux
+
+#ifndef __NR_epoll_create
+#define __NR_epoll_create 254
+#endif
+
+#ifndef __NR_epoll_ctl
+#define __NR_epoll_ctl 255
+#endif
+
+#ifndef __NR_epoll_wait
+#define __NR_epoll_wait 256
+#endif
+
+#define SET_ERRNO(ret) \
+ if ((ret < 0) && (ret > -4096)) \
+ { \
+ errno = ret; \
+ ret = -1; \
+ }
+
+int epoll_create( int size )
+{
+ int ret;
+ __asm__ __volatile__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
+ : "=a" (ret) : "0" (__NR_epoll_create), "g" (size) );
+ SET_ERRNO(ret)
+ return ret;
+}
+
+int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
+{
+ int ret;
+ __asm__ __volatile__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
+ : "=a" (ret)
+ : "0" (__NR_epoll_ctl),
+ "g" (epfd), "c" (op), "d" (fd), "S" (event) );
+ SET_ERRNO(ret)
+ return ret;
+}
+
+int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
+{
+ int ret;
+ __asm__ __volatile__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
+ : "=a" (ret)
+ : "0" (__NR_epoll_wait),
+ "g" (epfd), "c" (events), "d" (maxevents), "S" (timeout) );
+ SET_ERRNO(ret)
+ return ret;
+}
+
+#else
+
+int epoll_create( int size )
+{
+ return -ENOSYS;
+}
+
+int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
+{
+ return -ENOSYS;
+}
+
+int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
+{
+ return -ENOSYS;
+}
+
+#endif
+
+#endif
More information about the wine-patches
mailing list