I will expand just a little on QuietLion's post.
I will use Blackjack as an example.
They calculate your comps in BJ on an average of 60 hands an hour. If you are playing $25 a hand, that comes out to a total of $1500 wagered in an average hour (Wow! I didn't realize I was betting that much)
The average house take on BJ is around 2% (Every game differs in this category, with Blackjack and Craps being two of the highest payouts). That means that the house will win an average of $30 if you sit there for an hour at $20 a hand. Most casinos comp around 60% of the house take, meaning that you would earn $18 in comps for playing an hour of $25 a hand Blackjack.
It doesn't matter if you are winning or losing, as long as you are playing a large amount of money. They know in the long run you will lose anyway.
The Pit Boss has quite a bit of leeway in their ability to comp so this should not be taken as the mantra.