// called by AppThreadFunction public bool ovrMessageQueue_GetNextMessage(out ovrMessage message, bool waitForMessages) { // 1716 //ConsoleExtensions.tracei("enter ovrMessageQueue_GetNextMessage"); if (this.Wait == ovrMQWait.MQ_WAIT_PROCESSED) { pthread.pthread_cond_broadcast(ref Processed); this.Wait = ovrMQWait.MQ_WAIT_NONE; } if (waitForMessages) { ovrMessageQueue_SleepUntilMessage(); } pthread.pthread_mutex_lock(ref this.Mutex); if (this.Tail <= this.Head) { pthread.pthread_mutex_unlock(ref Mutex); message = default(ovrMessage); return(false); } message = this.Messages[Head & (MAX_MESSAGES - 1)]; this.Head++; pthread.pthread_mutex_unlock(ref Mutex); if (message.Wait == ovrMQWait.MQ_WAIT_RECEIVED) { // 1736! //pthread.pthread_cond_broadcast(ref Processed); pthread.pthread_cond_broadcast(ref Received); } else if (message.Wait == ovrMQWait.MQ_WAIT_PROCESSED) { this.Wait = ovrMQWait.MQ_WAIT_PROCESSED; } //ConsoleExtensions.tracei("exit ovrMessageQueue_GetNextMessage"); return(true); }
// called by Java_com_oculus_gles3jni_GLES3JNILib_onTouchEvent // uithread public void ovrMessageQueue_PostMessage(ref ovrMessage message) { // 1674 //ConsoleExtensions.tracei("enter ovrMessageQueue_PostMessage", (int)message.Id); // enabled by? if (!this.Enabled) { ConsoleExtensions.trace("exit ovrMessageQueue_PostMessage, disabled!"); return; } while (this.Tail - this.Head >= MAX_MESSAGES) { // block for a second until messages are processed in the worker? // usleep(microseconds) unistd.usleep(1000); } // lock(?) pthread.pthread_mutex_lock(ref this.Mutex); Messages[Tail & (MAX_MESSAGES - 1)] = message; Tail++; pthread.pthread_cond_broadcast(ref Posted); if (message.Wait == ovrMQWait.MQ_WAIT_RECEIVED) { //ConsoleExtensions.tracei("ovrMessageQueue_PostMessage MQ_WAIT_RECEIVED, pthread_cond_wait"); pthread.pthread_cond_wait(ref Received, ref Mutex); } else if (message.Wait == ovrMQWait.MQ_WAIT_PROCESSED) { //ConsoleExtensions.tracei("ovrMessageQueue_PostMessage MQ_WAIT_PROCESSED, pthread_cond_wait"); pthread.pthread_cond_wait(ref Processed, ref Mutex); //ConsoleExtensions.tracei("ovrMessageQueue_PostMessage MQ_WAIT_PROCESSED, pthread_cond_wait done"); } pthread.pthread_mutex_unlock(ref Mutex); //ConsoleExtensions.tracei("exit ovrMessageQueue_PostMessage"); }
// called by AppThreadFunction public bool ovrMessageQueue_GetNextMessage(out ovrMessage message, bool waitForMessages) { // 1716 //ConsoleExtensions.tracei("enter ovrMessageQueue_GetNextMessage"); if (this.Wait == ovrMQWait.MQ_WAIT_PROCESSED) { pthread.pthread_cond_broadcast(ref Processed); this.Wait = ovrMQWait.MQ_WAIT_NONE; } if (waitForMessages) { ovrMessageQueue_SleepUntilMessage(); } pthread.pthread_mutex_lock(ref this.Mutex); if (this.Tail <= this.Head) { pthread.pthread_mutex_unlock(ref Mutex); message = default(ovrMessage); return false; } message = this.Messages[Head & (MAX_MESSAGES - 1)]; this.Head++; pthread.pthread_mutex_unlock(ref Mutex); if (message.Wait == ovrMQWait.MQ_WAIT_RECEIVED) { // 1736! //pthread.pthread_cond_broadcast(ref Processed); pthread.pthread_cond_broadcast(ref Received); } else if (message.Wait == ovrMQWait.MQ_WAIT_PROCESSED) { this.Wait = ovrMQWait.MQ_WAIT_PROCESSED; } //ConsoleExtensions.tracei("exit ovrMessageQueue_GetNextMessage"); return true; }
// called by Java_com_oculus_gles3jni_GLES3JNILib_onTouchEvent // uithread public void ovrMessageQueue_PostMessage(ref ovrMessage message) { // 1674 //ConsoleExtensions.tracei("enter ovrMessageQueue_PostMessage", (int)message.Id); // enabled by? if (!this.Enabled) { ConsoleExtensions.trace("exit ovrMessageQueue_PostMessage, disabled!"); return; } while (this.Tail - this.Head >= MAX_MESSAGES) { // block for a second until messages are processed in the worker? // usleep(microseconds) unistd.usleep(1000); } // lock(?) pthread.pthread_mutex_lock(ref this.Mutex); Messages[Tail & (MAX_MESSAGES - 1)] = message; Tail++; pthread.pthread_cond_broadcast(ref Posted); if (message.Wait == ovrMQWait.MQ_WAIT_RECEIVED) { //ConsoleExtensions.tracei("ovrMessageQueue_PostMessage MQ_WAIT_RECEIVED, pthread_cond_wait"); pthread.pthread_cond_wait(ref Received, ref Mutex); } else if (message.Wait == ovrMQWait.MQ_WAIT_PROCESSED) { //ConsoleExtensions.tracei("ovrMessageQueue_PostMessage MQ_WAIT_PROCESSED, pthread_cond_wait"); pthread.pthread_cond_wait(ref Processed, ref Mutex); //ConsoleExtensions.tracei("ovrMessageQueue_PostMessage MQ_WAIT_PROCESSED, pthread_cond_wait done"); } pthread.pthread_mutex_unlock(ref Mutex); //ConsoleExtensions.tracei("exit ovrMessageQueue_PostMessage"); }