Skip to content

Update to Scala Native 0.4.4 and remove workaround #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions core/src/main/scala/scala/scalanative/loop/Eventloop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object EventLoop {

def run(): Unit = {
while (uv_loop_alive(loop) != 0 || queue.nonEmpty) {
while(queue.nonEmpty) {
while (queue.nonEmpty) {
val runnable = queue.remove(0)
try {
runnable.run()
Expand Down Expand Up @@ -66,9 +66,7 @@ object LibUV {
type PrepareCB = CFuncPtr1[PrepareHandle, Unit]
type ShutdownCB = CFuncPtr2[ShutdownReq, Int, Unit]
type CloseCB = CFuncPtr1[UVHandle, Unit]
// Workaround for https://github.com/scala-native/scala-native/issues/2550
// Use `Int` instead of `Integer` once fixed
type PollCB = CFuncPtr3[PollHandle, Integer, Integer, Unit]
type PollCB = CFuncPtr3[PollHandle, Int, Int, Unit]
type TimerCB = CFuncPtr1[TimerHandle, Unit]
type FSCB = CFuncPtr1[FSReq, Unit]

Expand Down
12 changes: 6 additions & 6 deletions core/src/main/scala/scala/scalanative/loop/Poll.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class RWResult(val result: Int, val readable: Boolean, val writable: Boolean)
object Poll {
private val pollReadWriteCB: PollCB = (
handle: PollHandle,
status: Integer,
events: Integer
status: Int,
events: Int
) => {
val callback =
HandleUtils.getData[RWResult => Unit](handle)
Expand All @@ -54,16 +54,16 @@ object Poll {
}
private val pollReadCB: PollCB = (
handle: PollHandle,
status: Integer,
events: Integer
status: Int,
events: Int
) => {
val callback = HandleUtils.getData[Int => Unit](handle)
if ((events & UV_READABLE) != 0) callback.apply(status)
}
private val pollWriteCB: PollCB = (
handle: PollHandle,
status: Integer,
events: Integer
status: Int,
events: Int
) => {
val callback = HandleUtils.getData[Int => Unit](handle)
if ((events & UV_WRITABLE) != 0) callback.apply(status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private[loop] object HandleUtils {
@inline def getData[T <: Object](handle: Ptr[Byte]): T = {
// data is the first member of uv_loop_t
val ptrOfPtr = handle.asInstanceOf[Ptr[Ptr[Byte]]]
val dataPtr = !ptrOfPtr
val dataPtr = !ptrOfPtr
if (dataPtr == null) null.asInstanceOf[T]
else {
val rawptr = toRawPtr(dataPtr)
Expand All @@ -24,7 +24,7 @@ private[loop] object HandleUtils {
@inline def setData(handle: Ptr[Byte], obj: Object): Unit = {
// data is the first member of uv_loop_t
val ptrOfPtr = handle.asInstanceOf[Ptr[Ptr[Byte]]]
if(obj != null) {
if (obj != null) {
if (references.contains(obj)) references(obj) += 1
else references(obj) = 1
val rawptr = castObjectToRawPtr(obj)
Expand All @@ -37,7 +37,7 @@ private[loop] object HandleUtils {
stdlib.free(handle)
}
@inline def close(handle: Ptr[Byte]): Unit = {
if(getData(handle) != null) {
if (getData(handle) != null) {
uv_close(handle, onCloseCB)
val data = getData[Object](handle)
val current = references(data)
Expand Down
5 changes: 3 additions & 2 deletions core/src/test/scala/scala/scalanative/loop/TimerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object TimerTests extends LoopTestSuite {
} yield ()
}
test("close multiple times") {
val p = Promise[Unit]()
val p = Promise[Unit]()
val timer = Timer.timeout(10.millis)(() => {})
timer.clear()
timer.clear()
Expand All @@ -66,7 +66,8 @@ object TimerTests extends LoopTestSuite {
}
test("deadlock when futures need event loop run to unlock") {
var completed = false
def recursive(): Future[Unit] = if (!completed) Future(recursive()) else Future.successful(())
def recursive(): Future[Unit] =
if (!completed) Future(recursive()) else Future.successful(())
val r = recursive()
Timer.timeout(10.millis)(() => completed = true)
r
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.3")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.4")
addSbtPlugin("com.eed3si9n" % "sbt-dirty-money" % "0.2.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.4")
Expand Down