1bb535300SJeff Roberson /* 2bb535300SJeff Roberson * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. 3bb535300SJeff Roberson * All rights reserved. 4bb535300SJeff Roberson * 5bb535300SJeff Roberson * Redistribution and use in source and binary forms, with or without 6bb535300SJeff Roberson * modification, are permitted provided that the following conditions 7bb535300SJeff Roberson * are met: 8bb535300SJeff Roberson * 1. Redistributions of source code must retain the above copyright 9bb535300SJeff Roberson * notice, this list of conditions and the following disclaimer. 10bb535300SJeff Roberson * 2. Redistributions in binary form must reproduce the above copyright 11bb535300SJeff Roberson * notice, this list of conditions and the following disclaimer in the 12bb535300SJeff Roberson * documentation and/or other materials provided with the distribution. 13bb535300SJeff Roberson * 3. All advertising materials mentioning features or use of this software 14bb535300SJeff Roberson * must display the following acknowledgement: 15bb535300SJeff Roberson * This product includes software developed by John Birrell. 16bb535300SJeff Roberson * 4. Neither the name of the author nor the names of any co-contributors 17bb535300SJeff Roberson * may be used to endorse or promote products derived from this software 18bb535300SJeff Roberson * without specific prior written permission. 19bb535300SJeff Roberson * 20bb535300SJeff Roberson * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 21bb535300SJeff Roberson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22bb535300SJeff Roberson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23bb535300SJeff Roberson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24bb535300SJeff Roberson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25bb535300SJeff Roberson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26bb535300SJeff Roberson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27bb535300SJeff Roberson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28bb535300SJeff Roberson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29bb535300SJeff Roberson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30bb535300SJeff Roberson * SUCH DAMAGE. 31bb535300SJeff Roberson * 32bb535300SJeff Roberson * $FreeBSD$ 33bb535300SJeff Roberson * 34bb535300SJeff Roberson */ 35bb535300SJeff Roberson 36bb535300SJeff Roberson #include <stdlib.h> 37bb535300SJeff Roberson #include <stdio.h> 38bb535300SJeff Roberson #include <string.h> 39bb535300SJeff Roberson #include <sched.h> 40bb535300SJeff Roberson #include <pthread.h> 41bb535300SJeff Roberson #include <unistd.h> 42bb535300SJeff Roberson 43bb535300SJeff Roberson #include <libc_private.h> 44bb535300SJeff Roberson 45bb535300SJeff Roberson #include "thr_private.h" 46bb535300SJeff Roberson 47bb535300SJeff Roberson void 48bb535300SJeff Roberson _spinunlock(spinlock_t *lck) 49bb535300SJeff Roberson { 50bb535300SJeff Roberson struct pthread *curthread = _get_curthread(); 51bb535300SJeff Roberson 52bb535300SJeff Roberson if (umtx_unlock((struct umtx *)lck, curthread->thr_id)) 53bb535300SJeff Roberson abort(); 54bb535300SJeff Roberson } 55bb535300SJeff Roberson 56bb535300SJeff Roberson /* 57bb535300SJeff Roberson * Lock a location for the running thread. Yield to allow other 58bb535300SJeff Roberson * threads to run if this thread is blocked because the lock is 59bb535300SJeff Roberson * not available. Note that this function does not sleep. It 60bb535300SJeff Roberson * assumes that the lock will be available very soon. 61bb535300SJeff Roberson */ 62bb535300SJeff Roberson void 63bb535300SJeff Roberson _spinlock(spinlock_t *lck) 64bb535300SJeff Roberson { 65bb535300SJeff Roberson struct pthread *curthread = _get_curthread(); 66bb535300SJeff Roberson 67bb535300SJeff Roberson if (umtx_lock((struct umtx *)lck, curthread->thr_id)) 68bb535300SJeff Roberson abort(); 69bb535300SJeff Roberson } 70bb535300SJeff Roberson 71bb535300SJeff Roberson /* 72bb535300SJeff Roberson * Lock a location for the running thread. Yield to allow other 73bb535300SJeff Roberson * threads to run if this thread is blocked because the lock is 74bb535300SJeff Roberson * not available. Note that this function does not sleep. It 75bb535300SJeff Roberson * assumes that the lock will be available very soon. 76bb535300SJeff Roberson * 77bb535300SJeff Roberson * This function checks if the running thread has already locked the 78bb535300SJeff Roberson * location, warns if this occurs and creates a thread dump before 79bb535300SJeff Roberson * returning. 80bb535300SJeff Roberson */ 81bb535300SJeff Roberson void 82bb535300SJeff Roberson _spinlock_debug(spinlock_t *lck, char *fname, int lineno) 83bb535300SJeff Roberson { 84bb535300SJeff Roberson struct pthread *curthread = _get_curthread(); 85bb535300SJeff Roberson 86bb535300SJeff Roberson if (umtx_lock((struct umtx *)lck, curthread->thr_id)) 87bb535300SJeff Roberson abort(); 88bb535300SJeff Roberson } 89