In the line 8 of while loop, rc-- should be the correct implementation.
Considering that, the first reader downs the database and last reader ups the database. Each reader increases the readers count and wait for S. Mutex m is a mutex lock on accessing variable rc. It is placed around rc statements. down(s) before read and up(s) after read operations are done.
Also,I think db should not be a mutex, it should be a binary semaphore,since mutex has ownership,i.e the reader which downs the database will only be able to up the database,which is not the case here.