pbrook | d597536 | 2008-06-07 20:50:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2003 Fabrice Bellard |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
Blue Swirl | 8167ee8 | 2009-07-16 20:47:01 +0000 | [diff] [blame] | 15 | * License along with this library; if not, see <http://www.gnu.org/licenses/> |
pbrook | d597536 | 2008-06-07 20:50:51 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
Peter Maydell | 0261533 | 2011-01-31 18:26:40 +0000 | [diff] [blame] | 18 | /* configure guarantees us that we have pthreads on any host except |
| 19 | * mingw32, which doesn't support any of the user-only targets. |
| 20 | * So we can simply assume we have pthread mutexes here. |
| 21 | */ |
| 22 | #if defined(CONFIG_USER_ONLY) |
pbrook | d597536 | 2008-06-07 20:50:51 +0000 | [diff] [blame] | 23 | |
| 24 | #include <pthread.h> |
| 25 | #define spin_lock pthread_mutex_lock |
| 26 | #define spin_unlock pthread_mutex_unlock |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 27 | #define spinlock_t pthread_mutex_t |
pbrook | d597536 | 2008-06-07 20:50:51 +0000 | [diff] [blame] | 28 | #define SPIN_LOCK_UNLOCKED PTHREAD_MUTEX_INITIALIZER |
| 29 | |
| 30 | #else |
| 31 | |
Peter Maydell | 0261533 | 2011-01-31 18:26:40 +0000 | [diff] [blame] | 32 | /* Empty implementations, on the theory that system mode emulation |
| 33 | * is single-threaded. This means that these functions should only |
| 34 | * be used from code run in the TCG cpu thread, and cannot protect |
| 35 | * data structures which might also be accessed from the IO thread |
| 36 | * or from signal handlers. |
| 37 | */ |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 38 | typedef int spinlock_t; |
pbrook | d597536 | 2008-06-07 20:50:51 +0000 | [diff] [blame] | 39 | #define SPIN_LOCK_UNLOCKED 0 |
| 40 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 41 | static inline void spin_lock(spinlock_t *lock) |
pbrook | d597536 | 2008-06-07 20:50:51 +0000 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 45 | static inline void spin_unlock(spinlock_t *lock) |
pbrook | d597536 | 2008-06-07 20:50:51 +0000 | [diff] [blame] | 46 | { |
| 47 | } |
pbrook | d597536 | 2008-06-07 20:50:51 +0000 | [diff] [blame] | 48 | |
| 49 | #endif |