Fix: Set the max number of resources waiting at a flag using FLAG_MAX_RES_COUNT.

Fixes various off-by-one bugs.