~ted/media-hub/deb-apps-apparmor

« back to all changes in this revision

Viewing changes to src/core/media/hashed_keyed_player_store.cpp

  • Committer: CI Train Bot
  • Author(s): Jim Hodapp
  • Date: 2016-03-08 19:36:00 UTC
  • mfrom: (171.1.11 media-hub)
  • Revision ID: ci-train-bot@canonical.com-20160308193600-mwd6jit3baprc6c6
Fix deadlock issue when adding/removing Player instances from the HashedKeyedPlayerStore Fixes: #1542947
Approved by: Alfonso Sanchez-Beato

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
bool media::HashedKeyedPlayerStore::has_player_for_key(const media::Player::PlayerKey& key) const
33
33
{
34
 
    std::lock_guard<std::mutex> lg{guard};
 
34
    std::lock_guard<std::recursive_mutex> lg{guard};
35
35
    return map.count(key) > 0;
36
36
}
37
37
 
38
38
std::shared_ptr<media::Player> media::HashedKeyedPlayerStore::player_for_key(const media::Player::PlayerKey& key) const
39
39
{
40
 
    std::lock_guard<std::mutex> lg{guard};
 
40
    std::lock_guard<std::recursive_mutex> lg{guard};
41
41
    auto it = map.find(key);
42
42
 
43
43
    if (it == map.end()) throw std::out_of_range
50
50
 
51
51
void media::HashedKeyedPlayerStore::enumerate_players(const media::KeyedPlayerStore::PlayerEnumerator& enumerator) const
52
52
{
53
 
    std::lock_guard<std::mutex> lg{guard};
 
53
    std::lock_guard<std::recursive_mutex> lg{guard};
54
54
    for (const auto& pair : map)
55
55
        enumerator(pair.first, pair.second);
56
56
}
57
57
 
58
58
void media::HashedKeyedPlayerStore::add_player_for_key(const media::Player::PlayerKey& key, const std::shared_ptr<media::Player>& player)
59
59
{
60
 
    std::lock_guard<std::mutex> lg{guard};
 
60
    std::lock_guard<std::recursive_mutex> lg{guard};
61
61
    map[key] = player;
62
62
}
63
63
 
64
64
void media::HashedKeyedPlayerStore::remove_player_for_key(const media::Player::PlayerKey& key)
65
65
{
66
 
    std::lock_guard<std::mutex> lg{guard};
 
66
    std::lock_guard<std::recursive_mutex> lg{guard};
67
67
    auto it = map.find(key);
68
68
    if (it != map.end())
69
69
    {
74
74
    }
75
75
}
76
76
 
 
77
size_t media::HashedKeyedPlayerStore::number_of_players() const
 
78
{
 
79
    std::lock_guard<std::recursive_mutex> lg{guard};
 
80
    return map.size();
 
81
}
 
82
 
77
83
void media::HashedKeyedPlayerStore::set_current_player_for_key(const media::Player::PlayerKey& key)
78
84
{
79
85
    prop_current_player = player_for_key(key);