+#endif
+#ifndef SYNC_PAINT
+ pthread_mutex_lock(&mutex);
+#endif
+ if ( rp != wp )
+ {
+ gOpcode o(queue[rp++]);
+ if ( rp == MAXSIZE )
+ rp=0;
+#ifndef SYNC_PAINT
+ pthread_mutex_unlock(&mutex);
+#endif
+ if (o.opcode==gOpcode::shutdown)
+ break;
+ else if (o.opcode==gOpcode::notify)
+ need_notify = 1;
+ else
+ {
+ o.dc->exec(&o);
+ // o.dc is a gDC* filled with grabref... so we must release it here
+ o.dc->Release();
+ }
+ }
+ else
+ {
+ if (need_notify)
+ {
+ need_notify = 0;
+ m_notify_pump.send(1);
+ }
+#ifndef SYNC_PAINT
+ while(rp == wp)
+ {
+
+ /* when the main thread is non-idle for a too long time without any display output,
+ we want to display a spinner. */
+
+ struct timeval time;
+ struct timespec timeout;
+ gettimeofday(&time, NULL);
+ timeout.tv_sec = time.tv_sec;
+ timeout.tv_nsec = time.tv_usec * 1000;
+
+ if (m_spinner_enabled)
+ timeout.tv_nsec += 100*1000*1000;
+ else
+ timeout.tv_nsec += 500*1000*1000;
+
+ /* yes, this is required. */
+ if (timeout.tv_nsec > 1000*1000*1000)
+ {
+ timeout.tv_nsec -= 1000*1000*1000;
+ timeout.tv_sec++;
+ }
+
+ int idle = 1;
+
+ if (pthread_cond_timedwait(&cond, &mutex, &timeout) == ETIMEDOUT)
+ {
+ if (eApp && !eApp->isIdle())
+ idle = 0;
+ }
+
+ pthread_mutex_unlock(&mutex);
+
+ if (!idle)
+ {
+ if (!m_spinner_enabled)
+ eDebug("main thread is non-idle! display spinner!");
+ enableSpinner();
+ } else
+ disableSpinner();
+ }
+#endif
+ }