< prev index next >

src/java.base/linux/classes/sun/nio/ch/EPollPort.java

Print this page
rev 49242 : [mq]: selector-cleanup
   1 /*
   2  * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  76 
  77     // queue of events for cases that a polling thread dequeues more than one
  78     // event
  79     private final ArrayBlockingQueue<Event> queue;
  80     private final Event NEED_TO_POLL = new Event(null, 0);
  81     private final Event EXECUTE_TASK_OR_SHUTDOWN = new Event(null, 0);
  82 
  83     EPollPort(AsynchronousChannelProvider provider, ThreadPool pool)
  84         throws IOException
  85     {
  86         super(provider, pool);
  87 
  88         // open epoll
  89         this.epfd = epollCreate();
  90 
  91         // create socket pair for wakeup mechanism
  92         int[] sv = new int[2];
  93         try {
  94             socketpair(sv);
  95             // register one end with epoll
  96             epollCtl(epfd, EPOLL_CTL_ADD, sv[0], Net.POLLIN);
  97         } catch (IOException x) {
  98             close0(epfd);
  99             throw x;
 100         }
 101         this.sp = sv;
 102 
 103         // allocate the poll array
 104         this.address = allocatePollArray(MAX_EPOLL_EVENTS);
 105 
 106         // create the queue and offer the special event to ensure that the first
 107         // threads polls
 108         this.queue = new ArrayBlockingQueue<>(MAX_EPOLL_EVENTS);
 109         this.queue.offer(NEED_TO_POLL);
 110     }
 111 
 112     EPollPort start() {
 113         startThreads(new EventHandlerTask());
 114         return this;
 115     }
 116 


   1 /*
   2  * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  76 
  77     // queue of events for cases that a polling thread dequeues more than one
  78     // event
  79     private final ArrayBlockingQueue<Event> queue;
  80     private final Event NEED_TO_POLL = new Event(null, 0);
  81     private final Event EXECUTE_TASK_OR_SHUTDOWN = new Event(null, 0);
  82 
  83     EPollPort(AsynchronousChannelProvider provider, ThreadPool pool)
  84         throws IOException
  85     {
  86         super(provider, pool);
  87 
  88         // open epoll
  89         this.epfd = epollCreate();
  90 
  91         // create socket pair for wakeup mechanism
  92         int[] sv = new int[2];
  93         try {
  94             socketpair(sv);
  95             // register one end with epoll
  96             epollCtl(epfd, EPOLL_CTL_ADD, sv[0], EPOLLIN);
  97         } catch (IOException x) {
  98             close0(epfd);
  99             throw x;
 100         }
 101         this.sp = sv;
 102 
 103         // allocate the poll array
 104         this.address = allocatePollArray(MAX_EPOLL_EVENTS);
 105 
 106         // create the queue and offer the special event to ensure that the first
 107         // threads polls
 108         this.queue = new ArrayBlockingQueue<>(MAX_EPOLL_EVENTS);
 109         this.queue.offer(NEED_TO_POLL);
 110     }
 111 
 112     EPollPort start() {
 113         startThreads(new EventHandlerTask());
 114         return this;
 115     }
 116 


< prev index next >