Bug 122946 - Main thread tasks in ThreadableBlobRegistry should use std::unique_ptr
Summary: Main thread tasks in ThreadableBlobRegistry should use std::unique_ptr
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Zan Dobersek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-17 00:45 PDT by Zan Dobersek
Modified: 2013-11-05 02:47 PST (History)
2 users (show)

See Also:


Attachments
Patch (4.26 KB, patch)
2013-10-17 00:56 PDT, Zan Dobersek
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zan Dobersek 2013-10-17 00:45:45 PDT
Main thread tasks in ThreadableBlobRegistry should use std::unique_ptr
Comment 1 Zan Dobersek 2013-10-17 00:56:37 PDT
Created attachment 214429 [details]
Patch
Comment 2 Darin Adler 2013-11-02 14:17:35 PDT
Comment on attachment 214429 [details]
Patch

Every time we have a new rather than a make_unique, it makes it hard to be sure we got the object lifetime right. It would be nicer to use the lambda form of callOnMainThread so we could pass the unique_ptr through rather than having to pass it through as a void*.
Comment 3 Zan Dobersek 2013-11-04 09:37:42 PST
Lambda could be used here if wrapped inside std::bind() with a naked pointer to the BlobRegistryContext object bound as the first argument to the lambda function, where the pointer would then be put under a std::unique_ptr.

Binding std::unique_ptr as the first argument to the lambda function doesn't work since storing the std::bind() product inside a std::function requires that product to be copy-constructible, but this falters since std::unique_ptr is not copyable.

So, this works, and I have a patch ready if it's preferable:

        callOnMainThread(std::bind([](BlobRegistryContext* contextPtr) {
            std::unique_ptr<BlobRegistryContext> context(contextPtr);
            blobRegistry().registerBlobURL(context->url, std::move(context->blobData));
        }, new BlobRegistryContext(url, std::move(blobData))));
Comment 4 Anders Carlsson 2013-11-04 10:58:20 PST
(In reply to comment #3)
> Lambda could be used here if wrapped inside std::bind() with a naked pointer to the BlobRegistryContext object bound as the first argument to the lambda function, where the pointer would then be put under a std::unique_ptr.
> 
> Binding std::unique_ptr as the first argument to the lambda function doesn't work since storing the std::bind() product inside a std::function requires that product to be copy-constructible, but this falters since std::unique_ptr is not copyable.
> 
> So, this works, and I have a patch ready if it's preferable:
> 
>         callOnMainThread(std::bind([](BlobRegistryContext* contextPtr) {
>             std::unique_ptr<BlobRegistryContext> context(contextPtr);
>             blobRegistry().registerBlobURL(context->url, std::move(context->blobData));
>         }, new BlobRegistryContext(url, std::move(blobData))));

Let’s hold off on making such a change. I’m working on an experiment that will let you create a lambda and do a “cross-thread copy” of all the required parameters.
Comment 5 Zan Dobersek 2013-11-05 00:06:46 PST
OK, I'll land the original patch.
Comment 6 Zan Dobersek 2013-11-05 02:47:00 PST
Comment on attachment 214429 [details]
Patch

Clearing flags on attachment: 214429

Committed r158661: <http://trac.webkit.org/changeset/158661>
Comment 7 Zan Dobersek 2013-11-05 02:47:06 PST
All reviewed patches have been landed.  Closing bug.