poggit / libasynql

Asynchronous MySQL access library for PocketMine plugins.
https://poggit.github.io/libasynql
Apache License 2.0
132 stars 44 forks source link

DataConnectorImpl->waitAll() now waits for results #74

Closed JavierLeon9966 closed 1 year ago

JavierLeon9966 commented 2 years ago

DataConnectorImpl->waitAll() uses usleep and a while loop to receive data from other threads which it might affect the CPU by looping an unnecessary amount of times. This pull request changes it so it now waits for data using wait() and notify() in QueryRecvQueue by adding a new method called waitForResults. This method could be merged into fetchResults but it only returns false if there are no available threads to receive data from.

SOF3 commented 1 year ago

Note also: usleep doesn't really consume notable amount of CPU, especially at such a low frequency. The more significant problem is delayed notification.