~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to iocore/eventsystem/Lock.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
/****************************************************************************
 
25
 
 
26
  Basic Locks for Threads
 
27
 
 
28
 
 
29
 
 
30
**************************************************************************/
 
31
#include "P_EventSystem.h"
 
32
 
 
33
ClassAllocator<ProxyMutex> mutexAllocator("mutexAllocator");
 
34
 
 
35
// #define ERROR_CONFIG_TAG_LOCKS
 
36
 
 
37
#ifdef ERROR_CONFIG_TAG_LOCKS
 
38
#include "Diags.h"
 
39
#endif
 
40
 
 
41
#ifdef DEBUG  // debug build needs lock_* functions
 
42
#undef INK_NO_LOCKS
 
43
#endif
 
44
 
 
45
void
 
46
lock_waiting(const char *file, int line, const char *handler)
 
47
{
 
48
  (void) file;
 
49
  (void) line;
 
50
  (void) handler;
 
51
#ifdef ERROR_CONFIG_TAG_LOCKS
 
52
  if (is_diags_on("locks"))
 
53
    fprintf(stderr, "WARNING: waiting on lock %s:%d for %s\n",
 
54
            file ? file : "UNKNOWN", line, handler ? handler : "UNKNOWN");
 
55
#endif
 
56
}
 
57
 
 
58
void
 
59
lock_holding(const char *file, int line, const char *handler)
 
60
{
 
61
  (void) file;
 
62
  (void) line;
 
63
  (void) handler;
 
64
#ifdef ERROR_CONFIG_TAG_LOCKS
 
65
  if (is_diags_on("locks"))
 
66
    fprintf(stderr, "WARNING: holding lock %s:%d too long for %s\n",
 
67
            file ? file : "UNKNOWN", line, handler ? handler : "UNKNOWN");
 
68
#endif
 
69
}
 
70
 
 
71
void
 
72
lock_taken(const char *file, int line, const char *handler)
 
73
{
 
74
  (void) file;
 
75
  (void) line;
 
76
  (void) handler;
 
77
#ifdef ERROR_CONFIG_TAG_LOCKS
 
78
  if (is_diags_on("locks"))
 
79
    fprintf(stderr, "WARNING: lock %s:%d taken too many times for %s\n",
 
80
            file ? file : "UNKNOWN", line, handler ? handler : "UNKNOWN");
 
81
#endif
 
82
}
 
83
 
 
84
#ifdef LOCK_CONTENTION_PROFILING
 
85
void
 
86
ProxyMutex::print_lock_stats(int flag)
 
87
{
 
88
  if (flag) {
 
89
    if (total_acquires < 10)
 
90
      return;
 
91
    printf("Lock Stats (Dying):successful %d (%.2f%%), unsuccessful %d (%.2f%%) blocking %d \n",
 
92
           successful_nonblocking_acquires,
 
93
           (nonblocking_acquires > 0 ?
 
94
            successful_nonblocking_acquires * 100.0 / nonblocking_acquires : 0.0),
 
95
           unsuccessful_nonblocking_acquires,
 
96
           (nonblocking_acquires > 0 ?
 
97
            unsuccessful_nonblocking_acquires * 100.0 / nonblocking_acquires : 0.0), blocking_acquires);
 
98
    fflush(stdout);
 
99
  } else {
 
100
    if (!(total_acquires % 100)) {
 
101
      printf("Lock Stats (Alive):successful %d (%.2f%%), unsuccessful %d (%.2f%%) blocking %d \n",
 
102
             successful_nonblocking_acquires,
 
103
             (nonblocking_acquires > 0 ?
 
104
              successful_nonblocking_acquires * 100.0 / nonblocking_acquires : 0.0),
 
105
             unsuccessful_nonblocking_acquires,
 
106
             (nonblocking_acquires > 0 ?
 
107
              unsuccessful_nonblocking_acquires * 100.0 / nonblocking_acquires : 0.0), blocking_acquires);
 
108
      fflush(stdout);
 
109
    }
 
110
  }
 
111
}
 
112
#endif //LOCK_CONTENTION_PROFILING