• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Lock.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /****************************************************************************
00025 
00026   Basic Locks for Threads
00027 
00028 
00029 
00030 **************************************************************************/
00031 #include "P_EventSystem.h"
00032 
00033 ClassAllocator<ProxyMutex> mutexAllocator("mutexAllocator");
00034 
00035 // #define ERROR_CONFIG_TAG_LOCKS
00036 
00037 #ifdef ERROR_CONFIG_TAG_LOCKS
00038 #include "Diags.h"
00039 #endif
00040 
00041 #ifdef DEBUG  // debug build needs lock_* functions
00042 #undef INK_NO_LOCKS
00043 #endif
00044 
00045 void
00046 lock_waiting(const char *file, int line, const char *handler)
00047 {
00048   (void) file;
00049   (void) line;
00050   (void) handler;
00051 #ifdef ERROR_CONFIG_TAG_LOCKS
00052   if (is_diags_on("locks"))
00053     fprintf(stderr, "WARNING: waiting on lock %s:%d for %s\n",
00054             file ? file : "UNKNOWN", line, handler ? handler : "UNKNOWN");
00055 #endif
00056 }
00057 
00058 void
00059 lock_holding(const char *file, int line, const char *handler)
00060 {
00061   (void) file;
00062   (void) line;
00063   (void) handler;
00064 #ifdef ERROR_CONFIG_TAG_LOCKS
00065   if (is_diags_on("locks"))
00066     fprintf(stderr, "WARNING: holding lock %s:%d too long for %s\n",
00067             file ? file : "UNKNOWN", line, handler ? handler : "UNKNOWN");
00068 #endif
00069 }
00070 
00071 void
00072 lock_taken(const char *file, int line, const char *handler)
00073 {
00074   (void) file;
00075   (void) line;
00076   (void) handler;
00077 #ifdef ERROR_CONFIG_TAG_LOCKS
00078   if (is_diags_on("locks"))
00079     fprintf(stderr, "WARNING: lock %s:%d taken too many times for %s\n",
00080             file ? file : "UNKNOWN", line, handler ? handler : "UNKNOWN");
00081 #endif
00082 }
00083 
00084 #ifdef LOCK_CONTENTION_PROFILING
00085 void
00086 ProxyMutex::print_lock_stats(int flag)
00087 {
00088   if (flag) {
00089     if (total_acquires < 10)
00090       return;
00091     printf("Lock Stats (Dying):successful %d (%.2f%%), unsuccessful %d (%.2f%%) blocking %d \n",
00092            successful_nonblocking_acquires,
00093            (nonblocking_acquires > 0 ?
00094             successful_nonblocking_acquires * 100.0 / nonblocking_acquires : 0.0),
00095            unsuccessful_nonblocking_acquires,
00096            (nonblocking_acquires > 0 ?
00097             unsuccessful_nonblocking_acquires * 100.0 / nonblocking_acquires : 0.0), blocking_acquires);
00098     fflush(stdout);
00099   } else {
00100     if (!(total_acquires % 100)) {
00101       printf("Lock Stats (Alive):successful %d (%.2f%%), unsuccessful %d (%.2f%%) blocking %d \n",
00102              successful_nonblocking_acquires,
00103              (nonblocking_acquires > 0 ?
00104               successful_nonblocking_acquires * 100.0 / nonblocking_acquires : 0.0),
00105              unsuccessful_nonblocking_acquires,
00106              (nonblocking_acquires > 0 ?
00107               unsuccessful_nonblocking_acquires * 100.0 / nonblocking_acquires : 0.0), blocking_acquires);
00108       fflush(stdout);
00109     }
00110   }
00111 }
00112 #endif //LOCK_CONTENTION_PROFILING

Generated by  doxygen 1.7.1