fibril_synch.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009 Jakub Jermar 
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef LIBC_FIBRIL_SYNCH_H_
00036 #define LIBC_FIBRIL_SYNCH_H_
00037 
00038 #include <fibril.h>
00039 #include <adt/list.h>
00040 #include <libarch/tls.h>
00041 #include <sys/time.h>
00042 #include <bool.h>
00043 
00044 typedef struct {
00045         fibril_owner_info_t oi;  
00046         int counter;
00047         link_t waiters;
00048 } fibril_mutex_t;
00049 
00050 #define FIBRIL_MUTEX_INITIALIZER(name) \
00051         { \
00052                 .oi = { \
00053                         .owned_by = NULL \
00054                 }, \
00055                 .counter = 1, \
00056                 .waiters = { \
00057                         .prev = &name.waiters, \
00058                         .next = &name.waiters, \
00059                 } \
00060         }
00061         
00062 #define FIBRIL_MUTEX_INITIALIZE(name) \
00063         fibril_mutex_t name = FIBRIL_MUTEX_INITIALIZER(name) 
00064 
00065 typedef struct {
00066         fibril_owner_info_t oi;  
00067         unsigned writers;
00068         unsigned readers;
00069         link_t waiters;
00070 } fibril_rwlock_t;
00071 
00072 #define FIBRIL_RWLOCK_INITIALIZER(name) \
00073         { \
00074                 .oi = { \
00075                         .owned_by = NULL \
00076                 }, \
00077                 .readers = 0, \
00078                 .writers = 0, \
00079                 .waiters = { \
00080                         .prev = &name.waiters, \
00081                         .next = &name.waiters, \
00082                 } \
00083         }
00084 
00085 #define FIBRIL_RWLOCK_INITIALIZE(name) \
00086         fibril_rwlock_t name = FIBRIL_RWLOCK_INITIALIZER(name)
00087 
00088 typedef struct {
00089         link_t waiters;
00090 } fibril_condvar_t;
00091 
00092 #define FIBRIL_CONDVAR_INITIALIZER(name) \
00093         { \
00094                 .waiters = { \
00095                         .next = &name.waiters, \
00096                         .prev = &name.waiters, \
00097                 } \
00098         }
00099 
00100 #define FIBRIL_CONDVAR_INITIALIZE(name) \
00101         fibril_condvar_t name = FIBRIL_CONDVAR_INITIALIZER(name)
00102 
00103 extern void fibril_mutex_initialize(fibril_mutex_t *);
00104 extern void fibril_mutex_lock(fibril_mutex_t *);
00105 extern bool fibril_mutex_trylock(fibril_mutex_t *);
00106 extern void fibril_mutex_unlock(fibril_mutex_t *);
00107 extern bool fibril_mutex_is_locked(fibril_mutex_t *);
00108 
00109 extern void fibril_rwlock_initialize(fibril_rwlock_t *);
00110 extern void fibril_rwlock_read_lock(fibril_rwlock_t *);
00111 extern void fibril_rwlock_write_lock(fibril_rwlock_t *);
00112 extern void fibril_rwlock_read_unlock(fibril_rwlock_t *);
00113 extern void fibril_rwlock_write_unlock(fibril_rwlock_t *);
00114 extern bool fibril_rwlock_is_read_locked(fibril_rwlock_t *);
00115 extern bool fibril_rwlock_is_write_locked(fibril_rwlock_t *);
00116 extern bool fibril_rwlock_is_locked(fibril_rwlock_t *);
00117 
00118 extern void fibril_condvar_initialize(fibril_condvar_t *);
00119 extern int fibril_condvar_wait_timeout(fibril_condvar_t *, fibril_mutex_t *,
00120     suseconds_t);
00121 extern void fibril_condvar_wait(fibril_condvar_t *, fibril_mutex_t *);
00122 extern void fibril_condvar_signal(fibril_condvar_t *);
00123 extern void fibril_condvar_broadcast(fibril_condvar_t *);
00124 
00125 #endif
00126 

Generated on Thu Jun 2 07:45:46 2011 for HelenOS/USB by  doxygen 1.4.7