Commit Graph

3 Commits

Author SHA1 Message Date
Valentin Shergin be6976d6fa RCTAllocatedRootViewTag was moved to RCTUIManagerUtils
Summary: This logic was decoupled from RCTRootView to make it reusable.

Reviewed By: javache

Differential Revision: D6214785

fbshipit-source-id: e7419be03ba0e20d95b47c11e41789636aa6e916
2017-11-07 16:16:56 -08:00
Valentin Shergin 5e25c0e32f Introducing PseudoUIManagerQueue
Summary:
Queues Problem Intro:
UIManager queue is special queue because it has special relationship with
the Main queue.

This particular relationship comes from two key factors:
 1. UIManager initiates execution of many blocks on the Main queue;
 2. In some cases, we want to initiate (and wait for) some UIManager's work *synchronously* from
    the Main queue.

So, how can we meet these criteria?
"Pseudo UIManager queue" comes to rescue!

"Pseudo UIManager queue" means safe execution of typical UIManager's work
on the Main queue while the UIManager queue is explicitly blocked for preventing
simultaneous/concurrent memory access.

So, how can we technically do this?
 1. `RCTAssertUIManagerQueue` is okay with execution on both actual UIManager and
    Pseudo UIManager queues.
 2. Both `RCTExecuteOnUIManagerQueue` and `RCTUnsafeExecuteOnUIManagerQueueSync`
    execute given block *synchronously* if they were called on actual UIManager
    or Pseudo UIManager queues.
 3. `RCTExecuteOnMainQueue` executes given block *synchronously* if we already on
    the Main queue.
 4. `RCTUnsafeExecuteOnUIManagerQueueSync` is smart enough to do the trick:
    It detects calling on the Main queue and in this case, instead of doing
    trivial *synchronous* dispatch, it does:
      - Block the Main queue;
      - Dispatch the special block on UIManager queue to block the queue and
        concurrent memory access;
      - Execute the given block on the Main queue;
      - Unblock the UIManager queue.

Imagine the analogy: We have two queues: the Main one and UIManager one.
And these queues are two lanes of railway go in parallel. Then,
at some point, we merge UIManager lane with the Main lane, and all cars use
the unified the Main lane.
And then we split lanes again.

This solution assumes that the code running on UIManager queue will never
*explicitly* block the Main queue via calling `RCTUnsafeExecuteOnMainQueueSync`.
Otherwise, it can cause a deadlock.

Reviewed By: mmmulani

Differential Revision: D5935464

fbshipit-source-id: 6a60ff236280d825b4e2b101f06222266097b97f
2017-10-08 21:40:19 -07:00
Valentin Shergin 6d67e2dbbc Bunch of utility funcs were moved to RCTUIManagerUtils
Summary: Because `RCTUIManager` is already overcomplicated and that stuff deserves separate file and header.

Reviewed By: javache

Differential Revision: D5856653

fbshipit-source-id: 7001bb8ba611976bf3b82d6a25f5619810a35b34
2017-09-26 14:08:28 -07:00