The open source OpenXR runtime

st/gui: Improve thread safety, improve comments and spelling

+17 -5
+17 -5
src/xrt/state_trackers/gui/gui_ogl_sink.c
··· 117 117 struct gui_ogl_sink *s = container_of(tex, struct gui_ogl_sink, tex); 118 118 (void)s; 119 119 120 - // Take the frame no need to adjust reference. 121 120 pthread_mutex_lock(&s->mutex); 122 - struct xrt_frame *frame = s->frame; 123 - s->frame = NULL; 121 + 122 + struct xrt_frame *frame = NULL; 123 + 124 + // Only take the frame if we are running. 125 + if (s->running) { 126 + // Take the frame no need to adjust reference. 127 + frame = s->frame; 128 + s->frame = NULL; 129 + } 130 + 124 131 pthread_mutex_unlock(&s->mutex); 125 132 126 133 if (frame == NULL) { 127 134 return; 128 135 } 129 136 130 - // To large stride for GLint. 137 + /* 138 + * The frame properties are immutable while it is alive, 139 + * so no need to take any locks while reading them. 140 + */ 141 + 142 + // Too large of stride for GLint. 131 143 if (frame->stride > INT_MAX) { 132 - U_LOG_E("Stride unreasonable large!"); 144 + U_LOG_E("Stride unreasonably large!"); 133 145 return; 134 146 } 135 147