Prevent overruns in DL11
This commit is contained in:
@@ -11,6 +11,8 @@ import com.thequux.mcpdp.ext.bit.maskSet
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.util.concurrent.Semaphore
|
||||
import java.util.concurrent.locks.Lock
|
||||
import java.util.concurrent.locks.LockSupport
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
|
||||
@@ -47,7 +49,7 @@ class DL11(private var istr: InputStream, private val ostr: OutputStream, val re
|
||||
rcsr = rcsr bic 15
|
||||
oldRcsr
|
||||
}
|
||||
2 -> { rcsr = rcsr bic 7; rbuf }
|
||||
2 -> { rcsr = rcsr bic 7; LockSupport.unpark(reader); rbuf }
|
||||
4 -> xcsr
|
||||
6 -> 0u
|
||||
else -> throw OddAddressError(addr)
|
||||
@@ -88,10 +90,14 @@ class DL11(private var istr: InputStream, private val ostr: OutputStream, val re
|
||||
try {
|
||||
while (true) {
|
||||
val data = istr.read()
|
||||
// wait for rcsr to be read
|
||||
while (synchronized(this) {(rcsr bit 7 || xcsr bit 2)}) {
|
||||
LockSupport.park()
|
||||
}
|
||||
|
||||
synchronized(this) {
|
||||
// receive if not in maintenance mode
|
||||
// TODO: block until receiver ready
|
||||
if (!(xcsr bit 1)) recvByte(data)
|
||||
if (!(xcsr bit 2)) recvByte(data)
|
||||
}
|
||||
if (data < 0) {
|
||||
break
|
||||
@@ -104,8 +110,7 @@ class DL11(private var istr: InputStream, private val ostr: OutputStream, val re
|
||||
override fun start() {
|
||||
super.start()
|
||||
reader = thread(block = this::readThread, isDaemon = false)
|
||||
|
||||
// reader?.interrupt()
|
||||
LockSupport.unpark(reader)
|
||||
}
|
||||
|
||||
override fun stop() {
|
||||
|
Reference in New Issue
Block a user