Currently, each write of LogFileOutput requires two locks.
First, current thread holds _rotation_semaphore(1), which is used to protect log rotation. Secondly, current thread will call flockfile(_stream) to ensure multiple threads won't interleave FILE* _stream.
The second one is redundant for LogFileOutput because _rotate_semaphore prevents other threads from writing _stream.
Not only it's slow, but it's also easy to end up with deadlock.
I think we should use a semaphore to fold two locks into one. flockfile doesn't work for log rotation scenrio because fclose() in LogFileOutput::rotate() will automatically unlock FILE->_lock.
First, current thread holds _rotation_semaphore(1), which is used to protect log rotation. Secondly, current thread will call flockfile(_stream) to ensure multiple threads won't interleave FILE* _stream.
The second one is redundant for LogFileOutput because _rotate_semaphore prevents other threads from writing _stream.
Not only it's slow, but it's also easy to end up with deadlock.
I think we should use a semaphore to fold two locks into one. flockfile doesn't work for log rotation scenrio because fclose() in LogFileOutput::rotate() will automatically unlock FILE->_lock.