skia2/include/core/SkMutex.h
bungeman f20488b4f2 Clean up a few includes, introduce iwyu.
The current include-what-you-use with current clang is much less
noisy and more useful than it has been in the past. This change
introduces a few IWYU directives (which are helpful documentation for
humans as well) and fixes a few sets of includes.

Review URL: https://codereview.chromium.org/1207893002
2015-07-29 11:49:40 -07:00

67 lines
1.4 KiB
C++

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkMutex_DEFINED
#define SkMutex_DEFINED
// This file is not part of the public Skia API.
#include "SkTypes.h"
// IWYU pragma: begin_exports
#if defined(SK_BUILD_FOR_WIN)
#include "../ports/SkMutex_win.h"
#else
#include "../ports/SkMutex_pthread.h"
#endif
// IWYU pragma: end_exports
template <typename Lock>
class SkAutoTAcquire : SkNoncopyable {
public:
explicit SkAutoTAcquire(Lock& mutex) : fMutex(&mutex) {
SkASSERT(fMutex != NULL);
mutex.acquire();
}
explicit SkAutoTAcquire(Lock* mutex) : fMutex(mutex) {
if (mutex) {
mutex->acquire();
}
}
/** If the mutex has not been released, release it now. */
~SkAutoTAcquire() {
if (fMutex) {
fMutex->release();
}
}
/** If the mutex has not been released, release it now. */
void release() {
if (fMutex) {
fMutex->release();
fMutex = NULL;
}
}
/** Assert that we're holding the mutex. */
void assertHeld() {
SkASSERT(fMutex);
fMutex->assertHeld();
}
private:
Lock* fMutex;
};
typedef SkAutoTAcquire<SkBaseMutex> SkAutoMutexAcquire;
#define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire)
#endif//SkMutex_DEFINED