Skip to content

Commit

Permalink
[NUI] Make ProcessController.Initialized check as static + Initialize…
Browse files Browse the repository at this point in the history
… at Instance getter

Let we don't get the instance of ProcessController at DisposeQueue.

Since DisposeQueue could be works at worker thread, or execute before NUIApplication initialized,
we need to check whether ProcessController was initialized or not.

Signed-off-by: Eunki, Hong <[email protected]>
  • Loading branch information
Eunki, Hong authored and hinohie committed Jul 3, 2024
1 parent 84a8c29 commit c135bef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
6 changes: 0 additions & 6 deletions src/Tizen.NUI/src/internal/Application/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -684,12 +684,6 @@ private void OnApplicationInit(IntPtr data)
DisposeQueue.Instance.Initialize();
Tizen.Tracer.End();

Log.Info("NUI", "[NUI] OnApplicationInit: ProcessorController Initialize");
Tizen.Tracer.Begin("[NUI] OnApplicationInit: ProcessorController Initialize");
// Initialize ProcessorController Singleton class. This is also required to create ProcessorController on main thread.
ProcessorController.Instance.Initialize();
Tizen.Tracer.End();

Log.Info("NUI", "[NUI] OnApplicationInit: GetWindow");
Tizen.Tracer.Begin("[NUI] OnApplicationInit: GetWindow");
Window.Instance = Window.Default = GetWindow();
Expand Down
6 changes: 3 additions & 3 deletions src/Tizen.NUI/src/internal/Common/DisposeQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private DisposeQueue()
{
Tizen.Log.Debug("NUI", $"DisposeQueue is destroyed\n");
initialized = false;
if (processorRegistered && ProcessorController.Instance.Initialized)
if (processorRegistered && ProcessorController.Initialized)
{
processorRegistered = false;
ProcessorController.Instance.ProcessorOnceEvent -= TriggerProcessDisposables;
Expand Down Expand Up @@ -158,7 +158,7 @@ public void ProcessDisposables()
if (incrementallyDisposedQueue.Count > 0)
{
if (!incrementalDisposeSupported ||
(!fullCollectRequested && !ProcessorController.Instance.Initialized))
(!fullCollectRequested && !ProcessorController.Initialized))
{
// Full Dispose if IncrementalDisposeSupported is false, or ProcessorController is not initialized yet.
fullCollectRequested = true;
Expand Down Expand Up @@ -189,7 +189,7 @@ private void ProcessDisposablesIncrementally()

if (incrementallyDisposedQueue.Count > 0)
{
if (ProcessorController.Instance.Initialized && !processorRegistered)
if (ProcessorController.Initialized && !processorRegistered)
{
processorRegistered = true;
ProcessorController.Instance.ProcessorOnceEvent += TriggerProcessDisposables;
Expand Down
16 changes: 10 additions & 6 deletions src/Tizen.NUI/src/internal/Common/ProcessorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Tizen.NUI
internal sealed class ProcessorController : Disposable
{
private static ProcessorController instance = null;
private bool initialized = false;
private static bool initialized = false;

private ProcessorController() : this(true)
{
Expand Down Expand Up @@ -75,23 +75,27 @@ public event EventHandler ProcessorOnceEvent
public event EventHandler ProcessorEvent;
public event EventHandler LayoutProcessorEvent;

public bool Initialized => initialized;
public static bool Initialized => initialized;

public static ProcessorController Instance
{
get
{
if (instance == null)
{
instance = new ProcessorController(false);
// Create an instance of ProcessorController with Initialize.
// Legacy note : We were call Initialize() at internal/Application/Application.cs OnApplicationInit().
// Since DisposeQueue can use this class before Application initialized.
// But now, we just make ProcessorController.Initialized state as static. So we don't need to call Initialize() at Application.cs.
instance = new ProcessorController(true);
}
return instance;
}
}

public void Initialize()
{
if (initialized == false)
if (initialized == false) // We only allow single instance ProcessorController
{
initialized = true;

Expand All @@ -108,7 +112,7 @@ public void Initialize()
}
}

public void Process()
private void Process()
{
// Let us add once event into 1 index during 0 event invoke
onceEventIndex = 1;
Expand Down Expand Up @@ -146,7 +150,7 @@ protected override void Dispose(DisposeTypes type)

/// <summary>
/// Awake ProcessorController.
/// It will call ProcessController.processorCallback and ProcessController.processorPostCallback hardly.
/// It will call ProcessorController.processorCallback and ProcessorController.processorPostCallback hardly.
/// </summary>
/// <note>
/// When event thread is not in idle state, This function will be ignored.
Expand Down

0 comments on commit c135bef

Please sign in to comment.