Chromium Code Reviews| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/shared_mutex.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include <algorithm> | |
| 9 | |
| 10 #include "base/string_piece.h" | |
| 11 #include "base/sys_string_conversions.h" | |
| 12 | |
| 13 namespace base { | |
| 14 | |
| 15 SharedMutex::SharedMutex(const std::string& name) : event_(NULL), name_(name) { | |
| 16 } | |
| 17 | |
| 18 bool SharedMutex::TryLock() { | |
| 19 std::wstring wname = base::SysUTF8ToWide(name_); | |
| 
 
sanjeevr
2010/11/09 06:21:05
Please use string16 instead of wstring.
 
dmac
2010/11/11 21:47:59
Done.
 
 | |
| 20 std::replace(wname.begin(), wname.end(), '\\', '!'); | |
| 
 
sanjeevr
2010/11/09 06:21:05
Not sure whether the escaping belongs here or outs
 
dmac
2010/11/11 21:47:59
Pulled escaping out.
 
 | |
| 21 wname = L"Global\\" + wname; | |
| 
 
sanjeevr
2010/11/09 06:21:05
You should not add the "Global\\". We want the eve
 
dmac
2010/11/11 21:47:59
removed, and added comment in header about it.
 
 | |
| 22 event_ = CreateEvent(NULL, FALSE, FALSE, wname.c_str()); | |
| 23 return event_ != NULL; | |
| 24 } | |
| 25 | |
| 26 void SharedMutex::Unlock() { | |
| 27 if (event_) { | |
| 
 
Mark Mentovai
2010/11/09 17:43:14
Don’t we have a ScopedHandle you could use?
 
dmac
2010/11/11 21:47:59
Done.
 
 | |
| 28 CloseHandle(event_); | |
| 29 event_ = NULL; | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 } // namespace base | |
| OLD | NEW |