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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include "apr_arch_thread_mutex.h"
22 #include "apr_arch_thread_cond.h"
24 static apr_status_t thread_cond_cleanup(void *data)
26 apr_thread_cond_t *cond = (apr_thread_cond_t *)data;
29 rv = pthread_cond_destroy(&cond->cond);
30 #ifdef HAVE_ZOS_PTHREADS
38 APR_DECLARE(apr_status_t) apr_thread_cond_create(apr_thread_cond_t **cond,
41 apr_thread_cond_t *new_cond;
44 new_cond = apr_palloc(pool, sizeof(apr_thread_cond_t));
46 new_cond->pool = pool;
48 if ((rv = pthread_cond_init(&new_cond->cond, NULL))) {
49 #ifdef HAVE_ZOS_PTHREADS
55 apr_pool_cleanup_register(new_cond->pool,
56 (void *)new_cond, thread_cond_cleanup,
57 apr_pool_cleanup_null);
63 APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
64 apr_thread_mutex_t *mutex)
68 rv = pthread_cond_wait(&cond->cond, &mutex->mutex);
69 #ifdef HAVE_ZOS_PTHREADS
77 APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
78 apr_thread_mutex_t *mutex,
79 apr_interval_time_t timeout)
83 struct timespec abstime;
85 then = apr_time_now() + timeout;
86 abstime.tv_sec = apr_time_sec(then);
87 abstime.tv_nsec = apr_time_usec(then) * 1000; /* nanoseconds */
89 rv = pthread_cond_timedwait(&cond->cond, &mutex->mutex, &abstime);
90 #ifdef HAVE_ZOS_PTHREADS
95 if (ETIMEDOUT == rv) {
102 APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
106 rv = pthread_cond_signal(&cond->cond);
107 #ifdef HAVE_ZOS_PTHREADS
115 APR_DECLARE(apr_status_t) apr_thread_cond_broadcast(apr_thread_cond_t *cond)
119 rv = pthread_cond_broadcast(&cond->cond);
120 #ifdef HAVE_ZOS_PTHREADS
128 APR_DECLARE(apr_status_t) apr_thread_cond_destroy(apr_thread_cond_t *cond)
130 return apr_pool_cleanup_run(cond->pool, cond, thread_cond_cleanup);
133 APR_POOL_IMPLEMENT_ACCESSOR(thread_cond)
135 #endif /* APR_HAS_THREADS */