Peter Xu | f1aff7a | 2018-04-25 10:54:57 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Common qemu-thread implementation header file. |
| 3 | * |
| 4 | * Copyright Red Hat, Inc. 2018 |
| 5 | * |
| 6 | * Authors: |
| 7 | * Peter Xu <peterx@redhat.com>, |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2 or later. |
| 10 | * See the COPYING file in the top-level directory. |
| 11 | */ |
| 12 | |
| 13 | #ifndef QEMU_THREAD_COMMON_H |
| 14 | #define QEMU_THREAD_COMMON_H |
| 15 | |
Peter Xu | f1aff7a | 2018-04-25 10:54:57 +0800 | [diff] [blame] | 16 | #include "qemu/thread.h" |
| 17 | #include "trace.h" |
| 18 | |
| 19 | static inline void qemu_mutex_post_init(QemuMutex *mutex) |
| 20 | { |
Paolo Bonzini | ba59fb7 | 2018-06-13 14:23:08 +0200 | [diff] [blame] | 21 | #ifdef CONFIG_DEBUG_MUTEX |
| 22 | mutex->file = NULL; |
| 23 | mutex->line = 0; |
| 24 | #endif |
Peter Xu | f1aff7a | 2018-04-25 10:54:57 +0800 | [diff] [blame] | 25 | mutex->initialized = true; |
| 26 | } |
| 27 | |
| 28 | static inline void qemu_mutex_pre_lock(QemuMutex *mutex, |
| 29 | const char *file, int line) |
| 30 | { |
| 31 | trace_qemu_mutex_lock(mutex, file, line); |
| 32 | } |
| 33 | |
| 34 | static inline void qemu_mutex_post_lock(QemuMutex *mutex, |
| 35 | const char *file, int line) |
| 36 | { |
Paolo Bonzini | ba59fb7 | 2018-06-13 14:23:08 +0200 | [diff] [blame] | 37 | #ifdef CONFIG_DEBUG_MUTEX |
| 38 | mutex->file = file; |
| 39 | mutex->line = line; |
| 40 | #endif |
Peter Xu | f1aff7a | 2018-04-25 10:54:57 +0800 | [diff] [blame] | 41 | trace_qemu_mutex_locked(mutex, file, line); |
| 42 | } |
| 43 | |
| 44 | static inline void qemu_mutex_pre_unlock(QemuMutex *mutex, |
| 45 | const char *file, int line) |
| 46 | { |
Paolo Bonzini | ba59fb7 | 2018-06-13 14:23:08 +0200 | [diff] [blame] | 47 | #ifdef CONFIG_DEBUG_MUTEX |
| 48 | mutex->file = NULL; |
| 49 | mutex->line = 0; |
| 50 | #endif |
Peter Xu | f1aff7a | 2018-04-25 10:54:57 +0800 | [diff] [blame] | 51 | trace_qemu_mutex_unlock(mutex, file, line); |
| 52 | } |
| 53 | |
| 54 | #endif |