1 #ifndef CYGONCE_POSIX_MUTEX_H
2 #define CYGONCE_POSIX_MUTEX_H
3 //=============================================================================
7 // POSIX mutex and condition variable function definitions
9 //=============================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version.
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 // at http://sources.redhat.com/ecos/ecos-license/
40 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND####
42 //=============================================================================
43 //#####DESCRIPTIONBEGIN####
45 // Author(s): nickg,jlarmour
48 // Purpose: POSIX mutex and condition variable function definitions
49 // Description: This header contains POSIX API definitions for mutexes
52 // Usage: #include <pthread.h>
55 //####DESCRIPTIONEND####
57 //=============================================================================
59 #include <pkgconf/posix.h>
61 #include <sys/types.h> // pthread_* types
63 //=============================================================================
66 //-----------------------------------------------------------------------------
67 // Mutex attributes manipulation functions
69 // Initialize attribute object
70 externC int pthread_mutexattr_init ( pthread_mutexattr_t *attr);
72 // Destroy attribute object
73 externC int pthread_mutexattr_destroy ( pthread_mutexattr_t *attr);
75 #if defined(_POSIX_THREAD_PRIO_INHERIT) || defined(_POSIX_THREAD_PRIO_PROTECT)
77 // Set priority inversion protection protocol
78 externC int pthread_mutexattr_setprotocol ( pthread_mutexattr_t *attr,
81 // Get priority inversion protection protocol
82 externC int pthread_mutexattr_getprotocol ( pthread_mutexattr_t *attr,
85 #if defined(_POSIX_THREAD_PRIO_PROTECT)
87 // Set priority for priority ceiling protocol
88 externC int pthread_mutexattr_setprioceiling ( pthread_mutexattr_t *attr,
91 // Get priority for priority ceiling protocol
92 externC int pthread_mutexattr_getprioceiling ( pthread_mutexattr_t *attr,
95 // Set priority ceiling of given thread, returning old ceiling.
96 externC int pthread_mutex_setprioceiling( pthread_mutex_t *mutex,
100 // Get priority ceiling of given thread
101 externC int pthread_mutex_getprioceiling( pthread_mutex_t *mutex,
107 //-----------------------------------------------------------------------------
110 // Initialize mutex. If mutex_attr is NULL, use default attributes.
111 externC int pthread_mutex_init (pthread_mutex_t *mutex,
112 const pthread_mutexattr_t *mutex_attr);
115 externC int pthread_mutex_destroy (pthread_mutex_t *mutex);
117 // Lock mutex, waiting for it if necessary.
118 externC int pthread_mutex_lock (pthread_mutex_t *mutex);
120 // Try to lock mutex.
121 externC int pthread_mutex_trylock (pthread_mutex_t *mutex);
125 externC int pthread_mutex_unlock (pthread_mutex_t *mutex);
129 //=============================================================================
130 // Condition Variables
132 //-----------------------------------------------------------------------------
133 // Attribute manipulation functions
134 // We do not actually support any attributes at present, so these do nothing.
136 // Initialize condition variable attributes
137 externC int pthread_condattr_init (pthread_condattr_t *attr);
139 // Destroy condition variable attributes
140 externC int pthread_condattr_destroy (pthread_condattr_t *attr);
142 //-----------------------------------------------------------------------------
143 // Condition variable functions
145 // Initialize condition variable.
146 externC int pthread_cond_init (pthread_cond_t *cond,
147 const pthread_condattr_t *attr);
149 // Destroy condition variable.
150 externC int pthread_cond_destroy (pthread_cond_t *cond);
152 // Wake up one thread waiting for condition variable
153 externC int pthread_cond_signal (pthread_cond_t *cond);
155 // Wake up all threads waiting for condition variable
156 externC int pthread_cond_broadcast (pthread_cond_t *cond);
158 // Block on condition variable until signalled. The mutex is
159 // assumed to be locked before this call, will be unlocked
160 // during the wait, and will be re-locked on wakeup.
161 externC int pthread_cond_wait (pthread_cond_t *cond,
162 pthread_mutex_t *mutex);
164 // Block on condition variable until signalled, or the timeout expires.
165 externC int pthread_cond_timedwait (pthread_cond_t *cond,
166 pthread_mutex_t *mutex,
167 const struct timespec *abstime);
170 //-----------------------------------------------------------------------------
171 #endif // ifndef CYGONCE_POSIX_MUTEX_H