1 /* Host thread abstraction for GCC.
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_HOST_THREAD_H
22 #define GCC_HOST_THREAD_H
24 /* For now, just pthreads. */
27 typedef pthread_mutex_t host_mutex
;
28 typedef pthread_cond_t host_condition
;
30 static inline host_mutex
*
31 host_mutex_create (void)
33 host_mutex
*result
= XNEW (host_mutex
);
34 pthread_mutex_init (result
, NULL
);
39 host_mutex_lock (host_mutex
*m
)
41 pthread_mutex_lock (m
);
45 host_mutex_unlock (host_mutex
*m
)
47 pthread_mutex_unlock (m
);
50 static inline host_condition
*
51 host_condition_create (void)
53 host_condition
*result
= XNEW (host_condition
);
54 pthread_cond_init (result
, NULL
);
59 host_condition_wait (host_condition
*c
, host_mutex
*m
)
61 pthread_cond_wait (c
, m
);
65 host_condition_broadcast (host_condition
*c
)
67 pthread_cond_broadcast (c
);
71 host_thread_create (void *(*func
) (void *), void *arg
)
75 pthread_attr_init (&attr
);
76 pthread_attr_setdetachstate (&attr
, PTHREAD_CREATE_DETACHED
);
77 /* FIXME: error handling. */
78 pthread_create (&thr
, &attr
, func
, arg
);
79 pthread_attr_destroy (&attr
);
82 #endif /* GCC_HOST_THREAD_H */