if( r->rgate != NULL ) { // if lock exists we must honour it
pthread_mutex_lock( r->rgate );
if( r->tail == r->head ) { // ensure ring didn't go empty while waiting
if( r->rgate != NULL ) { // if lock exists we must honour it
pthread_mutex_lock( r->rgate );
if( r->tail == r->head ) { // ensure ring didn't go empty while waiting