chromium/third_party/skia/src/base/SkSharedMutex.h

/*
 * 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 SkSharedLock_DEFINED
#define SkSharedLock_DEFINED

#include "include/private/base/SkDebug.h"
#include "include/private/base/SkSemaphore.h"
#include "include/private/base/SkThreadAnnotations.h"

#ifdef SK_DEBUG
    #include "include/private/base/SkMutex.h"
    #include <memory>
#endif  // SK_DEBUG

// There are two shared lock implementations one debug the other is high performance. They implement
// an interface similar to pthread's rwlocks.
// This is a shared lock implementation similar to pthreads rwlocks. The high performance
// implementation is cribbed from Preshing's article:
// http://preshing.com/20150316/semaphores-are-surprisingly-versatile/
//
// This lock does not obey strict queue ordering. It will always alternate between readers and
// a single writer.
class SK_CAPABILITY("mutex") SkSharedMutex {};

#ifndef SK_DEBUG
inline void SkSharedMutex::assertHeld() const {}
inline void SkSharedMutex::assertHeldShared() const {}
#endif  // SK_DEBUG

class SK_SCOPED_CAPABILITY SkAutoSharedMutexExclusive {};

class SK_SCOPED_CAPABILITY SkAutoSharedMutexShared {};

#endif // SkSharedLock_DEFINED