![]() |
![]() |
OpenMP Runtime
|
00001 /* Copyright (C) 2008, 2009 Free Software Foundation, Inc. 00002 Contributed by Jakub Jelinek <jakub@redhat.com>. 00003 00004 This file is part of the GNU OpenMP Library (libgomp). 00005 00006 Libgomp is free software; you can redistribute it and/or modify it 00007 under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3, or (at your option) 00009 any later version. 00010 00011 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY 00012 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00013 FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00014 more details. 00015 00016 Under Section 7 of GPL version 3, you are granted additional 00017 permissions described in the GCC Runtime Library Exception, version 00018 3.1, as published by the Free Software Foundation. 00019 00020 You should have received a copy of the GNU General Public License and 00021 a copy of the GCC Runtime Library Exception along with this program; 00022 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 <http://www.gnu.org/licenses/>. */ 00024 00025 /* Copyright (C) 2012 00026 Texas Instruments, Inc. 00027 00028 Using a Hardware Semaphore to implement mutex lock/unlock 00029 */ 00030 00031 00032 #ifndef GOMP_PTRLOCK_H 00033 #define GOMP_PTRLOCK_H 1 00034 00035 #include "tomp_util.h" 00036 00037 typedef struct { void *ptr; volatile unsigned int lock; } gomp_ptrlock_t; 00038 00039 static inline void gomp_ptrlock_init (gomp_ptrlock_t *ptrlock, void *ptr) 00040 { 00041 ptrlock->ptr = ptr; 00042 ptrlock->lock = TOMP_WS_HW_SEM_IDX; 00043 } 00044 00045 static inline void *gomp_ptrlock_get (gomp_ptrlock_t *ptrlock) 00046 { 00047 if (ptrlock->ptr != NULL) 00048 return ptrlock->ptr; 00049 00050 /* First thread to hit this point from gomp_loop_*_start acquires the lock 00051 * All remaining threads will sit and 00052 * spin here waiting for the lock to be released by the first thread 00053 * via gomp_ptrlock_set 00054 */ 00055 tomp_mutex_lock (ptrlock->lock); 00056 if (ptrlock->ptr != NULL) 00057 { 00058 tomp_mutex_unlock (ptrlock->lock); 00059 return ptrlock->ptr; 00060 } 00061 00062 return NULL; 00063 } 00064 00065 static inline void gomp_ptrlock_set (gomp_ptrlock_t *ptrlock, void *ptr) 00066 { 00067 ptrlock->ptr = ptr; 00068 tomp_mutex_unlock (ptrlock->lock); 00069 } 00070 00071 static inline void gomp_ptrlock_destroy (gomp_ptrlock_t *ptrlock) 00072 { 00073 /* Nothing to do here */ 00074 } 00075 00076 #endif /* GOMP_PTRLOCK_H */