~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/locks/os2/thread_mutex.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * 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_general.h"
 
18
#include "apr_lib.h"
 
19
#include "apr_strings.h"
 
20
#include "apr_portable.h"
 
21
#include "apr_arch_thread_mutex.h"
 
22
#include "apr_arch_file_io.h"
 
23
#include <string.h>
 
24
#include <stddef.h>
 
25
 
 
26
static apr_status_t thread_mutex_cleanup(void *themutex)
 
27
{
 
28
    apr_thread_mutex_t *mutex = themutex;
 
29
    return apr_thread_mutex_destroy(mutex);
 
30
}
 
31
 
 
32
 
 
33
 
 
34
/* XXX: Need to respect APR_THREAD_MUTEX_[UN]NESTED flags argument
 
35
 *      or return APR_ENOTIMPL!!!
 
36
 */
 
37
APR_DECLARE(apr_status_t) apr_thread_mutex_create(apr_thread_mutex_t **mutex,
 
38
                                                  unsigned int flags,
 
39
                                                  apr_pool_t *pool)
 
40
{
 
41
    apr_thread_mutex_t *new_mutex;
 
42
    ULONG rc;
 
43
 
 
44
    new_mutex = (apr_thread_mutex_t *)apr_palloc(pool, sizeof(apr_thread_mutex_t));
 
45
    new_mutex->pool = pool;
 
46
 
 
47
    rc = DosCreateMutexSem(NULL, &(new_mutex->hMutex), 0, FALSE);
 
48
    *mutex = new_mutex;
 
49
 
 
50
    if (!rc)
 
51
        apr_pool_cleanup_register(pool, new_mutex, thread_mutex_cleanup, apr_pool_cleanup_null);
 
52
 
 
53
    return APR_OS2_STATUS(rc);
 
54
}
 
55
 
 
56
 
 
57
 
 
58
APR_DECLARE(apr_status_t) apr_thread_mutex_lock(apr_thread_mutex_t *mutex)
 
59
{
 
60
    ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_INDEFINITE_WAIT);
 
61
    return APR_OS2_STATUS(rc);
 
62
}
 
63
 
 
64
 
 
65
 
 
66
APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex)
 
67
{
 
68
    ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_IMMEDIATE_RETURN);
 
69
    return APR_OS2_STATUS(rc);
 
70
}
 
71
 
 
72
 
 
73
 
 
74
APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex)
 
75
{
 
76
    ULONG rc = DosReleaseMutexSem(mutex->hMutex);
 
77
    return APR_OS2_STATUS(rc);
 
78
}
 
79
 
 
80
 
 
81
 
 
82
APR_DECLARE(apr_status_t) apr_thread_mutex_destroy(apr_thread_mutex_t *mutex)
 
83
{
 
84
    ULONG rc;
 
85
 
 
86
    if (mutex->hMutex == 0)
 
87
        return APR_SUCCESS;
 
88
 
 
89
    while (DosReleaseMutexSem(mutex->hMutex) == 0);
 
90
 
 
91
    rc = DosCloseMutexSem(mutex->hMutex);
 
92
 
 
93
    if (!rc) {
 
94
        mutex->hMutex = 0;
 
95
        return APR_SUCCESS;
 
96
    }
 
97
 
 
98
    return APR_FROM_OS_ERROR(rc);
 
99
}
 
100
 
 
101
APR_POOL_IMPLEMENT_ACCESSOR(thread_mutex)
 
102