70 lines
3.0 KiB
C
70 lines
3.0 KiB
C
/*
|
|
* This file is part of the Flowee project
|
|
* Copyright (C) 2009-2010 Satoshi Nakamoto
|
|
* Copyright (C) 2009-2012 The Bitcoin Core developers
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef FLOWEE_THREADSAFETY_H
|
|
#define FLOWEE_THREADSAFETY_H
|
|
|
|
#ifdef __clang__
|
|
// TL;DR Add GUARDED_BY(mutex) to member variables. The others are
|
|
// rarely necessary. Ex: int nFoo GUARDED_BY(cs_foo);
|
|
//
|
|
// See http://clang.llvm.org/docs/LanguageExtensions.html#threadsafety
|
|
// for documentation. The clang compiler can do advanced static analysis
|
|
// of locking when given the -Wthread-safety option.
|
|
#define LOCKABLE __attribute__((lockable))
|
|
#define SCOPED_LOCKABLE __attribute__((scoped_lockable))
|
|
#define GUARDED_BY(x) __attribute__((guarded_by(x)))
|
|
#define GUARDED_VAR __attribute__((guarded_var))
|
|
#define PT_GUARDED_BY(x) __attribute__((pt_guarded_by(x)))
|
|
#define PT_GUARDED_VAR __attribute__((pt_guarded_var))
|
|
#define ACQUIRED_AFTER(...) __attribute__((acquired_after(__VA_ARGS__)))
|
|
#define ACQUIRED_BEFORE(...) __attribute__((acquired_before(__VA_ARGS__)))
|
|
#define EXCLUSIVE_LOCK_FUNCTION(...) __attribute__((exclusive_lock_function(__VA_ARGS__)))
|
|
#define SHARED_LOCK_FUNCTION(...) __attribute__((shared_lock_function(__VA_ARGS__)))
|
|
#define EXCLUSIVE_TRYLOCK_FUNCTION(...) __attribute__((exclusive_trylock_function(__VA_ARGS__)))
|
|
#define SHARED_TRYLOCK_FUNCTION(...) __attribute__((shared_trylock_function(__VA_ARGS__)))
|
|
#define UNLOCK_FUNCTION(...) __attribute__((unlock_function(__VA_ARGS__)))
|
|
#define LOCK_RETURNED(x) __attribute__((lock_returned(x)))
|
|
#define LOCKS_EXCLUDED(...) __attribute__((locks_excluded(__VA_ARGS__)))
|
|
#define EXCLUSIVE_LOCKS_REQUIRED(...) __attribute__((exclusive_locks_required(__VA_ARGS__)))
|
|
#define SHARED_LOCKS_REQUIRED(...) __attribute__((shared_locks_required(__VA_ARGS__)))
|
|
#define NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis))
|
|
#else
|
|
#define LOCKABLE
|
|
#define SCOPED_LOCKABLE
|
|
#define GUARDED_BY(x)
|
|
#define GUARDED_VAR
|
|
#define PT_GUARDED_BY(x)
|
|
#define PT_GUARDED_VAR
|
|
#define ACQUIRED_AFTER(...)
|
|
#define ACQUIRED_BEFORE(...)
|
|
#define EXCLUSIVE_LOCK_FUNCTION(...)
|
|
#define SHARED_LOCK_FUNCTION(...)
|
|
#define EXCLUSIVE_TRYLOCK_FUNCTION(...)
|
|
#define SHARED_TRYLOCK_FUNCTION(...)
|
|
#define UNLOCK_FUNCTION(...)
|
|
#define LOCK_RETURNED(x)
|
|
#define LOCKS_EXCLUDED(...)
|
|
#define EXCLUSIVE_LOCKS_REQUIRED(...)
|
|
#define SHARED_LOCKS_REQUIRED(...)
|
|
#define NO_THREAD_SAFETY_ANALYSIS
|
|
#endif // __GNUC__
|
|
|
|
#endif
|