View | Details | Raw Unified | Return to bug 39289
Collapse All | Expand All

(-)test/testglobalmutex.h.orig (+4 lines)
Lines 17-25 Link Here
17
#ifndef TESTGLOBALMUTEX_H
17
#ifndef TESTGLOBALMUTEX_H
18
#define TESTGLOBALMUTEX_H
18
#define TESTGLOBALMUTEX_H
19
19
20
#define NORMAL_MODE 0
21
#define TRY_MODE 1
22
20
/* set this to 255 so that the child processes can return it successfully. */
23
/* set this to 255 so that the child processes can return it successfully. */
21
#define MAX_ITER 255
24
#define MAX_ITER 255
22
#define MAX_COUNTER (MAX_ITER * 4)
25
#define MAX_COUNTER (MAX_ITER * 4)
26
#define MAX_WAIT_USEC (1000*1000)
23
27
24
#define LOCKNAME "data/apr_globalmutex.lock"
28
#define LOCKNAME "data/apr_globalmutex.lock"
25
29
(-)test/testglobalmutex.c.orig (-9 / +31 lines)
Lines 21-31 Link Here
21
#include "apr_errno.h"
21
#include "apr_errno.h"
22
#include "testutil.h"
22
#include "testutil.h"
23
23
24
static void launch_child(abts_case *tc, apr_lockmech_e mech,
24
static void launch_child(abts_case *tc, int mode, apr_lockmech_e mech,
25
                         apr_proc_t *proc, apr_pool_t *p)
25
                         apr_proc_t *proc, apr_pool_t *p)
26
{
26
{
27
    apr_procattr_t *procattr;
27
    apr_procattr_t *procattr;
28
    const char *args[3];
28
    const char *args[4];
29
    apr_status_t rv;
29
    apr_status_t rv;
30
30
31
    rv = apr_procattr_create(&procattr, p);
31
    rv = apr_procattr_create(&procattr, p);
Lines 39-46 Link Here
39
    APR_ASSERT_SUCCESS(tc, "Couldn't set error check in procattr", rv);
39
    APR_ASSERT_SUCCESS(tc, "Couldn't set error check in procattr", rv);
40
40
41
    args[0] = "globalmutexchild" EXTENSION;
41
    args[0] = "globalmutexchild" EXTENSION;
42
    args[1] = (const char*)apr_itoa(p, (int)mech);
42
    args[1] = (const char*)apr_itoa(p, mode);
43
    args[2] = NULL;
43
    args[2] = (const char*)apr_itoa(p, (int)mech);
44
    args[3] = NULL;
44
    rv = apr_proc_create(proc, "./globalmutexchild" EXTENSION, args, NULL,
45
    rv = apr_proc_create(proc, "./globalmutexchild" EXTENSION, args, NULL,
45
            procattr, p);
46
            procattr, p);
46
    APR_ASSERT_SUCCESS(tc, "Couldn't launch program", rv);
47
    APR_ASSERT_SUCCESS(tc, "Couldn't launch program", rv);
Lines 81-94 Link Here
81
    int x = 0;
82
    int x = 0;
82
    abts_log_message("lock mechanism is: ");
83
    abts_log_message("lock mechanism is: ");
83
    abts_log_message(mutexname(mech));
84
    abts_log_message(mutexname(mech));
85
    abts_log_message("using normal lock mode");
84
 
86
 
85
    rv = apr_global_mutex_create(&global_lock, LOCKNAME, mech, p);
87
    rv = apr_global_mutex_create(&global_lock, LOCKNAME, mech, p);
86
    APR_ASSERT_SUCCESS(tc, "Error creating mutex", rv);
88
    APR_ASSERT_SUCCESS(tc, "Error creating mutex", rv);
87
89
88
    launch_child(tc, mech, &p1, p);
90
    launch_child(tc, NORMAL_MODE, mech, &p1, p);
89
    launch_child(tc, mech, &p2, p);
91
    launch_child(tc, NORMAL_MODE, mech, &p2, p);
90
    launch_child(tc, mech, &p3, p);
92
    launch_child(tc, NORMAL_MODE, mech, &p3, p);
91
    launch_child(tc, mech, &p4, p);
93
    launch_child(tc, NORMAL_MODE, mech, &p4, p);
92
 
94
 
93
    x += wait_child(tc, &p1);
95
    x += wait_child(tc, &p1);
94
    x += wait_child(tc, &p2);
96
    x += wait_child(tc, &p2);
Lines 97-103 Link Here
97
99
98
    if (x != MAX_COUNTER) {
100
    if (x != MAX_COUNTER) {
99
        char buf[200];
101
        char buf[200];
100
        sprintf(buf, "global mutex '%s' failed: %d not %d",
102
        sprintf(buf, "global mutex '%s' failed: %d not %d (in normal mode)",
103
                mutexname(mech), x, MAX_COUNTER);
104
        abts_fail(tc, buf, __LINE__);
105
    }
106
107
    x = 0;
108
    abts_log_message("using try lock mode");
109
110
    launch_child(tc, TRY_MODE, mech, &p1, p);
111
    launch_child(tc, TRY_MODE, mech, &p2, p);
112
    launch_child(tc, TRY_MODE, mech, &p3, p);
113
    launch_child(tc, TRY_MODE, mech, &p4, p);
114
 
115
    x += wait_child(tc, &p1);
116
    x += wait_child(tc, &p2);
117
    x += wait_child(tc, &p3);
118
    x += wait_child(tc, &p4);
119
120
    if (x != MAX_COUNTER) {
121
        char buf[200];
122
        sprintf(buf, "global mutex '%s' failed: %d not %d (in try mode)",
101
                mutexname(mech), x, MAX_COUNTER);
123
                mutexname(mech), x, MAX_COUNTER);
102
        abts_fail(tc, buf, __LINE__);
124
        abts_fail(tc, buf, __LINE__);
103
    }
125
    }
(-)test/globalmutexchild.c.orig (-2 / +22 lines)
Lines 31-36 Link Here
31
{
31
{
32
    apr_pool_t *p;
32
    apr_pool_t *p;
33
    int i = 0;
33
    int i = 0;
34
    int mode;
34
    apr_lockmech_e mech;
35
    apr_lockmech_e mech;
35
    apr_global_mutex_t *global_lock;
36
    apr_global_mutex_t *global_lock;
36
    apr_status_t rv;
37
    apr_status_t rv;
Lines 40-46 Link Here
40
    
41
    
41
    apr_pool_create(&p, NULL);
42
    apr_pool_create(&p, NULL);
42
    if (argc >= 2) {
43
    if (argc >= 2) {
43
        mech = (apr_lockmech_e)apr_strtoi64(argv[1], NULL, 0);
44
        mode = atoi(argv[1]);
45
    }
46
    else {
47
        mode = NORMAL_MODE;
48
    }
49
    if (argc >= 3) {
50
        mech = (apr_lockmech_e)apr_strtoi64(argv[2], NULL, 0);
44
    }
51
    }
45
    else {
52
    else {
46
        mech = APR_LOCK_DEFAULT;
53
        mech = APR_LOCK_DEFAULT;
Lines 52-58 Link Here
52
    apr_global_mutex_child_init(&global_lock, LOCKNAME, p);
59
    apr_global_mutex_child_init(&global_lock, LOCKNAME, p);
53
    
60
    
54
    while (1) {
61
    while (1) {
55
        apr_global_mutex_lock(global_lock);
62
        if (mode == NORMAL_MODE) {
63
            apr_global_mutex_lock(global_lock);
64
        }
65
        else {
66
            int wait_usec = 0;
67
68
            while (rv = apr_global_mutex_trylock(global_lock)) {
69
                if (!APR_STATUS_IS_EBUSY(rv))
70
                    exit(-rv);
71
                if (++wait_usec >= MAX_WAIT_USEC)
72
                    exit(-APR_EBUSY);
73
                apr_sleep(1);
74
            }
75
        }
56
        if (i == MAX_ITER) {
76
        if (i == MAX_ITER) {
57
            apr_global_mutex_unlock(global_lock);
77
            apr_global_mutex_unlock(global_lock);
58
            exit(i);
78
            exit(i);

Return to bug 39289