Closed Bug 1520955 Opened 7 years ago Closed 7 years ago

Add ref qualifier to DataMutex for more safety

Categories

(Core :: XPCOM, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla66
Tracking Status
firefox66 --- fixed

People

(Reporter: jrmuizel, Assigned: jrmuizel)

Details

Attachments

(1 file)

We lose some sugar but gain some safety. This seems like the right trade. If people want sugar they should use Rust.

We lose some sugar but gain some safety. This seems like the right
trade. If people want sugar they should use Rust.

Pushed by jmuizelaar@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/0f73ecaf9f40 Add ref qualifier to DataMutex for more safety. r=froydnj
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla66
Assignee: nobody → jmuizelaar

What safety is gained through these changes?

Flags: needinfo?(jmuizelaar)

I've actually forgotten. Perhaps the lock can be dropped too early in some situations. I guess I should've written a better commit message. Maybe Nathan remembers.

Flags: needinfo?(jmuizelaar) → needinfo?(nfroyd)

I think the concern is T& x = mMember.Lock().ref(); or similar doesn't actually hold the lock as long as you would like. I know there are rules about const references extending lifetimes of temporaries (I can't find the standardese for them right now), but I don't think they would apply in this case (even if x was const T&).

Flags: needinfo?(nfroyd)

I was more thinking about operator-> which was also changed by the attached patch to disallow writing something like:

mDataMutex.Lock()->DoSomething()

which is not very convenient. The similar class boost::synchronized_value allows this, e.g.

Maybe the deletions of operator-> (and maybe also operator*) can be removed again?

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: