Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/Event.cpp

Issue 29369479: Issue #4694 - Add mutex protection to JS event handling
Patch Set: Created Dec. 21, 2016, 7:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "Event.h"
19
20 void EventManager::Set(const std::string& eventName, AdblockPlus::JsEngine::Even tCallback callback)
21 {
22 UniqueLockType ul(m);
23 eventMap[eventName] = callback;
24 }
25
26 void EventManager::Remove(const std::string& eventName)
27 {
28 UniqueLockType ul(m);
29 eventMap.erase(eventName);
30 }
31
32 /**
33 * \par Implementation Notes
34 *
35 * A triggered event runs with mutex unlocked.
sergei 2017/03/15 12:17:20 I don't think we need this comment.
36 */
37 void EventManager::Trigger(const std::string& eventName, AdblockPlus::JsValueLis t& args)
38 {
39 AdblockPlus::JsEngine::EventCallback f;
40 {
41 // Find the callback with mutex locked
sergei 2017/03/15 12:17:20 this comment is superfluous.
42 UniqueLockType ul(m);
43 auto it = eventMap.find(eventName);
44 if (it == eventMap.end())
45 {
46 return;
47 }
48 f = it->second;
49 }
50 // Execute the callback with mutex unlocked
sergei 2017/03/15 12:17:20 this comment is superfluous.
51 f(args);
52 }
OLDNEW

Powered by Google App Engine
This is Rietveld