Do mojo sync functions synchronize multiple calls?

48 views
Skip to first unread message

Koji Ishii

unread,
Oct 9, 2021, 3:46:27 AM10/9/21
to chromium-mojo
Hello chromium-mojo experts,

Could any experts here help us to figure out if/how mojo synchronizes multiple simultaneous calls?

Renderer calls Windows DirectWrite functions using [sync] calls in dwrite_font_proxy.mojom. Its implementation, DWriteFontProxyImpl, has DirectWrite objects, and nobody should call them simultaneously.

When multiple renderer processes call these mojo functions simultaneously, does the [sync] attribute serializes the requests and prevents calling DWriteFontProxyImpl functions simultaneously, or does DWriteFontProxyImpl need to synchronize by itself?

Dave Tapuska

unread,
Oct 9, 2021, 7:36:10 AM10/9/21
to Koji Ishii, chromium-mojo
I don't believe there is any special handling really on the receiver side. They are essentially handled like an async message. If you require coordination on your service between the time you receive a message and when you call the callback (presumably you are doing something else while waiting on something) you'll have to build that yourself. 

Dave

--
You received this message because you are subscribed to the Google Groups "chromium-mojo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-moj...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-mojo/CAHe_1d%2BoF9LEcbCNseu1KUMLsz6kBZEUUX4bhRbw7MxU6QES2g%40mail.gmail.com.

Ken Rockot

unread,
Oct 9, 2021, 12:36:11 PM10/9/21
to Dave Tapuska, Koji Ishii, chromium-mojo
On Sat, Oct 9, 2021 at 4:36 AM Dave Tapuska <dtap...@chromium.org> wrote:
I don't believe there is any special handling really on the receiver side. They are essentially handled like an async message. If you require coordination on your service between the time you receive a message and when you call the callback (presumably you are doing something else while waiting on something) you'll have to build that yourself. 

By the same token, if there's only one DWriteFontProxyImpl or all instances are bound to the same sequence, you don't need to do anything to ensure mutual exclusion of calls. All calls will be sequenced.
 

Dave

On Sat., Oct. 9, 2021, 3:46 a.m. Koji Ishii, <ko...@chromium.org> wrote:
Hello chromium-mojo experts,

Could any experts here help us to figure out if/how mojo synchronizes multiple simultaneous calls?

Renderer calls Windows DirectWrite functions using [sync] calls in dwrite_font_proxy.mojom. Its implementation, DWriteFontProxyImpl, has DirectWrite objects, and nobody should call them simultaneously.

When multiple renderer processes call these mojo functions simultaneously, does the [sync] attribute serializes the requests and prevents calling DWriteFontProxyImpl functions simultaneously, or does DWriteFontProxyImpl need to synchronize by itself?

--
You received this message because you are subscribed to the Google Groups "chromium-mojo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-moj...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-mojo/CAHe_1d%2BoF9LEcbCNseu1KUMLsz6kBZEUUX4bhRbw7MxU6QES2g%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "chromium-mojo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-moj...@chromium.org.

Koji Ishii

unread,
Oct 10, 2021, 1:03:35 PM10/10/21
to Ken Rockot, Dave Tapuska, chromium-mojo
Thanks Dave and Ken, this is great info.

A little more advice is appreciated, my knowledge can't determine if the current code suffices the "if" conditions.

From the code search, I can find two codes. One in RenderProcessHostImpl::RegisterMojoInterfaces:
  registry->AddInterface(
      base::BindRepeating(&DWriteFontProxyImpl::Create),
      base::ThreadPool::CreateSequencedTaskRunner(
          {base::TaskPriority::USER_BLOCKING, base::MayBlock()}));
I guess the use of a SequencedTaskRunner suffices the "if" condition, is that correct?

  if (auto r = receiver.As<blink::mojom::DWriteFontProxy>()) {
    base::ThreadPool::CreateSequencedTaskRunner(
        {base::TaskPriority::USER_BLOCKING, base::MayBlock()})
        ->PostTask(FROM_HERE,
                   base::BindOnce(&DWriteFontProxyImpl::Create, std::move(r)));
    return;
  }
I'm not sure what this is doing.

Can you see whether this is sequenced or not from these code snippets?

Daniel Cheng

unread,
Oct 10, 2021, 3:23:26 PM10/10/21
to Koji Ishii, Ken Rockot, Dave Tapuska, chromium-mojo
Unfortunately, the current code will bind a DWriteFontProxyImpl for each RenderProcessHost to a different sequence, since RegisterMojoInterfaces() would be called for each RenderProcessHost. Each call to CreateSequencedTaskRunner() will create a distinct sequence.

If we need this to be synchronized, then we should create a sequenced task runner once and pass the same task runner to all the sites that create DWriteFontProxyImpl.

Daniel

Daniel Cheng

unread,
Oct 10, 2021, 3:25:25 PM10/10/21
to Koji Ishii, Ken Rockot, Dave Tapuska, chromium-mojo
To be clear though, this creates distinct DWriteFontProxyImpl instances for each RPH. Is it also not allowed to simultaneously handle calls for different instances?

Daniel

Koji Ishii

unread,
Oct 10, 2021, 6:07:05 PM10/10/21
to Daniel Cheng, Ken Rockot, Dave Tapuska, chromium-mojo, Ian Prest, Daniel Libby, alm...@microsoft.com
Thanks, very helpful. Understood what this code means better.

And good point, I don't know if it's safe for multiple threads to call different instances of DWriteFactory and system font collections. I'll check with Microsoft engineers.
Reply all
Reply to author
Forward
0 new messages