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

Remove std::io::lazy::Lazy in favour of SyncOnceCell #77154

Merged
merged 5 commits into from
Sep 27, 2020

Commits on Sep 24, 2020

  1. Remove std::io::lazy::Lazy in favour of SyncOnceCell

    The (internal) std::io::lazy::Lazy was used to lazily initialize the
    stdout and stdin buffers (and mutexes). It uses atexit() to register a
    destructor to flush the streams on exit, and mark the streams as
    'closed'. Using the stream afterwards would result in a panic.
    
    Stdout uses a LineWriter which contains a BufWriter that will flush the
    buffer on drop. This one is important to be executed during shutdown,
    to make sure no buffered output is lost. It also forbids access to
    stdout afterwards, since the buffer is already flushed and gone.
    
    Stdin uses a BufReader, which does not implement Drop. It simply forgets
    any previously read data that was not read from the buffer yet. This
    means that in the case of stdin, the atexit() function's only effect is
    making stdin inaccessible to the program, such that later accesses
    result in a panic. This is uncessary, as it'd have been safe to access
    stdin during shutdown of the program.
    
    ---
    
    This change removes the entire io::lazy module in favour of
    SyncOnceCell. SyncOnceCell's fast path is much faster (a single atomic
    operation) than locking a sys_common::Mutex on every access like Lazy
    did.
    
    However, SyncOnceCell does not use atexit() to drop the contained object
    during shutdown.
    
    As noted above, this is not a problem for stdin. It simply means stdin
    is now usable during shutdown.
    
    The atexit() call for stdout is moved to the stdio module. Unlike the
    now-removed Lazy struct, SyncOnceCell does not have a 'gone and
    unusable' state that panics. Instead of adding this again, this simply
    replaces the buffer with one with zero capacity. This effectively
    flushes the old buffer *and* makes any writes afterwards pass through
    directly without touching a buffer, making print!() available during
    shutdown without panicking.
    m-ou-se committed Sep 24, 2020
    Configuration menu
    Copy the full SHA
    bab15f7 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    e9b25f5 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    45700a9 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    6f9c132 View commit details
    Browse the repository at this point in the history

Commits on Sep 26, 2020

  1. Configuration menu
    Copy the full SHA
    6b8b9c4 View commit details
    Browse the repository at this point in the history