/// <summary> /// Initializes a new <see cref="AwaitableEvent"/> instance. /// </summary> /// <param name="handle">The handle to the OpenCL event.</param> public AwaitableEvent(IntPtr handle) : base(handle, "AwaitableEvent", true) { // Subscribes to the event callbacks of the OpenCL event, so that a CLR event can be raised EventsNativeApi.SetEventCallback( Handle, (int)CommandExecutionStatus.Queued, Marshal.GetFunctionPointerForDelegate(new AwaitableEventCallback((waitEvent, userData) => OnQueued?.Invoke(this, new EventArgs()))), IntPtr.Zero); EventsNativeApi.SetEventCallback( Handle, (int)CommandExecutionStatus.Submitted, Marshal.GetFunctionPointerForDelegate(new AwaitableEventCallback((waitEvent, userData) => OnSubmitted?.Invoke(this, new EventArgs()))), IntPtr.Zero); EventsNativeApi.SetEventCallback( Handle, (int)CommandExecutionStatus.Running, Marshal.GetFunctionPointerForDelegate(new AwaitableEventCallback((waitEvent, userData) => OnRunning?.Invoke(this, new EventArgs()))), IntPtr.Zero); EventsNativeApi.SetEventCallback( Handle, (int)CommandExecutionStatus.Complete, Marshal.GetFunctionPointerForDelegate(new AwaitableEventCallback((waitEvent, userData) => OnCompleted?.Invoke(this, new EventArgs()))), IntPtr.Zero); }
public void EnqueueDeferred(IEntity source, QueueAction a) { if (a == null) { return; } #if _QUEUE_DEBUG DebugLog.WriteLine("Queue (Game " + Game.GameId + "): Queueing action " + a + " for " + source.ShortDescription + " at depth " + Depth); #endif var e = initializeAction(source, a); if (OnQueueing != null) { OnQueueing(this, e); // TODO: Count the number of arguments the cancelled action would take and remove those too if (!e.Cancel) { Queue.AddBack(e); } } else { Queue.AddBack(e); } OnQueued?.Invoke(this, e); }