1 |
27 |
unneback |
#ifndef CYGONCE_POSIX_MUTEX_H
|
2 |
|
|
#define CYGONCE_POSIX_MUTEX_H
|
3 |
|
|
//=============================================================================
|
4 |
|
|
//
|
5 |
|
|
// mutex.h
|
6 |
|
|
//
|
7 |
|
|
// POSIX mutex and condition variable function definitions
|
8 |
|
|
//
|
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.
|
14 |
|
|
//
|
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.
|
18 |
|
|
//
|
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
|
22 |
|
|
// for more details.
|
23 |
|
|
//
|
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.
|
27 |
|
|
//
|
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.
|
34 |
|
|
//
|
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.
|
37 |
|
|
//
|
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####
|
44 |
|
|
//
|
45 |
|
|
// Author(s): nickg,jlarmour
|
46 |
|
|
// Contributors:
|
47 |
|
|
// Date: 2001-09-10
|
48 |
|
|
// Purpose: POSIX mutex and condition variable function definitions
|
49 |
|
|
// Description: This header contains POSIX API definitions for mutexes
|
50 |
|
|
// and cond vars.
|
51 |
|
|
//
|
52 |
|
|
// Usage: #include <pthread.h>
|
53 |
|
|
//
|
54 |
|
|
//
|
55 |
|
|
//####DESCRIPTIONEND####
|
56 |
|
|
//
|
57 |
|
|
//=============================================================================
|
58 |
|
|
|
59 |
|
|
#include <pkgconf/posix.h>
|
60 |
|
|
|
61 |
|
|
#include <sys/types.h> // pthread_* types
|
62 |
|
|
|
63 |
|
|
//=============================================================================
|
64 |
|
|
// Mutexes
|
65 |
|
|
|
66 |
|
|
//-----------------------------------------------------------------------------
|
67 |
|
|
// Mutex attributes manipulation functions
|
68 |
|
|
|
69 |
|
|
// Initialize attribute object
|
70 |
|
|
externC int pthread_mutexattr_init ( pthread_mutexattr_t *attr);
|
71 |
|
|
|
72 |
|
|
// Destroy attribute object
|
73 |
|
|
externC int pthread_mutexattr_destroy ( pthread_mutexattr_t *attr);
|
74 |
|
|
|
75 |
|
|
#if defined(_POSIX_THREAD_PRIO_INHERIT) || defined(_POSIX_THREAD_PRIO_PROTECT)
|
76 |
|
|
|
77 |
|
|
// Set priority inversion protection protocol
|
78 |
|
|
externC int pthread_mutexattr_setprotocol ( pthread_mutexattr_t *attr,
|
79 |
|
|
int protocol);
|
80 |
|
|
|
81 |
|
|
// Get priority inversion protection protocol
|
82 |
|
|
externC int pthread_mutexattr_getprotocol ( pthread_mutexattr_t *attr,
|
83 |
|
|
int *protocol);
|
84 |
|
|
|
85 |
|
|
#if defined(_POSIX_THREAD_PRIO_PROTECT)
|
86 |
|
|
|
87 |
|
|
// Set priority for priority ceiling protocol
|
88 |
|
|
externC int pthread_mutexattr_setprioceiling ( pthread_mutexattr_t *attr,
|
89 |
|
|
int prioceiling);
|
90 |
|
|
|
91 |
|
|
// Get priority for priority ceiling protocol
|
92 |
|
|
externC int pthread_mutexattr_getprioceiling ( pthread_mutexattr_t *attr,
|
93 |
|
|
int *prioceiling);
|
94 |
|
|
|
95 |
|
|
// Set priority ceiling of given thread, returning old ceiling.
|
96 |
|
|
externC int pthread_mutex_setprioceiling( pthread_mutex_t *mutex,
|
97 |
|
|
int prioceiling,
|
98 |
|
|
int *old_ceiling);
|
99 |
|
|
|
100 |
|
|
// Get priority ceiling of given thread
|
101 |
|
|
externC int pthread_mutex_getprioceiling( pthread_mutex_t *mutex,
|
102 |
|
|
int *prioceiling);
|
103 |
|
|
#endif
|
104 |
|
|
|
105 |
|
|
#endif
|
106 |
|
|
|
107 |
|
|
//-----------------------------------------------------------------------------
|
108 |
|
|
// Mutex functions
|
109 |
|
|
|
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);
|
113 |
|
|
|
114 |
|
|
// Destroy mutex.
|
115 |
|
|
externC int pthread_mutex_destroy (pthread_mutex_t *mutex);
|
116 |
|
|
|
117 |
|
|
// Lock mutex, waiting for it if necessary.
|
118 |
|
|
externC int pthread_mutex_lock (pthread_mutex_t *mutex);
|
119 |
|
|
|
120 |
|
|
// Try to lock mutex.
|
121 |
|
|
externC int pthread_mutex_trylock (pthread_mutex_t *mutex);
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
// Unlock mutex.
|
125 |
|
|
externC int pthread_mutex_unlock (pthread_mutex_t *mutex);
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
//=============================================================================
|
130 |
|
|
// Condition Variables
|
131 |
|
|
|
132 |
|
|
//-----------------------------------------------------------------------------
|
133 |
|
|
// Attribute manipulation functions
|
134 |
|
|
// We do not actually support any attributes at present, so these do nothing.
|
135 |
|
|
|
136 |
|
|
// Initialize condition variable attributes
|
137 |
|
|
externC int pthread_condattr_init (pthread_condattr_t *attr);
|
138 |
|
|
|
139 |
|
|
// Destroy condition variable attributes
|
140 |
|
|
externC int pthread_condattr_destroy (pthread_condattr_t *attr);
|
141 |
|
|
|
142 |
|
|
//-----------------------------------------------------------------------------
|
143 |
|
|
// Condition variable functions
|
144 |
|
|
|
145 |
|
|
// Initialize condition variable.
|
146 |
|
|
externC int pthread_cond_init (pthread_cond_t *cond,
|
147 |
|
|
const pthread_condattr_t *attr);
|
148 |
|
|
|
149 |
|
|
// Destroy condition variable.
|
150 |
|
|
externC int pthread_cond_destroy (pthread_cond_t *cond);
|
151 |
|
|
|
152 |
|
|
// Wake up one thread waiting for condition variable
|
153 |
|
|
externC int pthread_cond_signal (pthread_cond_t *cond);
|
154 |
|
|
|
155 |
|
|
// Wake up all threads waiting for condition variable
|
156 |
|
|
externC int pthread_cond_broadcast (pthread_cond_t *cond);
|
157 |
|
|
|
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);
|
163 |
|
|
|
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);
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
//-----------------------------------------------------------------------------
|
171 |
|
|
#endif // ifndef CYGONCE_POSIX_MUTEX_H
|
172 |
|
|
// End of mutex.h
|