From 38abb09a2e4c682d0dcbe2d592c32bf0f9c2d1c5 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Mon, 20 May 2013 12:55:50 +1000 Subject: [PATCH] runtime: change PollDesc.fd from int32 to uintptr This is in preparation for netpoll windows version. R=golang-dev, bradfitz CC=dvyukov, golang-dev, mikioh.mikioh https://golang.org/cl/9569043 --- src/pkg/net/fd_poll_runtime.go | 4 ++-- src/pkg/runtime/netpoll.goc | 6 +++--- src/pkg/runtime/netpoll_epoll.c | 8 ++++---- src/pkg/runtime/netpoll_kqueue.c | 10 +++++----- src/pkg/runtime/runtime.h | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/pkg/net/fd_poll_runtime.go b/src/pkg/net/fd_poll_runtime.go index e3b4f7e464..e71ded589c 100644 --- a/src/pkg/net/fd_poll_runtime.go +++ b/src/pkg/net/fd_poll_runtime.go @@ -13,7 +13,7 @@ import ( ) func runtime_pollServerInit() -func runtime_pollOpen(fd int) (uintptr, int) +func runtime_pollOpen(fd uintptr) (uintptr, int) func runtime_pollClose(ctx uintptr) func runtime_pollWait(ctx uintptr, mode int) int func runtime_pollReset(ctx uintptr, mode int) int @@ -33,7 +33,7 @@ func sysInit() { func (pd *pollDesc) Init(fd *netFD) error { serverInit.Do(runtime_pollServerInit) - ctx, errno := runtime_pollOpen(fd.sysfd) + ctx, errno := runtime_pollOpen(uintptr(fd.sysfd)) if errno != 0 { return syscall.Errno(errno) } diff --git a/src/pkg/runtime/netpoll.goc b/src/pkg/runtime/netpoll.goc index 06b6d61727..0ab75cf0da 100644 --- a/src/pkg/runtime/netpoll.goc +++ b/src/pkg/runtime/netpoll.goc @@ -14,7 +14,7 @@ package net // Integrated network poller (platform-independent part). // A particular implementation (epoll/kqueue) must define the following functions: // void runtime·netpollinit(void); // to initialize the poller -// int32 runtime·netpollopen(int32 fd, PollDesc *pd); // to arm edge-triggered notifications +// int32 runtime·netpollopen(uintptr fd, PollDesc *pd); // to arm edge-triggered notifications // and associate fd with pd. // An implementation must call the following function to denote that the pd is ready. // void runtime·netpollready(G **gpp, PollDesc *pd, int32 mode); @@ -25,7 +25,7 @@ struct PollDesc { PollDesc* link; // in pollcache, protected by pollcache.Lock Lock; // protectes the following fields - int32 fd; + uintptr fd; bool closing; uintptr seq; // protects from stale timers and ready notifications G* rg; // G waiting for read or READY (binary semaphore) @@ -63,7 +63,7 @@ func runtime_pollServerInit() { runtime·netpollinit(); } -func runtime_pollOpen(fd int) (pd *PollDesc, errno int) { +func runtime_pollOpen(fd uintptr) (pd *PollDesc, errno int) { pd = allocPollDesc(); runtime·lock(pd); if(pd->wg != nil && pd->wg != READY) diff --git a/src/pkg/runtime/netpoll_epoll.c b/src/pkg/runtime/netpoll_epoll.c index 9b5980700e..885ac5e4df 100644 --- a/src/pkg/runtime/netpoll_epoll.c +++ b/src/pkg/runtime/netpoll_epoll.c @@ -31,24 +31,24 @@ runtime·netpollinit(void) } int32 -runtime·netpollopen(int32 fd, PollDesc *pd) +runtime·netpollopen(uintptr fd, PollDesc *pd) { EpollEvent ev; int32 res; ev.events = EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET; ev.data = (uint64)pd; - res = runtime·epollctl(epfd, EPOLL_CTL_ADD, fd, &ev); + res = runtime·epollctl(epfd, EPOLL_CTL_ADD, (int32)fd, &ev); return -res; } int32 -runtime·netpollclose(int32 fd) +runtime·netpollclose(uintptr fd) { EpollEvent ev; int32 res; - res = runtime·epollctl(epfd, EPOLL_CTL_DEL, fd, &ev); + res = runtime·epollctl(epfd, EPOLL_CTL_DEL, (int32)fd, &ev); return -res; } diff --git a/src/pkg/runtime/netpoll_kqueue.c b/src/pkg/runtime/netpoll_kqueue.c index 0ed03d31fa..6718c6fc8f 100644 --- a/src/pkg/runtime/netpoll_kqueue.c +++ b/src/pkg/runtime/netpoll_kqueue.c @@ -27,7 +27,7 @@ runtime·netpollinit(void) } int32 -runtime·netpollopen(int32 fd, PollDesc *pd) +runtime·netpollopen(uintptr fd, PollDesc *pd) { Kevent ev[2]; int32 n; @@ -35,7 +35,7 @@ runtime·netpollopen(int32 fd, PollDesc *pd) // Arm both EVFILT_READ and EVFILT_WRITE in edge-triggered mode (EV_CLEAR) // for the whole fd lifetime. The notifications are automatically unregistered // when fd is closed. - ev[0].ident = fd; + ev[0].ident = (uint32)fd; ev[0].filter = EVFILT_READ; ev[0].flags = EV_ADD|EV_RECEIPT|EV_CLEAR; ev[0].fflags = 0; @@ -47,8 +47,8 @@ runtime·netpollopen(int32 fd, PollDesc *pd) if(n < 0) return -n; if(n != 2 || - (ev[0].flags&EV_ERROR) == 0 || ev[0].ident != fd || ev[0].filter != EVFILT_READ || - (ev[1].flags&EV_ERROR) == 0 || ev[1].ident != fd || ev[1].filter != EVFILT_WRITE) + (ev[0].flags&EV_ERROR) == 0 || ev[0].ident != (uint32)fd || ev[0].filter != EVFILT_READ || + (ev[1].flags&EV_ERROR) == 0 || ev[1].ident != (uint32)fd || ev[1].filter != EVFILT_WRITE) return EFAULT; // just to mark out from other errors if(ev[0].data != 0) return ev[0].data; @@ -58,7 +58,7 @@ runtime·netpollopen(int32 fd, PollDesc *pd) } int32 -runtime·netpollclose(int32 fd) +runtime·netpollclose(uintptr fd) { // Don't need to unregister because calling close() // on fd will remove any kevents that reference the descriptor. diff --git a/src/pkg/runtime/runtime.h b/src/pkg/runtime/runtime.h index cb72b92d67..ef162e9bbb 100644 --- a/src/pkg/runtime/runtime.h +++ b/src/pkg/runtime/runtime.h @@ -803,8 +803,8 @@ void runtime·addtimer(Timer*); bool runtime·deltimer(Timer*); G* runtime·netpoll(bool); void runtime·netpollinit(void); -int32 runtime·netpollopen(int32, PollDesc*); -int32 runtime·netpollclose(int32); +int32 runtime·netpollopen(uintptr, PollDesc*); +int32 runtime·netpollclose(uintptr); void runtime·netpollready(G**, PollDesc*, int32); void runtime·crash(void);