PrimaryFeather/Sparrow-Framework — pull request #1071 by tconkling (2012-06-27 21:36:38+00:00)
Title: Thread-safe SPPool

Hey Daniel,

The current implementation of SPPool is not thread-safe, which I just learned the hard way after spending a long day tracking down baffling memory errors. My game isn't heavily multithreaded, but it does load assets on another thread, as I suspect most games do - and some of that asset loading involves points, matrices, and rectangles. (Also, the game will eventually need a network thread or two - more places for potential memory blowups).

I tried to be as efficient as possible in this modification (using @synchronized only when absolutely necessary - i.e. when performing an operation on an SPPoolInfo* itself, not when modifying an object's retain count).

Since the - (SPPoolInfo *)poolInfo implementation also changed, I created a macro - SP_IMPLEMENT_MEMORY_POOL() - that classes should use, rather than copy-pasting the implementation. (This should also help future-proof classes against more changes down the road).