~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to lib/ts/test_freelist.cc

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
  A brief file description
 
4
 
 
5
  @section license License
 
6
 
 
7
  Licensed to the Apache Software Foundation (ASF) under one
 
8
  or more contributor license agreements.  See the NOTICE file
 
9
  distributed with this work for additional information
 
10
  regarding copyright ownership.  The ASF licenses this file
 
11
  to you under the Apache License, Version 2.0 (the
 
12
  "License"); you may not use this file except in compliance
 
13
  with the License.  You may obtain a copy of the License at
 
14
 
 
15
      http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
17
  Unless required by applicable law or agreed to in writing, software
 
18
  distributed under the License is distributed on an "AS IS" BASIS,
 
19
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
20
  See the License for the specific language governing permissions and
 
21
  limitations under the License.
 
22
 */
 
23
 
 
24
#include <stdlib.h>
 
25
#include <string.h>
 
26
#include "ink_thread.h"
 
27
#include "ink_queue.h"
 
28
#include "ink_unused.h" /* MAGIC_EDITING_TAG */
 
29
 
 
30
 
 
31
#define NTHREADS 64
 
32
 
 
33
 
 
34
InkFreeList *flist = NULL;
 
35
 
 
36
 
 
37
void *
 
38
test(void *d)
 
39
{
 
40
  int id;
 
41
  void *m1, *m2, *m3;
 
42
 
 
43
  id = *((int *) &d);
 
44
 
 
45
  time_t start = time(NULL);
 
46
  int count = 0;
 
47
  for (;;) {
 
48
    m1 = ink_freelist_new(flist);
 
49
    m2 = ink_freelist_new(flist);
 
50
    m3 = ink_freelist_new(flist);
 
51
 
 
52
    if ((m1 == m2) || (m1 == m3) || (m2 == m3)) {
 
53
      printf("0x%08llx   0x%08llx   0x%08llx\n", (uint64_t)(uintptr_t) m1, (uint64_t)(uintptr_t) m2, (uint64_t)(uintptr_t) m3);
 
54
      exit(1);
 
55
    }
 
56
 
 
57
    memset(m1, id, 64);
 
58
    memset(m2, id, 64);
 
59
    memset(m3, id, 64);
 
60
 
 
61
    ink_freelist_free(flist, m1);
 
62
    ink_freelist_free(flist, m2);
 
63
    ink_freelist_free(flist, m3);
 
64
 
 
65
    // break out of the test if we have run more then 60 seconds
 
66
    if (++count % 1000 == 0 && (start + 60) < time(NULL)) {
 
67
      return NULL;
 
68
    }
 
69
  }
 
70
 
 
71
}
 
72
 
 
73
 
 
74
int
 
75
main(int argc, char *argv[])
 
76
{
 
77
  ink_thread threads[NTHREADS];
 
78
  //void *status;
 
79
  int i;
 
80
 
 
81
  flist = ink_freelist_create("woof", 64, 256, 0, 8);
 
82
 
 
83
  for (i = 0; i < NTHREADS; i++) {
 
84
    fprintf(stderr, "Create thread %d\n", i);
 
85
    threads[i] = ink_thread_create(test, (void *) i);
 
86
  }
 
87
 
 
88
  test((void *) NTHREADS);
 
89
 
 
90
  return 0;
 
91
}