Why does the tension on the pulley in an Atwood machine not equal $(m_1 + m_2)g$? Consider the following simple Atwood machine with an ideal pulley and an ideal string

According to my textbook, the tension on the clamp that holds the machine to the wall equals $2T$. I don't understand why that is. The tension in $T$ in the string is equal in magnitude to $m_1g + m_1a = m_2g - m_2a$, assuming that $m_1$ is accelerating upwards.
Also, the acceleration of masses in an atwood machine is given by
$$a = \frac{(m_2 - m_1)g}{m_1 + m_2}$$
Substituting this in, we get the tension equal to
$$T = m_1g + m_1\frac{(m_2 - m_1)g}{m_1 + m_2} = m_1g\left(1 + \frac{m_2 - m_1}{m_2 + m_1}\right) = \frac{2m_2m_1g}{m_1 + m_2}$$
So, according to my textbook, the tension on the pulley clamp should be:
$$2T = \frac{4m_1m_2g}{m_1 + m_2}$$
But, aren't all these forces internal forces? If we consider the whole atwood machine as the system (excluding the clamp), the only forces acting on it are the force of gravity, $(m_1 + m_2)g$ and the tension in the clamp, $T_c$. Since the system is at rest
$$T_c = (m_1 + m_2)g$$
Am I right, or is there a flaw in my argument? 
 A: The system is not at rest. If you consider the masses and the pulley to be one system, you can understand the behaviour of the system by the behaviour of its centre of mass. Unless the masses are equal, the centre of mass of the system is not at rest.
It might be useful  to think of it in this way - Inside the system boundary mass $m_1$ moves down through a distance while mass $m_2$ moves up by the same distance. So, the centre of mass has moved down (or up depending whether $m_1 > m_2$).
So, the tension would be given by the equation:
$$(m_1+m_2)a_{cm} = (m_1+m_2)g - T_c $$
You can further work out that
$a_{cm} = a(m_2-m_1) /(m_1+m_2)$, where a is the value of the acceleration of mass $m_1$ that you have mentioned.
Plug it in the equation and you'll find that:
$T_c=\frac{4m_1m_2}{m_1+m_2}{g}$
A: Your result holds when the two masses are the same, in that case $a=0$ and you'd have that:
$T = m_1 g = m_2 g$.
Or:
$2T = 2m_1 g=2m_2g=(m_1+m_2)g$.
In the case that the masses are not the same, then both masses are accelerating, which in its turn apply yields a lower force on the pulley-system (and on the clamp).
This can be easilly checked with your formula of the tension!
$T = \frac{2m_1m_2g}{m_1+m_2},$
If I were to define the total mass as: $M=m_1+m_2$, then I could express $T$ as:
$T=\frac{2m_1(M-m_1)g}{M}=\frac{2g}{M}(m_1(M-m_1)).$
You can check if you'd plot $T$ as a function of $m_1$, that it reaches a maximum in $m_1=M/2$, which means that the tension becomes maximal if the two masses are equal, the tension then becomes:
$T=\frac{Mg}{2}=\frac{(m_1+m_2)g}{2}$,
or as you were thinking:
$2T=(m_1+m_2)g$
For completeness the plot of the tension in function of the mass $m_1$ in terms of dimensionless quantities.

On this plot you can easilly see that if $m_1=0 \Rightarrow m_2=M$ or $m_1=M \Rightarrow m_2=0$, that there'd be no tension since one of the two masses would be free falling. In the intermediate cases there would be tension since there is a ''pull'' on both sides of the string, the more the masses $m_1$ and $m_2$ equal eachother, the less movement there is and the more pull there is on the string.
A: There is indeed a flaw in your argument. In short, the tension on the pulley clasp is only required to cancel the total gravitational force on the system when everything is in equilibrium and there is no acceleration. However, if the masses are unbalanced then one of them will fall and the other will rise, and it is not clear that this will keep the total force at the same value as the balanced case.
In fact, you can check that when the two masses are equal then the answers coincide: the correct tension on the pulley clasp is 
$$
T_\text{clasp}=2T=\frac{4m^2}{m+m}g=2mg=(m+m)g.
$$
