2012-10-13 02:53:12 +08:00
|
|
|
// Copyright (c) 2012 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
2014-09-17 05:19:52 +08:00
|
|
|
#ifndef STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_
|
|
|
|
#define STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_
|
2012-10-13 02:53:12 +08:00
|
|
|
|
2018-02-14 14:31:50 +08:00
|
|
|
// Use Clang's thread safety analysis annotations when available. In other
|
|
|
|
// environments, the macros receive empty definitions.
|
|
|
|
// Usage documentation: https://clang.llvm.org/docs/ThreadSafetyAnalysis.html
|
|
|
|
|
|
|
|
#if !defined(THREAD_ANNOTATION_ATTRIBUTE__)
|
|
|
|
|
|
|
|
#if defined(__clang__)
|
|
|
|
|
|
|
|
#define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
|
|
|
|
#else
|
|
|
|
#define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // !defined(THREAD_ANNOTATION_ATTRIBUTE__)
|
|
|
|
|
|
|
|
#ifndef GUARDED_BY
|
|
|
|
#define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PT_GUARDED_BY
|
|
|
|
#define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ACQUIRED_AFTER
|
|
|
|
#define ACQUIRED_AFTER(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ACQUIRED_BEFORE
|
|
|
|
#define ACQUIRED_BEFORE(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__))
|
|
|
|
#endif
|
2012-10-13 02:53:12 +08:00
|
|
|
|
|
|
|
#ifndef EXCLUSIVE_LOCKS_REQUIRED
|
2018-02-14 14:31:50 +08:00
|
|
|
#define EXCLUSIVE_LOCKS_REQUIRED(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(__VA_ARGS__))
|
2012-10-13 02:53:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SHARED_LOCKS_REQUIRED
|
2018-02-14 14:31:50 +08:00
|
|
|
#define SHARED_LOCKS_REQUIRED(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(shared_locks_required(__VA_ARGS__))
|
2012-10-13 02:53:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LOCKS_EXCLUDED
|
2018-02-14 14:31:50 +08:00
|
|
|
#define LOCKS_EXCLUDED(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
|
2012-10-13 02:53:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LOCK_RETURNED
|
2018-02-14 14:31:50 +08:00
|
|
|
#define LOCK_RETURNED(x) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
|
2012-10-13 02:53:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LOCKABLE
|
2018-02-14 14:31:50 +08:00
|
|
|
#define LOCKABLE \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(lockable)
|
2012-10-13 02:53:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SCOPED_LOCKABLE
|
2018-02-14 14:31:50 +08:00
|
|
|
#define SCOPED_LOCKABLE \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
|
2012-10-13 02:53:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef EXCLUSIVE_LOCK_FUNCTION
|
2018-02-14 14:31:50 +08:00
|
|
|
#define EXCLUSIVE_LOCK_FUNCTION(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(exclusive_lock_function(__VA_ARGS__))
|
2012-10-13 02:53:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SHARED_LOCK_FUNCTION
|
2018-02-14 14:31:50 +08:00
|
|
|
#define SHARED_LOCK_FUNCTION(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(shared_lock_function(__VA_ARGS__))
|
2012-10-13 02:53:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef EXCLUSIVE_TRYLOCK_FUNCTION
|
2018-02-14 14:31:50 +08:00
|
|
|
#define EXCLUSIVE_TRYLOCK_FUNCTION(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(exclusive_trylock_function(__VA_ARGS__))
|
2012-10-13 02:53:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SHARED_TRYLOCK_FUNCTION
|
2018-02-14 14:31:50 +08:00
|
|
|
#define SHARED_TRYLOCK_FUNCTION(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(shared_trylock_function(__VA_ARGS__))
|
2012-10-13 02:53:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef UNLOCK_FUNCTION
|
2018-02-14 14:31:50 +08:00
|
|
|
#define UNLOCK_FUNCTION(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(__VA_ARGS__))
|
2012-10-13 02:53:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef NO_THREAD_SAFETY_ANALYSIS
|
2018-02-14 14:31:50 +08:00
|
|
|
#define NO_THREAD_SAFETY_ANALYSIS \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ASSERT_EXCLUSIVE_LOCK
|
|
|
|
#define ASSERT_EXCLUSIVE_LOCK(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(assert_exclusive_lock(__VA_ARGS__))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ASSERT_SHARED_LOCK
|
|
|
|
#define ASSERT_SHARED_LOCK(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_lock(__VA_ARGS__))
|
2012-10-13 02:53:12 +08:00
|
|
|
#endif
|
|
|
|
|
2014-09-17 05:19:52 +08:00
|
|
|
#endif // STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_
|