Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split sys_common::Mutex in StaticMutex and MovableMutex. #77147

Merged
merged 2 commits into from
Oct 2, 2020

Commits on Sep 27, 2020

  1. Split sys_common::Mutex in StaticMutex and MovableMutex.

    The (unsafe) Mutex from sys_common had a rather complicated interface.
    You were supposed to call init() manually, unless you could guarantee it
    was neither moved nor used reentrantly.
    
    Calling `destroy()` was also optional, although it was unclear if 1)
    resources might be leaked or not, and 2) if destroy() should only be
    called when `init()` was called.
    
    This allowed for a number of interesting (confusing?) different ways to
    use this Mutex, all captured in a single type.
    
    In practice, this type was only ever used in two ways:
    
    1. As a static variable. In this case, neither init() nor destroy() are
       called. The variable is never moved, and it is never used
       reentrantly. It is only ever locked using the LockGuard, never with
       raw_lock.
    
    2. As a Boxed variable. In this case, both init() and destroy() are
       called, it will be moved and possibly used reentrantly.
    
    No other combinations are used anywhere in `std`.
    
    This change simplifies things by splitting this Mutex type into
    two types matching the two use cases: StaticMutex and MovableMutex.
    
    The interface of both new types is now both safer and simpler. The first
    one does not call nor expose init/destroy, and the second one calls
    those automatically in its new() and Drop functions. Also, the locking
    functions of MovableMutex are no longer unsafe.
    m-ou-se committed Sep 27, 2020
    Configuration menu
    Copy the full SHA
    6f6336b View commit details
    Browse the repository at this point in the history
  2. Fix ui test.

    This test checks if the compiler complains about accesing a private
    field before complaining (or crashing) about the private function on it
    not marked as stable/unstable.
    
    The interface of the internal type (sys_common's Mutex) used for this
    was changed. With this change, it uses another function to test for the
    same issue.
    m-ou-se committed Sep 27, 2020
    Configuration menu
    Copy the full SHA
    825dda8 View commit details
    Browse the repository at this point in the history