]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: change PollDesc.fd from int32 to uintptr
authorAlex Brainman <alex.brainman@gmail.com>
Mon, 20 May 2013 02:55:50 +0000 (12:55 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Mon, 20 May 2013 02:55:50 +0000 (12:55 +1000)
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
src/pkg/runtime/netpoll.goc
src/pkg/runtime/netpoll_epoll.c
src/pkg/runtime/netpoll_kqueue.c
src/pkg/runtime/runtime.h

index e3b4f7e464801f1aebe446190136f29339140b36..e71ded589c9db2aa0f3d5d5d6b653ee6e64a8f32 100644 (file)
@@ -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)
        }
index 06b6d61727fc481c4a0fc933e6043a76deb9d20b..0ab75cf0da23f498dcdfaef3f7e1eca83dc6a43e 100644 (file)
@@ -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)
index 9b5980700ecd8db59939dccdafc0ac98d866cb37..885ac5e4dfc7829e9dbebec9c20d00cdb5ececbd 100644 (file)
@@ -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;
 }
 
index 0ed03d31fa39807e7c8ea15d4487cb9ef0fe003e..6718c6fc8f753b9041c2408935e25e08243e01e2 100644 (file)
@@ -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.
index cb72b92d67d0afd5a1c8f151ef02b5362ad17826..ef162e9bbbb34339f41af9491f2fe60b3e385248 100644 (file)
@@ -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);