shiny/driver/x11driver: fix SHM completion race.

Previously, bufferImpl's upload method was was:

----
// LINE A.
cookie := shm.PutImage(etc)

// LINE B.
b.s.mu.Lock()

// LINE C.
b.s.uploads[cookie.Sequence] = etc

// LINE D.
b.s.mu.Unlock()
----

The race was that the PutImage call could complete, and be processed by
the X11 event goroutine, after LINE A and before LINE B, so that
screenImpl's handleCompletion would find nothing in the s.uploads map,
and log "no matching upload for a SHM completion event", leaking the
screen.Buffer.

The fix is to increment a counter before LINE A and decrement it after
LINE C, so that the s.uploads map isn't inspected while we're just about
to add something to it.

Change-Id: Ief1cb40129f16dd3fc2ba008c9d1b9be1db05a6d
Reviewed-on: https://go-review.googlesource.com/14818
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2 files changed