Exemplo n.º 1
0
        void INTERNAL_SDLThread_InvokeQueue_HandleInvoke(Invoke_RendererOnly ueInfo)
        {
            // Invoke the delegate
            if (ueInfo.cbInvoke != null)
            {
                ueInfo.cbInvoke(this);
            }

            if (ueInfo.IsBlocking)
            {
                // Signal the invoking thread that the delegate has been run.
                // The invoking thread will handle releasing the unmanaged resources.
                ueInfo.sync.Release();
            }
            else
            {
                // BeginInvoke() means we need to free the unmanaged resources
                ueInfo.Dispose();
                ueInfo = null;
            }
        }
Exemplo n.º 2
0
        void INTERNAL_SDLThread_InvokeQueue_PrepareInvoke(void_RendererOnly del, bool asyncBegin)
        {
            // Invoke will cause a queued event in the SDL thread.  Normal Invoke/BeginInvoke
            // cannot be used as the main loop for the SDL thread is always running.
            // Due to this being handled through a queue system the call can be delayed.

            // Begin/Invoke struct
            var ueInfo = new Invoke_RendererOnly();

            ueInfo.cbInvoke = del;
            ueInfo.sync     = null;

            if (!asyncBegin)
            {
                // Create a semaphore with 1 slot and 0 available to handle Invoke()
                // This way we already hold the lone semaphore slot before we push
                // the event to the queue.  When the event is handled it will release
                // the semaphore count and allow this thread to resume execution.
                ueInfo.sync = new SemaphoreSlim(0, 1);
            }

            // Add this event to the queue
            INTERNAL_SDLThread_InvokeQueue_Add(ueInfo);

            // Was this an Invoke?
            if (!asyncBegin)
            {
                // Wait for the SDL thread to handle the Invoke()
                ueInfo.sync.Wait();
                ueInfo.sync.Release();

                // We need to free the unmanaged resources here
                ueInfo.Dispose();
                ueInfo = null;
            }
        }
Exemplo n.º 3
0
        void INTERNAL_SDLThread_InvokeQueue_Add(Invoke_RendererOnly ueInfo)
        {
            var c = _invokeQueue.Count;

            _invokeQueue.Insert(c, ueInfo);
        }