Main Page   File List  

lock.h

Go to the documentation of this file.
00001 /* $Id: lock.h 28276 2007-04-10 12:44:30Z adam $ */
00002 /*****************************************************************************/
00011 /*
00012  * Copyright (C) 2000-2004
00013  * Dresden University of Technology, Operating Systems Research Group
00014  *
00015  * This file contains free software, you can redistribute it and/or modify 
00016  * it under the terms of the GNU General Public License, Version 2 as 
00017  * published by the Free Software Foundation (see the file COPYING). 
00018  *
00019  * This program is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  * 
00024  * For different licensing schemes please contact 
00025  * <contact@os.inf.tu-dresden.de>.
00026  */
00027 /*****************************************************************************/
00028 #ifndef __L4UTIL_LOCK_H__
00029 #define __L4UTIL_LOCK_H__
00030 
00031 #include <l4/sys/syscalls.h>
00032 #include <l4/sys/compiler.h>
00033 #include <l4/util/atomic.h>
00034 
00035 EXTERN_C_BEGIN
00036 
00037 typedef l4_uint32_t l4util_simple_lock_t;
00038 
00039 L4_INLINE int  l4_simple_try_lock(l4util_simple_lock_t *lock);
00040 L4_INLINE void l4_simple_unlock(l4util_simple_lock_t *lock);
00041 L4_INLINE int  l4_simple_lock_locked(l4util_simple_lock_t *lock);
00042 L4_INLINE void l4_simple_lock_solid(register l4util_simple_lock_t *p);
00043 L4_INLINE void l4_simple_lock(l4util_simple_lock_t * lock);
00044 
00045 L4_INLINE int 
00046 l4_simple_try_lock(l4util_simple_lock_t *lock)
00047 {
00048   return l4util_xchg32(lock, 1) == 0;
00049 }
00050  
00051 L4_INLINE void 
00052 l4_simple_unlock(l4util_simple_lock_t *lock)
00053 {
00054   *lock = 0;
00055 }
00056 
00057 L4_INLINE int
00058 l4_simple_lock_locked(l4util_simple_lock_t *lock)
00059 {
00060   return (*lock == 0) ? 0 : 1;
00061 }
00062 
00063 L4_INLINE void
00064 l4_simple_lock_solid(register l4util_simple_lock_t *p)
00065 {
00066   while (l4_simple_lock_locked(p) || !l4_simple_try_lock(p))
00067     l4_thread_switch(L4_NIL_ID);
00068 }
00069 
00070 L4_INLINE void
00071 l4_simple_lock(l4util_simple_lock_t * lock)
00072 {
00073   if (!l4_simple_try_lock(lock))
00074     l4_simple_lock_solid(lock);
00075 }
00076 
00077 EXTERN_C_END
00078 
00079 #endif

L4 Utilities, part of DROPS  © 2000-2003