Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Aug 6, 2024
1 parent 80be0d0 commit d7a4669
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ object EpollSystem extends PollingSystem {
def poll(poller: Poller, nanos: Long, reportFailure: Throwable => Unit): Boolean =
poller.poll(nanos)

def steal(poller: Poller, reportFailure: Throwable => Unit): Boolean =
poller.steal()

def needsPoll(poller: Poller): Boolean = poller.needsPoll()

def interrupt(targetThread: Thread, targetPoller: Poller): Unit = ()
Expand Down Expand Up @@ -219,6 +222,8 @@ object EpollSystem extends PollingSystem {
polled
}

private[EpollSystem] def steal(): Boolean = poll(0)

private[EpollSystem] def needsPoll(): Boolean = !handles.isEmpty()

private[EpollSystem] def register(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2020-2024 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cats.effect
package unsafe

trait PollingSystemSpec extends BaseSpec {

def system: IO[PollingSystem]

"Polling System" should {
"not blocker stealer when owner is polling" in real {
system.flatMap { s =>
IO(s.makePoller()).flatMap { p =>
IO.interruptible(s.poll(p, -1, _ => ())).background.surround {
IO(s.steal(p, _ => ()) should beFalse)
}
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,8 @@
package cats.effect
package unsafe

class SelectorSystemSpec extends BaseSpec {
class SelectorSystemSpec extends PollingSystemSpec {

"SelectorSystem" should {
"not blocker stealer when owner is polling" in real {
IO(SelectorSystem()).flatMap { s =>
IO(s.makePoller()).flatMap { p =>
IO.interruptible(s.poll(p, -1, _ => ())).background.surround {
IO(s.steal(p, _ => ()) should beFalse)
}
}
}
}
}
def system = IO(SelectorSystem())

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2020-2024 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cats.effect
package unsafe

class SelectorSystemSpec extends PollingSystemSpec {

def system = IO(FileDescriptorPoller)

}

0 comments on commit d7a4669

Please sign in to comment.