1 // -----------------------------------------------------------------------
2 // Copyright (C) 2006 - 2007 FRESCOR consortium partners:
4 // Universidad de Cantabria, SPAIN
5 // University of York, UK
6 // Scuola Superiore Sant'Anna, ITALY
7 // Kaiserslautern University, GERMANY
8 // Univ. Politecnica Valencia, SPAIN
9 // Czech Technical University in Prague, CZECH REPUBLIC
11 // Thales Communication S.A. FRANCE
12 // Visual Tools S.A. SPAIN
13 // Rapita Systems Ltd UK
16 // See http://www.frescor.org for a link to partners' websites
18 // FRESCOR project (FP6/2005/IST/5-034026) is funded
19 // in part by the European Union Sixth Framework Programme
20 // The European Union is not liable of any use that may be
23 // This file is part of the FRSH implementation
25 // FRSH is free software; you can redistribute it and/or modify
26 // it under the terms of the GNU General Public License as published by
27 // the Free Software Foundation; either version 2, or (at your option)
30 // FRSH is distributed in the hope that it will be useful, but
31 // WITHOUT ANY WARRANTY; without even the implied warranty of
32 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33 // General Public License for more details.
35 // You should have received a copy of the GNU General Public License
36 // distributed with FRSH; see file COPYING. If not, write to the
37 // Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
40 // As a special exception, if you include this header file into source
41 // files to be compiled, this header file does not by itself cause
42 // the resulting executable to be covered by the GNU General Public
43 // License. This exception does not however invalidate any other
44 // reasons why the executable file might be covered by the GNU General
46 // -----------------------------------------------------------------------
47 //fosa_mutexes_and_condvars.h
48 //==============================================
49 // ******** ****** ******** **********
50 // **///// /** ** **////// /** /**
51 // ** /** ** /** /** /**
52 // ******* /** ** /********* /**********
53 // **//// /** ** ////////** /**//////**
54 // ** /** ** /** /** /**
55 // ** /** ** ******** /** /**
56 // // /******/ //////// // //
58 // FOSA(Frescor Operating System Adaptation layer)
59 //================================================
64 /*******************************************************
65 * Mutexes with priority/bandwidth inheritance
66 ******************************************************/
69 int fosa_mutex_init(frsh_mutex_t *mutex, int prioceiling)
71 pthread_mutexattr_t mutex_attr;
73 /* prioceiling serves as a flag */
75 /* We use priority inheritance as the default protocol */
76 pthread_mutexattr_init(&mutex_attr);
77 pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT);
79 return pthread_mutex_init(mutex, &mutex_attr);
81 return pthread_mutex_init(mutex, NULL);
84 int fosa_mutex_destroy(frsh_mutex_t *mutex)
86 return pthread_mutex_destroy(mutex);
89 int fosa_mutex_set_prioceiling(frsh_mutex_t *mutex,
96 int fosa_mutex_get_prioceiling(const frsh_mutex_t *mutex, int *ceiling)
101 int fosa_mutex_lock(frsh_mutex_t *mutex)
103 return pthread_mutex_lock(mutex);
106 int fosa_mutex_trylock(frsh_mutex_t *mutex)
108 return pthread_mutex_trylock(mutex);
111 int fosa_mutex_unlock(frsh_mutex_t *mutex)
113 return pthread_mutex_unlock(mutex);
116 /**********************
117 * Condition variables
118 *********************/
120 int fosa_cond_init(fosa_cond_t *cond)
122 return pthread_cond_init(cond, NULL);
125 int fosa_cond_destroy(fosa_cond_t *cond)
127 return pthread_cond_destroy(cond);
130 int fosa_cond_signal(fosa_cond_t *cond)
132 return pthread_cond_signal(cond);
135 int fosa_cond_broadcast(fosa_cond_t *cond)
137 return pthread_cond_broadcast(cond);
140 int fosa_cond_wait(fosa_cond_t *cond, frsh_mutex_t *mutex)
142 return pthread_cond_wait(cond, mutex);
145 int fosa_cond_timedwait(fosa_cond_t *cond,
147 const struct timespec *abstime)
149 return pthread_cond_timedwait(cond, mutex, abstime);