1 /* |
1 /* |
2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package sun.nio.ch; |
26 package sun.nio.ch; |
27 |
27 |
28 import java.io.*; |
28 import java.io.FileDescriptor; |
|
29 import java.io.IOException; |
29 import java.nio.ByteBuffer; |
30 import java.nio.ByteBuffer; |
30 import java.nio.channels.*; |
31 import java.nio.channels.ClosedChannelException; |
31 import java.nio.channels.spi.*; |
32 import java.nio.channels.Pipe; |
|
33 import java.nio.channels.SelectionKey; |
|
34 import java.nio.channels.spi.SelectorProvider; |
|
35 import java.util.concurrent.locks.ReentrantLock; |
32 |
36 |
33 |
37 |
34 class SourceChannelImpl |
38 class SourceChannelImpl |
35 extends Pipe.SourceChannel |
39 extends Pipe.SourceChannel |
36 implements SelChImpl |
40 implements SelChImpl |
38 |
42 |
39 // Used to make native read and write calls |
43 // Used to make native read and write calls |
40 private static final NativeDispatcher nd = new FileDispatcherImpl(); |
44 private static final NativeDispatcher nd = new FileDispatcherImpl(); |
41 |
45 |
42 // The file descriptor associated with this channel |
46 // The file descriptor associated with this channel |
43 FileDescriptor fd; |
47 private final FileDescriptor fd; |
44 |
48 |
45 // fd value needed for dev/poll. This value will remain valid |
49 // fd value needed for dev/poll. This value will remain valid |
46 // even after the value in the file descriptor object has been set to -1 |
50 // even after the value in the file descriptor object has been set to -1 |
47 int fdVal; |
51 private final int fdVal; |
48 |
52 |
49 // ID of native thread doing read, for signalling |
53 // ID of native thread doing read, for signalling |
50 private volatile long thread; |
54 private volatile long thread; |
51 |
55 |
52 // Lock held by current reading thread |
56 // Lock held by current reading thread |
53 private final Object lock = new Object(); |
57 private final ReentrantLock readLock = new ReentrantLock(); |
54 |
58 |
55 // Lock held by any thread that modifies the state fields declared below |
59 // Lock held by any thread that modifies the state fields declared below |
56 // DO NOT invoke a blocking I/O operation while holding this lock! |
60 // DO NOT invoke a blocking I/O operation while holding this lock! |
57 private final Object stateLock = new Object(); |
61 private final Object stateLock = new Object(); |
58 |
62 |