eventmachine/eventmachine — pull request #445 by ept (2013-06-03 19:03:26+00:00)
Title: Make ScheduleClose() idempotent

I think this fixes issue #441.

8b613d05047ad6954f7d856b1404522214e8f001 changed the `select` timeout to zero in the case where `NumCloseScheduled > 0`. It seems that in certain circumstances (for example, if `close_connection` is called in a connection's `unbind`) `NumCloseScheduled` would get incremented twice, but only decremented once, thus never again reaching zero for the lifetime of the reactor.

The user-observed effect was that one CPU core would be pegged at 100%, because the zero `select` timeout caused us to go around the select loop without any pause.

Changing it so that it is safe to call `ScheduleClose()` multiple times seems like the cleanest solution to the problem.