~raof/mir/make-default-surface-store-threadsafe

« back to all changes in this revision

Viewing changes to src/server/shell/default_persistent_surface_store.cpp

  • Committer: Christopher James Halse Rogers
  • Date: 2017-08-14 02:48:54 UTC
  • Revision ID: christopher.halse.rogers@canonical.com-20170814024854-8053wq5o15uaj2vk
DefaultPersistentSurfaceStore: Switch to std::mutex/lock_guard.

For this simple case it doesn't make much sense to use an smart-pointer-esque Mutex

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
auto msh::DefaultPersistentSurfaceStore::id_for_surface(std::shared_ptr<scene::Surface> const& surface)
83
83
    -> Id
84
84
{
85
 
    return (*store)->insert_or_retrieve(surface);
 
85
    std::lock_guard<std::mutex> lock{mutex};
 
86
    return store->insert_or_retrieve(surface);
86
87
}
87
88
 
88
89
std::shared_ptr<ms::Surface> msh::DefaultPersistentSurfaceStore::surface_for_id(Id const& id) const
89
90
{
90
91
    try
91
92
    {
92
 
        return (**store)[id];
 
93
        std::lock_guard<std::mutex> lock{mutex};
 
94
        return (*store)[id];
93
95
    }
94
96
    catch (std::out_of_range& err)
95
97
    {