waffle-gl/waffle — pull request #17 by fjhenigman (2014-10-22 03:23:30+00:00)
Title: gbm: lock and release buffer in swap buffers

Otherwise mesa prints "libEGL debug: EGL user error 0x300d (EGL_BAD_SURFACE) in dri2_swap_buffers"
when environment variable EGL_LOG_LEVEL=debug.

You can see this by running waffle's gl_basic example. Every call to swap_buffers after the first one will cause this message to be printed.
Though an error message is printed, no harm is done and no error is returned. I'm not sure why mesa does this, but assuming there's a reason, this lock/unlock seems to be what it wants us to do.