[BACK]Return to sync.h CVS log [TXT][DIR] Up to [local] / prex-old / sys / include

Annotation of prex-old/sys/include/sync.h, Revision 1.1.1.1

1.1       nbrk        1: /*-
                      2:  * Copyright (c) 2005-2007, 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 <event.h>
                     34: #include <task.h>
                     35:
                     36: struct sem {
                     37:        int             magic;          /* magic number */
                     38:        task_t          task;           /* owner task */
                     39:        struct event    event;          /* event */
                     40:        u_int           value;          /* current value */
                     41: };
                     42:
                     43: struct mutex {
                     44:        int             magic;          /* magic number */
                     45:        task_t          task;           /* owner task */
                     46:        struct event    event;          /* event */
                     47:        struct list     link;           /* linkage on locked mutex list */
                     48:        thread_t        owner;          /* owner thread locking this mutex */
                     49:        int             prio;           /* highest prio in waiting threads */
                     50:        int             lock_count;     /* counter for recursive lock */
                     51: };
                     52:
                     53: struct cond {
                     54:        int             magic;          /* magic number */
                     55:        task_t          task;           /* owner task */
                     56:        struct event    event;          /* event */
                     57: };
                     58:
                     59: #define sem_valid(s)   (kern_area(s) && ((s)->magic == SEM_MAGIC))
                     60:
                     61: #define mutex_valid(m) (kern_area(m) && \
                     62:                         ((m)->magic == MUTEX_MAGIC) && \
                     63:                         ((m)->task == cur_task()))
                     64:
                     65: #define cond_valid(c)  (kern_area(c) && \
                     66:                         ((c)->magic == COND_MAGIC) && \
                     67:                         ((c)->task == cur_task()))
                     68:
                     69: /* maximum value for semaphore. */
                     70: #define MAXSEMVAL              ((u_int)((~0u) >> 1))
                     71:
                     72: #define MUTEX_INITIALIZER      (mutex_t)0x4d496e69     /* 'MIni' */
                     73: #define COND_INITIALIZER       (cond_t)0x43496e69      /* 'CIni' */
                     74:
                     75: extern int      sem_init(sem_t *, u_int);
                     76: extern int      sem_destroy(sem_t *);
                     77: extern int      sem_wait(sem_t *, u_long);
                     78: extern int      sem_trywait(sem_t *);
                     79: extern int      sem_post(sem_t *);
                     80: extern int      sem_getvalue(sem_t *, u_int *);
                     81:
                     82: extern int      mutex_init(mutex_t *);
                     83: extern int      mutex_destroy(mutex_t *);
                     84: extern int      mutex_lock(mutex_t *);
                     85: extern int      mutex_trylock(mutex_t *);
                     86: extern int      mutex_unlock(mutex_t *);
                     87: extern void     mutex_cleanup(thread_t);
                     88: extern void     mutex_setprio(thread_t, int);
                     89:
                     90: extern int      cond_init(cond_t *);
                     91: extern int      cond_destroy(cond_t *);
                     92: extern int      cond_wait(cond_t *, mutex_t *);
                     93: extern int      cond_signal(cond_t *);
                     94: extern int      cond_broadcast(cond_t *);
                     95:
                     96: #endif /* !_SYNC_H */

CVSweb