Created
February 24, 2018 12:43
-
-
Save jesustorresdev/bc82c00db707816928867730b3fddb28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QImage FiniteBuffer::extractFrame() | |
{ | |
// Bloquear el cerrojo. Es lo mismo que hacer manualmente: | |
// mutex_.lock() | |
QMutexLocker lock(&mutex); | |
// El código del productor a partir de este punto no se | |
// ejecutará si el productor ha bloqueado el cerrojo | |
// primero. | |
if (bufferHead_ == bufferTail_) // ¿Cola vacía?... | |
bufferNotEmpty_.wait(&mutex); // Dormir si es así | |
QImage image = buffer_[++bufferHead_ % buffer_.size()]; | |
// El cerrojo se libera automáticamente al salir de la función | |
// y destruirse lock. Es lo mismo que hacer manualmente: | |
// mutex_.unlock() | |
return image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment