Chromium Code Reviews| Index: base/shared_mutex_win.cc |
| diff --git a/base/shared_mutex_win.cc b/base/shared_mutex_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..324d3930db1b8d64a4a1d8da0d671db10a46717c |
| --- /dev/null |
| +++ b/base/shared_mutex_win.cc |
| @@ -0,0 +1,33 @@ |
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/shared_mutex.h" |
| + |
| +#include <string> |
| +#include <algorithm> |
| + |
| +#include "base/string_piece.h" |
| +#include "base/sys_string_conversions.h" |
| + |
| +namespace base { |
| + |
| +SharedMutex::SharedMutex(const std::string& name) : event_(NULL), name_(name) { |
| +} |
| + |
| +bool SharedMutex::TryLock() { |
| + 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.
|
| + 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.
|
| + 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.
|
| + event_ = CreateEvent(NULL, FALSE, FALSE, wname.c_str()); |
| + return event_ != NULL; |
| +} |
| + |
| +void SharedMutex::Unlock() { |
| + 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.
|
| + CloseHandle(event_); |
| + event_ = NULL; |
| + } |
| +} |
| + |
| +} // namespace base |