Fix a race condition while processing tasks by background threads.
Fix a race condition while processing tasks by background threads.

Summary:
Suppose you submit 100 background tasks one after another. The first
enqueu task finds that the queue is empty and wakes up one worker thread.
Now suppose that all remaining 99 work items are enqueued, they do not
wake up any worker threads because the queue is already non-empty.
This causes a situation when there are 99 tasks in the task queue but
only one worker thread is processing a task while the remaining
worker threads are waiting.
The fix is to always wakeup one worker thread while enqueuing a task.

I also added a check to count the number of elements in the queue
to help in debugging.

Test Plan: make clean check.

Reviewers: chip

Reviewed By: chip

CC: leveldb

Differential Revision: https://reviews.facebook.net/D7203

ylong/rocksdb,Andymic/rocksdb,lgscofield/rocksdb,tizzybec/rocksdb,alihalabyah/rocksdb,dkorolev/rocksdb,kaschaeffer/rocksdb,wskplho/rocksdb,tsheasha/rocksdb,Andymic/rocksdb,OverlordQ/rocksdb,fengshao0907/rocksdb,wlqGit/rocksdb,norton/rocksdb,zhangpng/rocksdb,jalexanderqed/rocksdb,kaschaeffer/rocksdb,virtdb/rocksdb,JohnPJenkins/rocksdb,OverlordQ/rocksdb,NickCis/rocksdb,rDSN-Projects/rocksdb.replicated,ryneli/rocksdb,bbiao/rocksdb,mbarbon/rocksdb,Applied-Duality/rocksdb,kaschaeffer/rocksdb,ylong/rocksdb,siddhartharay007/rocksdb,anagav/rocksdb,sorphi/rocksdb,skunkwerks/rocksdb,SunguckLee/RocksDB,IMCG/RcoksDB,NickCis/rocksdb,anagav/rocksdb,amyvmiwei/rocksdb,wat-ze-hex/rocksdb,jalexanderqed/rocksdb,amyvmiwei/rocksdb,rDSN-Projects/rocksdb.replicated,vashstorm/rocksdb,lgscofield/rocksdb,jalexanderqed/rocksdb,temicai/rocksdb,hobinyoon/rocksdb,wskplho/rocksdb,biddyweb/rocksdb,JackLian/rocksdb,vashstorm/rocksdb,wenduo/rocksdb,caijieming-baidu/rocksdb,wskplho/rocksdb,skunkwerks/rocksdb,makelivedotnet/rocksdb,vmx/rocksdb,NickCis/rocksdb,vashstorm/rocksdb,hobinyoon/rocksdb,flabby/rocksdb,wenduo/rocksdb,vashstorm/rocksdb,IMCG/RcoksDB,wenduo/rocksdb,makelivedotnet/rocksdb,zhangpng/rocksdb,RyanTech/rocksdb,jalexanderqed/rocksdb,Vaisman/rocksdb,Andymic/rocksdb,tschottdorf/rocksdb,caijieming-baidu/rocksdb,JohnPJenkins/rocksdb,RyanTech/rocksdb,alihalabyah/rocksdb,flabby/rocksdb,rDSN-Projects/rocksdb.replicated,anagav/rocksdb,lgscofield/rocksdb,anagav/rocksdb,tschottdorf/rocksdb,sorphi/rocksdb,wat-ze-hex/rocksdb,caijieming-baidu/rocksdb,tsheasha/rocksdb,JoeWoo/rocksdb,Applied-Duality/rocksdb,virtdb/rocksdb,Applied-Duality/rocksdb,Vaisman/rocksdb,temicai/rocksdb,hobinyoon/rocksdb,siddhartharay007/rocksdb,bbiao/rocksdb,JoeWoo/rocksdb,temicai/rocksdb,Andymic/rocksdb,jalexanderqed/rocksdb,tsheasha/rocksdb,flabby/rocksdb,norton/rocksdb,sorphi/rocksdb,tsheasha/rocksdb,IMCG/RcoksDB,dkorolev/rocksdb,wlqGit/rocksdb,wat-ze-hex/rocksdb,luckywhu/rocksdb,vmx/rocksdb,IMCG/RcoksDB,msb-at-yahoo/rocksdb,tsheasha/rocksdb,wenduo/rocksdb,sorphi/rocksdb,JohnPJenkins/rocksdb,wskplho/rocksdb,wat-ze-hex/rocksdb,SunguckLee/RocksDB,vmx/rocksdb,dkorolev/rocksdb,wlqGit/rocksdb,mbarbon/rocksdb,tsheasha/rocksdb,wat-ze-hex/rocksdb,NickCis/rocksdb,vmx/rocksdb,temicai/rocksdb,norton/rocksdb,dkorolev/rocksdb,fengshao0907/rocksdb,ylong/rocksdb,wlqGit/rocksdb,makelivedotnet/rocksdb,kaschaeffer/rocksdb,bbiao/rocksdb,ryneli/rocksdb,kaschaeffer/rocksdb,biddyweb/rocksdb,IMCG/RcoksDB,Vaisman/rocksdb,RyanTech/rocksdb,alihalabyah/rocksdb,hobinyoon/rocksdb,kaschaeffer/rocksdb,rDSN-Projects/rocksdb.replicated,makelivedotnet/rocksdb,lgscofield/rocksdb,anagav/rocksdb,JoeWoo/rocksdb,virtdb/rocksdb,ryneli/rocksdb,biddyweb/rocksdb,virtdb/rocksdb,anagav/rocksdb,JackLian/rocksdb,tizzybec/rocksdb,OverlordQ/rocksdb,fengshao0907/rocksdb,norton/rocksdb,SunguckLee/RocksDB,wenduo/rocksdb,luckywhu/rocksdb,dkorolev/rocksdb,sorphi/rocksdb,Andymic/rocksdb,bbiao/rocksdb,OverlordQ/rocksdb,luckywhu/rocksdb,wlqGit/rocksdb,hobinyoon/rocksdb,temicai/rocksdb,tschottdorf/rocksdb,msb-at-yahoo/rocksdb,alihalabyah/rocksdb,temicai/rocksdb,flabby/rocksdb,NickCis/rocksdb,bbiao/rocksdb,JoeWoo/rocksdb,sorphi/rocksdb,RyanTech/rocksdb,siddhartharay007/rocksdb,facebook/rocksdb,vashstorm/rocksdb,JohnPJenkins/rocksdb,lgscofield/rocksdb,fengshao0907/rocksdb,JackLian/rocksdb,luckywhu/rocksdb,wlqGit/rocksdb,wat-ze-hex/rocksdb,Applied-Duality/rocksdb,JackLian/rocksdb,makelivedotnet/rocksdb,wat-ze-hex/rocksdb,jalexanderqed/rocksdb,wenduo/rocksdb,zhangpng/rocksdb,ryneli/rocksdb,ylong/rocksdb,skunkwerks/rocksdb,JohnPJenkins/rocksdb,dkorolev/rocksdb,Vaisman/rocksdb,JohnPJenkins/rocksdb,wskplho/rocksdb,skunkwerks/rocksdb,facebook/rocksdb,sorphi/rocksdb,flabby/rocksdb,geraldoandradee/rocksdb,mbarbon/rocksdb,vmx/rocksdb,alihalabyah/rocksdb,SunguckLee/RocksDB,siddhartharay007/rocksdb,zhangpng/rocksdb,wat-ze-hex/rocksdb,tizzybec/rocksdb,tschottdorf/rocksdb,bbiao/rocksdb,OverlordQ/rocksdb,mbarbon/rocksdb,norton/rocksdb,OverlordQ/rocksdb,NickCis/rocksdb,jalexanderqed/rocksdb,zhangpng/rocksdb,tschottdorf/rocksdb,RyanTech/rocksdb,JoeWoo/rocksdb,fengshao0907/rocksdb,Vaisman/rocksdb,geraldoandradee/rocksdb,wenduo/rocksdb,rDSN-Projects/rocksdb.replicated,Vaisman/rocksdb,luckywhu/rocksdb,Applied-Duality/rocksdb,biddyweb/rocksdb,geraldoandradee/rocksdb,ylong/rocksdb,caijieming-baidu/rocksdb,mbarbon/rocksdb,Applied-Duality/rocksdb,vmx/rocksdb,norton/rocksdb,tizzybec/rocksdb,JoeWoo/rocksdb,norton/rocksdb,Andymic/rocksdb,siddhartharay007/rocksdb,ryneli/rocksdb,skunkwerks/rocksdb,virtdb/rocksdb,JoeWoo/rocksdb,wskplho/rocksdb,wskplho/rocksdb,facebook/rocksdb,lgscofield/rocksdb,ryneli/rocksdb,hobinyoon/rocksdb,fengshao0907/rocksdb,skunkwerks/rocksdb,wlqGit/rocksdb,Andymic/rocksdb,alihalabyah/rocksdb,vashstorm/rocksdb,SunguckLee/RocksDB,ylong/rocksdb,dkorolev/rocksdb,JackLian/rocksdb,hobinyoon/rocksdb,facebook/rocksdb,NickCis/rocksdb,SunguckLee/RocksDB,amyvmiwei/rocksdb,geraldoandradee/rocksdb,Andymic/rocksdb,lgscofield/rocksdb,msb-at-yahoo/rocksdb,SunguckLee/RocksDB,rDSN-Projects/rocksdb.replicated,makelivedotnet/rocksdb,msb-at-yahoo/rocksdb,biddyweb/rocksdb,amyvmiwei/rocksdb,SunguckLee/RocksDB,RyanTech/rocksdb,zhangpng/rocksdb,OverlordQ/rocksdb,alihalabyah/rocksdb,flabby/rocksdb,Applied-Duality/rocksdb,luckywhu/rocksdb,norton/rocksdb,IMCG/RcoksDB,vmx/rocksdb,siddhartharay007/rocksdb,anagav/rocksdb,facebook/rocksdb,mbarbon/rocksdb,wenduo/rocksdb,facebook/rocksdb,tizzybec/rocksdb,tizzybec/rocksdb,vashstorm/rocksdb,bbiao/rocksdb,fengshao0907/rocksdb,zhangpng/rocksdb,skunkwerks/rocksdb,tizzybec/rocksdb,temicai/rocksdb,caijieming-baidu/rocksdb,JackLian/rocksdb,siddhartharay007/rocksdb,msb-at-yahoo/rocksdb,IMCG/RcoksDB,amyvmiwei/rocksdb,Vaisman/rocksdb,kaschaeffer/rocksdb,mbarbon/rocksdb,JohnPJenkins/rocksdb,ylong/rocksdb,bbiao/rocksdb,hobinyoon/rocksdb,rDSN-Projects/rocksdb.replicated,ryneli/rocksdb,geraldoandradee/rocksdb,amyvmiwei/rocksdb,geraldoandradee/rocksdb,caijieming-baidu/rocksdb,facebook/rocksdb,vmx/rocksdb,JackLian/rocksdb,caijieming-baidu/rocksdb,makelivedotnet/rocksdb,RyanTech/rocksdb,msb-at-yahoo/rocksdb,luckywhu/rocksdb,tsheasha/rocksdb,geraldoandradee/rocksdb,tsheasha/rocksdb,biddyweb/rocksdb,biddyweb/rocksdb,facebook/rocksdb,tschottdorf/rocksdb,virtdb/rocksdb,virtdb/rocksdb,flabby/rocksdb,amyvmiwei/rocksdb