lib_mutex.cc 752 B

1234567891011121314151617181920212223242526272829303132
  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
  3. // found in the LICENSE file.
  4. #include "rlz/win/lib/lib_mutex.h"
  5. #include <windows.h>
  6. #include "base/win/windows_version.h"
  7. namespace {
  8. const long kTimeoutMs = 5000L;
  9. const wchar_t kMutexName[] = L"{A946A6A9-917E-4949-B9BC-6BADA8C7FD63}";
  10. } // namespace
  11. namespace rlz_lib {
  12. LibMutex::LibMutex() : acquired_(false), mutex_(NULL) {
  13. mutex_ = CreateMutex(NULL, FALSE, kMutexName);
  14. if (mutex_)
  15. acquired_ = (WAIT_OBJECT_0 == WaitForSingleObject(mutex_, kTimeoutMs));
  16. }
  17. LibMutex::~LibMutex() {
  18. if (acquired_)
  19. ReleaseMutex(mutex_);
  20. if (mutex_)
  21. CloseHandle(mutex_);
  22. }
  23. } // namespace rlz_lib