The thermodynamic theory of black holes