Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Side by Side Diff: base/message_loop/message_pump_libevent.h

Issue 19661004: Made MessagePump a non-thread safe class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding a missing header. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_ 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_
6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_ 6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher); 91 DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher);
92 }; 92 };
93 93
94 enum Mode { 94 enum Mode {
95 WATCH_READ = 1 << 0, 95 WATCH_READ = 1 << 0,
96 WATCH_WRITE = 1 << 1, 96 WATCH_WRITE = 1 << 1,
97 WATCH_READ_WRITE = WATCH_READ | WATCH_WRITE 97 WATCH_READ_WRITE = WATCH_READ | WATCH_WRITE
98 }; 98 };
99 99
100 MessagePumpLibevent(); 100 MessagePumpLibevent();
101 virtual ~MessagePumpLibevent();
101 102
102 // Have the current thread's message loop watch for a a situation in which 103 // Have the current thread's message loop watch for a a situation in which
103 // reading/writing to the FD can be performed without blocking. 104 // reading/writing to the FD can be performed without blocking.
104 // Callers must provide a preallocated FileDescriptorWatcher object which 105 // Callers must provide a preallocated FileDescriptorWatcher object which
105 // can later be used to manage the lifetime of this event. 106 // can later be used to manage the lifetime of this event.
106 // If a FileDescriptorWatcher is passed in which is already attached to 107 // If a FileDescriptorWatcher is passed in which is already attached to
107 // an event, then the effect is cumulative i.e. after the call |controller| 108 // an event, then the effect is cumulative i.e. after the call |controller|
108 // will watch both the previous event and the new one. 109 // will watch both the previous event and the new one.
109 // If an error occurs while calling this method in a cumulative fashion, the 110 // If an error occurs while calling this method in a cumulative fashion, the
110 // event previously attached to |controller| is aborted. 111 // event previously attached to |controller| is aborted.
111 // Returns true on success. 112 // Returns true on success.
112 // Must be called on the same thread the message_pump is running on. 113 // Must be called on the same thread the message_pump is running on.
113 // TODO(dkegel): switch to edge-triggered readiness notification 114 // TODO(dkegel): switch to edge-triggered readiness notification
114 bool WatchFileDescriptor(int fd, 115 bool WatchFileDescriptor(int fd,
115 bool persistent, 116 bool persistent,
116 int mode, 117 int mode,
117 FileDescriptorWatcher *controller, 118 FileDescriptorWatcher *controller,
118 Watcher *delegate); 119 Watcher *delegate);
119 120
120 void AddIOObserver(IOObserver* obs); 121 void AddIOObserver(IOObserver* obs);
121 void RemoveIOObserver(IOObserver* obs); 122 void RemoveIOObserver(IOObserver* obs);
122 123
123 // MessagePump methods: 124 // MessagePump methods:
124 virtual void Run(Delegate* delegate) OVERRIDE; 125 virtual void Run(Delegate* delegate) OVERRIDE;
125 virtual void Quit() OVERRIDE; 126 virtual void Quit() OVERRIDE;
126 virtual void ScheduleWork() OVERRIDE; 127 virtual void ScheduleWork() OVERRIDE;
127 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) OVERRIDE; 128 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) OVERRIDE;
128 129
129 protected:
130 virtual ~MessagePumpLibevent();
131
132 private: 130 private:
133 friend class MessagePumpLibeventTest; 131 friend class MessagePumpLibeventTest;
134 132
135 void WillProcessIOEvent(); 133 void WillProcessIOEvent();
136 void DidProcessIOEvent(); 134 void DidProcessIOEvent();
137 135
138 // Risky part of constructor. Returns true on success. 136 // Risky part of constructor. Returns true on success.
139 bool Init(); 137 bool Init();
140 138
141 // Called by libevent to tell us a registered FD can be read/written to. 139 // Called by libevent to tell us a registered FD can be read/written to.
(...skipping 28 matching lines...) Expand all
170 event* wakeup_event_; 168 event* wakeup_event_;
171 169
172 ObserverList<IOObserver> io_observers_; 170 ObserverList<IOObserver> io_observers_;
173 ThreadChecker watch_file_descriptor_caller_checker_; 171 ThreadChecker watch_file_descriptor_caller_checker_;
174 DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent); 172 DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent);
175 }; 173 };
176 174
177 } // namespace base 175 } // namespace base
178 176
179 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_ 177 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_
OLDNEW
« no previous file with comments | « base/message_loop/message_pump_io_ios_unittest.cc ('k') | base/message_loop/message_pump_libevent_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698