|
|||
Prex Home / Browse Source - Prex Version: 0.9.0 |
|||
root/sys/include/sync.h/* [<][>][^][v][top][bottom][index][help] */INCLUDED FROM1 /*- 2 * Copyright (c) 2005-2008, Kohsuke Ohtani 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the author nor the names of any co-contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #ifndef _SYNC_H 31 #define _SYNC_H 32 33 #include <types.h> 34 #include <sys/cdefs.h> 35 #include <sys/list.h> 36 #include <event.h> 37 38 struct sem { 39 struct sem *next; /* linkage on semaphore list in system */ 40 struct list task_link; /* linkage on semaphore list in task */ 41 task_t owner; /* owner task */ 42 struct event event; /* event */ 43 u_int value; /* current value */ 44 int refcnt; /* reference count */ 45 }; 46 47 struct mutex { 48 struct list task_link; /* linkage on mutex list in task */ 49 task_t owner; /* owner task */ 50 struct event event; /* event */ 51 struct list link; /* linkage on locked mutex list */ 52 thread_t holder; /* thread that holds the mutex */ 53 int priority; /* highest priority in waiting threads */ 54 int locks; /* counter for recursive lock */ 55 }; 56 57 struct cond { 58 struct list task_link; /* linkage on cv list in task */ 59 task_t owner; /* owner task */ 60 struct event event; /* event */ 61 }; 62 63 /* maximum value for semaphore. */ 64 #define MAXSEMVAL ((u_int)((~0u) >> 1)) 65 66 /* max mutex count to inherit priority */ 67 #define MAXINHERIT 10 68 69 #define MUTEX_INITIALIZER (mutex_t)0x4d496e69 /* 'MIni' */ 70 #define COND_INITIALIZER (cond_t)0x43496e69 /* 'CIni' */ 71 72 __BEGIN_DECLS 73 int sem_init(sem_t *, u_int); 74 int sem_destroy(sem_t *); 75 int sem_wait(sem_t *, u_long); 76 int sem_trywait(sem_t *); 77 int sem_post(sem_t *); 78 int sem_getvalue(sem_t *, u_int *); 79 void sem_cleanup(task_t); 80 81 int mutex_init(mutex_t *); 82 int mutex_destroy(mutex_t *); 83 int mutex_lock(mutex_t *); 84 int mutex_trylock(mutex_t *); 85 int mutex_unlock(mutex_t *); 86 void mutex_cancel(thread_t); 87 void mutex_setpri(thread_t, int); 88 void mutex_cleanup(task_t); 89 90 int cond_init(cond_t *); 91 int cond_destroy(cond_t *); 92 int cond_wait(cond_t *, mutex_t *); 93 int cond_signal(cond_t *); 94 int cond_broadcast(cond_t *); 95 void cond_cleanup(task_t); 96 __END_DECLS 97 98 #endif /* !_SYNC_H */ /* [<][>][^][v][top][bottom][index][help] */ | |||
Copyright© 2005-2009 Kohsuke Ohtani |