Apache HTTPD
thread_cond.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "apr.h"
18
19#if APR_HAS_THREADS
20
21#include "apr_arch_thread_mutex.h"
22#include "apr_arch_thread_cond.h"
23
25{
27 apr_status_t rv;
28
29 rv = pthread_cond_destroy(&cond->cond);
30#ifdef HAVE_ZOS_PTHREADS
31 if (rv) {
32 rv = errno;
33 }
34#endif
35 return rv;
36}
37
40{
42 apr_status_t rv;
43
45
46 new_cond->pool = pool;
47
48 if ((rv = pthread_cond_init(&new_cond->cond, NULL))) {
49#ifdef HAVE_ZOS_PTHREADS
50 rv = errno;
51#endif
52 return rv;
53 }
54
58
59 *cond = new_cond;
60 return APR_SUCCESS;
61}
62
64 apr_thread_mutex_t *mutex)
65{
66 apr_status_t rv;
67
68 rv = pthread_cond_wait(&cond->cond, &mutex->mutex);
69#ifdef HAVE_ZOS_PTHREADS
70 if (rv) {
71 rv = errno;
72 }
73#endif
74 return rv;
75}
76
78 apr_thread_mutex_t *mutex,
80{
81 apr_status_t rv;
82 if (timeout < 0) {
83 rv = pthread_cond_wait(&cond->cond, &mutex->mutex);
84#ifdef HAVE_ZOS_PTHREADS
85 if (rv) {
86 rv = errno;
87 }
88#endif
89 }
90 else {
92 struct timespec abstime;
93
95 abstime.tv_sec = apr_time_sec(then);
96 abstime.tv_nsec = apr_time_usec(then) * 1000; /* nanoseconds */
97
98 rv = pthread_cond_timedwait(&cond->cond, &mutex->mutex, &abstime);
99#ifdef HAVE_ZOS_PTHREADS
100 if (rv) {
101 rv = errno;
102 }
103#endif
104 if (ETIMEDOUT == rv) {
105 return APR_TIMEUP;
106 }
107 }
108 return rv;
109}
110
111
113{
114 apr_status_t rv;
115
116 rv = pthread_cond_signal(&cond->cond);
117#ifdef HAVE_ZOS_PTHREADS
118 if (rv) {
119 rv = errno;
120 }
121#endif
122 return rv;
123}
124
126{
127 apr_status_t rv;
128
129 rv = pthread_cond_broadcast(&cond->cond);
130#ifdef HAVE_ZOS_PTHREADS
131 if (rv) {
132 rv = errno;
133 }
134#endif
135 return rv;
136}
137
139{
140 return apr_pool_cleanup_run(cond->pool, cond, thread_cond_cleanup);
141}
142
144
145#endif /* APR_HAS_THREADS */
static apr_status_t thread_cond_cleanup(void *data)
Definition thread_cond.c:22
#define APR_TIMEUP
Definition apr_errno.h:450
const void apr_status_t(*) apr_status_t(* APR_DECLARE)(void) apr_pool_pre_cleanup_register(apr_pool_t *p
Definition apr_pools.h:646
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * data
#define APR_POOL_IMPLEMENT_ACCESSOR(type)
Definition apr_pools.h:91
apr_int64_t apr_interval_time_t
Definition apr_time.h:55
apr_int64_t apr_time_t
Definition apr_time.h:45
#define apr_time_sec(time)
Definition apr_time.h:63
#define apr_time_usec(time)
Definition apr_time.h:66
return NULL
Definition mod_so.c:359
IN ULONG IN INT timeout