Merge lock annotation macros in threads.h
This commit is contained in:
parent
53d10f48b5
commit
bed6ac416b
7 changed files with 59 additions and 99 deletions
|
@ -28,7 +28,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include "locks_annotate.h"
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include "threads.h"
|
#include "threads.h"
|
||||||
|
|
2
cnd.c
2
cnd.c
|
@ -28,7 +28,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include "locks_annotate.h"
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
/*-
|
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 1991, 1993
|
|
||||||
* The Regents of the University of California. All rights reserved.
|
|
||||||
*
|
|
||||||
* This code is derived from software contributed to Berkeley by
|
|
||||||
* Berkeley Software Design, Inc.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of the University nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
|
||||||
* without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
||||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
||||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
||||||
* SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* @(#)cdefs.h 8.8 (Berkeley) 1/9/95
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _LOCKS_ANNOTATE_H
|
|
||||||
#define _LOCKS_ANNOTATE_H
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Lock annotations.
|
|
||||||
*
|
|
||||||
* Clang provides support for doing basic thread-safety tests at
|
|
||||||
* compile-time, by marking which locks will/should be held when
|
|
||||||
* entering/leaving a functions.
|
|
||||||
*
|
|
||||||
* Furthermore, it is also possible to annotate variables and structure
|
|
||||||
* members to enforce that they are only accessed when certain locks are
|
|
||||||
* held.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if __has_extension(c_thread_safety_attributes)
|
|
||||||
#define __lock_annotate(x) __attribute__((x))
|
|
||||||
#else
|
|
||||||
#define __lock_annotate(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Structure implements a lock. */
|
|
||||||
#define __lockable __lock_annotate(lockable)
|
|
||||||
|
|
||||||
/* Function acquires an exclusive or shared lock. */
|
|
||||||
#define __locks_exclusive(...) \
|
|
||||||
__lock_annotate(exclusive_lock_function(__VA_ARGS__))
|
|
||||||
#define __locks_shared(...) \
|
|
||||||
__lock_annotate(shared_lock_function(__VA_ARGS__))
|
|
||||||
|
|
||||||
/* Function attempts to acquire an exclusive or shared lock. */
|
|
||||||
#define __trylocks_exclusive(...) \
|
|
||||||
__lock_annotate(exclusive_trylock_function(__VA_ARGS__))
|
|
||||||
#define __trylocks_shared(...) \
|
|
||||||
__lock_annotate(shared_trylock_function(__VA_ARGS__))
|
|
||||||
|
|
||||||
/* Function releases a lock. */
|
|
||||||
#define __unlocks(...) __lock_annotate(unlock_function(__VA_ARGS__))
|
|
||||||
|
|
||||||
/* Function asserts that an exclusive or shared lock is held. */
|
|
||||||
#define __asserts_exclusive(...) \
|
|
||||||
__lock_annotate(assert_exclusive_lock(__VA_ARGS__))
|
|
||||||
#define __asserts_shared(...) \
|
|
||||||
__lock_annotate(assert_shared_lock(__VA_ARGS__))
|
|
||||||
|
|
||||||
|
|
||||||
/* Function requires that an exclusive or shared lock is or is not held. */
|
|
||||||
#define __requires_exclusive(...) \
|
|
||||||
__lock_annotate(exclusive_locks_required(__VA_ARGS__))
|
|
||||||
#define __requires_shared(...) \
|
|
||||||
__lock_annotate(shared_locks_required(__VA_ARGS__))
|
|
||||||
#define __requires_unlocked(...) \
|
|
||||||
__lock_annotate(locks_excluded(__VA_ARGS__))
|
|
||||||
|
|
||||||
/* Function should not be analyzed. */
|
|
||||||
#define __no_lock_analysis __lock_annotate(no_thread_safety_analysis)
|
|
||||||
|
|
||||||
#endif
|
|
2
mtx.c
2
mtx.c
|
@ -28,7 +28,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include "locks_annotate.h"
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
|
|
2
thrd.c
2
thrd.c
|
@ -28,7 +28,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include "locks_annotate.h"
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
54
threads.h
54
threads.h
|
@ -33,6 +33,60 @@
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lock annotations.
|
||||||
|
*
|
||||||
|
* Clang provides support for doing basic thread-safety tests at
|
||||||
|
* compile-time, by marking which locks will/should be held when
|
||||||
|
* entering/leaving a functions.
|
||||||
|
*
|
||||||
|
* Furthermore, it is also possible to annotate variables and structure
|
||||||
|
* members to enforce that they are only accessed when certain locks are
|
||||||
|
* held.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if __has_extension(c_thread_safety_attributes)
|
||||||
|
#define __lock_annotate(x) __attribute__((x))
|
||||||
|
#else
|
||||||
|
#define __lock_annotate(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Structure implements a lock. */
|
||||||
|
#define __lockable __lock_annotate(lockable)
|
||||||
|
|
||||||
|
/* Function acquires an exclusive or shared lock. */
|
||||||
|
#define __locks_exclusive(...) \
|
||||||
|
__lock_annotate(exclusive_lock_function(__VA_ARGS__))
|
||||||
|
#define __locks_shared(...) \
|
||||||
|
__lock_annotate(shared_lock_function(__VA_ARGS__))
|
||||||
|
|
||||||
|
/* Function attempts to acquire an exclusive or shared lock. */
|
||||||
|
#define __trylocks_exclusive(...) \
|
||||||
|
__lock_annotate(exclusive_trylock_function(__VA_ARGS__))
|
||||||
|
#define __trylocks_shared(...) \
|
||||||
|
__lock_annotate(shared_trylock_function(__VA_ARGS__))
|
||||||
|
|
||||||
|
/* Function releases a lock. */
|
||||||
|
#define __unlocks(...) __lock_annotate(unlock_function(__VA_ARGS__))
|
||||||
|
|
||||||
|
/* Function asserts that an exclusive or shared lock is held. */
|
||||||
|
#define __asserts_exclusive(...) \
|
||||||
|
__lock_annotate(assert_exclusive_lock(__VA_ARGS__))
|
||||||
|
#define __asserts_shared(...) \
|
||||||
|
__lock_annotate(assert_shared_lock(__VA_ARGS__))
|
||||||
|
|
||||||
|
|
||||||
|
/* Function requires that an exclusive or shared lock is or is not held. */
|
||||||
|
#define __requires_exclusive(...) \
|
||||||
|
__lock_annotate(exclusive_locks_required(__VA_ARGS__))
|
||||||
|
#define __requires_shared(...) \
|
||||||
|
__lock_annotate(shared_locks_required(__VA_ARGS__))
|
||||||
|
#define __requires_unlocked(...) \
|
||||||
|
__lock_annotate(locks_excluded(__VA_ARGS__))
|
||||||
|
|
||||||
|
/* Function should not be analyzed. */
|
||||||
|
#define __no_lock_analysis __lock_annotate(no_thread_safety_analysis)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The C11 threads interface.
|
* The C11 threads interface.
|
||||||
*
|
*
|
||||||
|
|
2
tss.c
2
tss.c
|
@ -28,7 +28,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include "locks_annotate.h"
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include "threads.h"
|
#include "threads.h"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue