This is an automated email from the ASF dual-hosted git repository. jpeach pushed a commit to branch master in repository https://git-dual.apache.org/repos/asf/trafficserver.git
commit f6726744568401a766c4748c95f799a071824ae9 Author: James Peach <[email protected]> AuthorDate: Thu Apr 21 21:02:58 2016 -0700 TS-4370: Refactor and rename SrcLoc. In preparation for using SrcLoc outside of diaags, split it into its own source file with no dependencies, and rename it to SourceLocation. --- iocore/eventsystem/I_Lock.h | 40 +++++++++++++++--------------- iocore/eventsystem/Lock.cc | 6 ++--- iocore/net/P_SSLUtils.h | 10 ++++---- iocore/net/SSLUtils.cc | 2 +- lib/ts/Diags.cc | 40 +++--------------------------- lib/ts/Diags.h | 46 +++------------------------------- lib/ts/Makefile.am | 2 ++ lib/ts/SourceLocation.cc | 54 ++++++++++++++++++++++++++++++++++++++++ lib/ts/SourceLocation.h | 60 +++++++++++++++++++++++++++++++++++++++++++++ proxy/shared/Error.cc | 2 +- 10 files changed, 154 insertions(+), 108 deletions(-) diff --git a/iocore/eventsystem/I_Lock.h b/iocore/eventsystem/I_Lock.h index e90d1bf..5f4cfc5 100644 --- a/iocore/eventsystem/I_Lock.h +++ b/iocore/eventsystem/I_Lock.h @@ -50,7 +50,7 @@ */ #ifdef DEBUG -#define SCOPED_MUTEX_LOCK(_l, _m, _t) MutexLock _l(DiagsMakeLocation(), NULL, _m, _t) +#define SCOPED_MUTEX_LOCK(_l, _m, _t) MutexLock _l(MakeSourceLocation(), NULL, _m, _t) #else #define SCOPED_MUTEX_LOCK(_l, _m, _t) MutexLock _l(_m, _t) #endif // DEBUG @@ -69,7 +69,7 @@ @param _t The current EThread executing your code. */ -#define MUTEX_TRY_LOCK(_l, _m, _t) MutexTryLock _l(DiagsMakeLocation(), (char *)NULL, _m, _t) +#define MUTEX_TRY_LOCK(_l, _m, _t) MutexTryLock _l(MakeSourceLocation(), (char *)NULL, _m, _t) /** Attempts to acquire the lock to the ProxyMutex. @@ -85,7 +85,7 @@ @param _sc The number of attempts or spin count. It must be a positive value. */ -#define MUTEX_TRY_LOCK_SPIN(_l, _m, _t, _sc) MutexTryLock _l(DiagsMakeLocation(), (char *)NULL, _m, _t, _sc) +#define MUTEX_TRY_LOCK_SPIN(_l, _m, _t, _sc) MutexTryLock _l(MakeSourceLocation(), (char *)NULL, _m, _t, _sc) /** Attempts to acquire the lock to the ProxyMutex. @@ -102,7 +102,7 @@ */ -#define MUTEX_TRY_LOCK_FOR(_l, _m, _t, _c) MutexTryLock _l(DiagsMakeLocation(), NULL, _m, _t) +#define MUTEX_TRY_LOCK_FOR(_l, _m, _t, _c) MutexTryLock _l(MakeSourceLocation(), NULL, _m, _t) #else // DEBUG #define MUTEX_TRY_LOCK(_l, _m, _t) MutexTryLock _l(_m, _t) #define MUTEX_TRY_LOCK_SPIN(_l, _m, _t, _sc) MutexTryLock _l(_m, _t, _sc) @@ -126,9 +126,9 @@ ///////////////////////////////////// // DEPRECATED DEPRECATED DEPRECATED #ifdef DEBUG -#define MUTEX_TAKE_TRY_LOCK(_m, _t) Mutex_trylock(DiagsMakeLocation(), (char *)NULL, _m, _t) -#define MUTEX_TAKE_TRY_LOCK_FOR(_m, _t, _c) Mutex_trylock(DiagsMakeLocation(), (char *)NULL, _m, _t) -#define MUTEX_TAKE_TRY_LOCK_FOR_SPIN(_m, _t, _c, _sc) Mutex_trylock_spin(DiagsMakeLocation(), NULL, _m, _t, _sc) +#define MUTEX_TAKE_TRY_LOCK(_m, _t) Mutex_trylock(MakeSourceLocation(), (char *)NULL, _m, _t) +#define MUTEX_TAKE_TRY_LOCK_FOR(_m, _t, _c) Mutex_trylock(MakeSourceLocation(), (char *)NULL, _m, _t) +#define MUTEX_TAKE_TRY_LOCK_FOR_SPIN(_m, _t, _c, _sc) Mutex_trylock_spin(MakeSourceLocation(), NULL, _m, _t, _sc) #else #define MUTEX_TAKE_TRY_LOCK(_m, _t) Mutex_trylock(_m, _t) #define MUTEX_TAKE_TRY_LOCK_FOR(_m, _t, _c) Mutex_trylock(_m, _t) @@ -136,8 +136,8 @@ #endif #ifdef DEBUG -#define MUTEX_TAKE_LOCK(_m, _t) Mutex_lock(DiagsMakeLocation(), (char *)NULL, _m, _t) -#define MUTEX_TAKE_LOCK_FOR(_m, _t, _c) Mutex_lock(DiagsMakeLocation(), NULL, _m, _t) +#define MUTEX_TAKE_LOCK(_m, _t) Mutex_lock(MakeSourceLocation(), (char *)NULL, _m, _t) +#define MUTEX_TAKE_LOCK_FOR(_m, _t, _c) Mutex_lock(MakeSourceLocation(), NULL, _m, _t) #else #define MUTEX_TAKE_LOCK(_m, _t) Mutex_lock(_m, _t) #define MUTEX_TAKE_LOCK_FOR(_m, _t, _c) Mutex_lock(_m, _t) @@ -152,9 +152,9 @@ typedef EThread *EThreadPtr; typedef volatile EThreadPtr VolatileEThreadPtr; #if DEBUG -inkcoreapi extern void lock_waiting(const SrcLoc &, const char *handler); -inkcoreapi extern void lock_holding(const SrcLoc &, const char *handler); -inkcoreapi extern void lock_taken(const SrcLoc &, const char *handler); +inkcoreapi extern void lock_waiting(const SourceLocation &, const char *handler); +inkcoreapi extern void lock_holding(const SourceLocation &, const char *handler); +inkcoreapi extern void lock_taken(const SourceLocation &, const char *handler); #endif /** @@ -209,7 +209,7 @@ public: #ifdef DEBUG ink_hrtime hold_time; - SrcLoc srcloc; + SourceLocation srcloc; const char *handler; #ifdef MAX_LOCK_TAKEN @@ -280,7 +280,7 @@ extern inkcoreapi ClassAllocator<ProxyMutex> mutexAllocator; inline bool Mutex_trylock( #ifdef DEBUG - const SrcLoc &location, const char *ahandler, + const SourceLocation &location, const char *ahandler, #endif ProxyMutex *m, EThread *t) { @@ -324,7 +324,7 @@ Mutex_trylock( inline bool Mutex_trylock_spin( #ifdef DEBUG - const SrcLoc &location, const char *ahandler, + const SourceLocation &location, const char *ahandler, #endif ProxyMutex *m, EThread *t, int spincnt = 1) { @@ -373,7 +373,7 @@ Mutex_trylock_spin( inline int Mutex_lock( #ifdef DEBUG - const SrcLoc &location, const char *ahandler, + const SourceLocation &location, const char *ahandler, #endif ProxyMutex *m, EThread *t) { @@ -416,7 +416,7 @@ Mutex_unlock(ProxyMutex *m, EThread *t) if (m->taken > MAX_LOCK_TAKEN) lock_taken(m->srcloc, m->handler); #endif // MAX_LOCK_TAKEN - m->srcloc = SrcLoc(NULL, NULL, 0); + m->srcloc = SourceLocation(NULL, NULL, 0); m->handler = NULL; #endif // DEBUG ink_assert(m->thread_holding); @@ -436,7 +436,7 @@ private: public: MutexLock( #ifdef DEBUG - const SrcLoc &location, const char *ahandler, + const SourceLocation &location, const char *ahandler, #endif // DEBUG ProxyMutex *am, EThread *t) : m(am) @@ -462,7 +462,7 @@ private: public: MutexTryLock( #ifdef DEBUG - const SrcLoc &location, const char *ahandler, + const SourceLocation &location, const char *ahandler, #endif // DEBUG ProxyMutex *am, EThread *t) : m(am) @@ -476,7 +476,7 @@ public: MutexTryLock( #ifdef DEBUG - const SrcLoc &location, const char *ahandler, + const SourceLocation &location, const char *ahandler, #endif // DEBUG ProxyMutex *am, EThread *t, int sp) : m(am) diff --git a/iocore/eventsystem/Lock.cc b/iocore/eventsystem/Lock.cc index 098884c..401532a 100644 --- a/iocore/eventsystem/Lock.cc +++ b/iocore/eventsystem/Lock.cc @@ -34,7 +34,7 @@ ClassAllocator<ProxyMutex> mutexAllocator("mutexAllocator"); void -lock_waiting(const SrcLoc &srcloc, const char *handler) +lock_waiting(const SourceLocation &srcloc, const char *handler) { if (is_diags_on("locks")) { char buf[128]; @@ -43,7 +43,7 @@ lock_waiting(const SrcLoc &srcloc, const char *handler) } void -lock_holding(const SrcLoc &srcloc, const char *handler) +lock_holding(const SourceLocation &srcloc, const char *handler) { if (is_diags_on("locks")) { char buf[128]; @@ -52,7 +52,7 @@ lock_holding(const SrcLoc &srcloc, const char *handler) } void -lock_taken(const SrcLoc &srcloc, const char *handler) +lock_taken(const SourceLocation &srcloc, const char *handler) { if (is_diags_on("locks")) { char buf[128]; diff --git a/iocore/net/P_SSLUtils.h b/iocore/net/P_SSLUtils.h index f890190..9a15426 100644 --- a/iocore/net/P_SSLUtils.h +++ b/iocore/net/P_SSLUtils.h @@ -133,11 +133,11 @@ ssl_error_t SSLAccept(SSL *ssl); ssl_error_t SSLConnect(SSL *ssl); // Log an SSL error. -#define SSLError(fmt, ...) SSLDiagnostic(DiagsMakeLocation(), false, NULL, fmt, ##__VA_ARGS__) -#define SSLErrorVC(vc, fmt, ...) SSLDiagnostic(DiagsMakeLocation(), false, (vc), fmt, ##__VA_ARGS__) +#define SSLError(fmt, ...) SSLDiagnostic(MakeSourceLocation(), false, NULL, fmt, ##__VA_ARGS__) +#define SSLErrorVC(vc, fmt, ...) SSLDiagnostic(MakeSourceLocation(), false, (vc), fmt, ##__VA_ARGS__) // Log a SSL diagnostic using the "ssl" diagnostic tag. -#define SSLDebug(fmt, ...) SSLDiagnostic(DiagsMakeLocation(), true, NULL, fmt, ##__VA_ARGS__) -#define SSLDebugVC(vc, fmt, ...) SSLDiagnostic(DiagsMakeLocation(), true, (vc), fmt, ##__VA_ARGS__) +#define SSLDebug(fmt, ...) SSLDiagnostic(MakeSourceLocation(), true, NULL, fmt, ##__VA_ARGS__) +#define SSLDebugVC(vc, fmt, ...) SSLDiagnostic(MakeSourceLocation(), true, (vc), fmt, ##__VA_ARGS__) #define SSL_CLR_ERR_INCR_DYN_STAT(vc, x, fmt, ...) \ do { \ @@ -145,7 +145,7 @@ ssl_error_t SSLConnect(SSL *ssl); RecIncrRawStat(ssl_rsb, NULL, (int)x, 1); \ } while (0) -void SSLDiagnostic(const SrcLoc &loc, bool debug, SSLNetVConnection *vc, const char *fmt, ...) TS_PRINTFLIKE(4, 5); +void SSLDiagnostic(const SourceLocation &loc, bool debug, SSLNetVConnection *vc, const char *fmt, ...) TS_PRINTFLIKE(4, 5); // Return a static string name for a SSL_ERROR constant. const char *SSLErrorName(int ssl_error); diff --git a/iocore/net/SSLUtils.cc b/iocore/net/SSLUtils.cc index 0c419b9..96af263 100644 --- a/iocore/net/SSLUtils.cc +++ b/iocore/net/SSLUtils.cc @@ -1116,7 +1116,7 @@ increment_ssl_server_error(unsigned long err) } void -SSLDiagnostic(const SrcLoc &loc, bool debug, SSLNetVConnection *vc, const char *fmt, ...) +SSLDiagnostic(const SourceLocation &loc, bool debug, SSLNetVConnection *vc, const char *fmt, ...) { unsigned long l; char buf[256]; diff --git a/lib/ts/Diags.cc b/lib/ts/Diags.cc index f5543bb..3c6accd 100644 --- a/lib/ts/Diags.cc +++ b/lib/ts/Diags.cc @@ -67,39 +67,6 @@ vprintline(FILE *fp, char (&buffer)[Size], va_list ap) ////////////////////////////////////////////////////////////////////////////// // -// char *SrcLoc::str(char *buf, int buflen) -// -// This method takes a SrcLoc source location data structure and -// converts it to a human-readable representation, in the buffer <buf> -// with length <buflen>. The buffer will always be NUL-terminated, and -// must always have a length of at least 1. The buffer address is -// returned on success. The routine will only fail if the SrcLoc is -// not valid, or the buflen is less than 1. -// -////////////////////////////////////////////////////////////////////////////// - -char * -SrcLoc::str(char *buf, int buflen) const -{ - const char *shortname; - - if (!this->valid() || buflen < 1) - return (NULL); - - shortname = strrchr(file, '/'); - shortname = shortname ? (shortname + 1) : file; - - if (func != NULL) { - snprintf(buf, buflen, "%s:%d (%s)", shortname, line, func); - } else { - snprintf(buf, buflen, "%s:%d", shortname, line); - } - buf[buflen - 1] = NUL; - return (buf); -} - -////////////////////////////////////////////////////////////////////////////// -// // Diags::Diags(char *bdt, char *bat) // // This is the constructor for the Diags class. The constructor takes @@ -229,7 +196,8 @@ Diags::~Diags() ////////////////////////////////////////////////////////////////////////////// void -Diags::print_va(const char *debug_tag, DiagsLevel diags_level, const SrcLoc *loc, const char *format_string, va_list ap) const +Diags::print_va(const char *debug_tag, DiagsLevel diags_level, const SourceLocation *loc, const char *format_string, + va_list ap) const { struct timeval tp; const char *s; @@ -545,7 +513,7 @@ Diags::log(const char *tag, DiagsLevel level, const char *file, const char *func va_list ap; va_start(ap, format_string); if (show_location) { - SrcLoc lp(file, func, line); + SourceLocation lp(file, func, line); print_va(tag, level, &lp, format_string, ap); } else { print_va(tag, level, NULL, format_string, ap); @@ -563,7 +531,7 @@ Diags::error_va(DiagsLevel level, const char *file, const char *func, const int } if (show_location) { - SrcLoc lp(file, func, line); + SourceLocation lp(file, func, line); print_va(NULL, level, &lp, format_string, ap); } else { print_va(NULL, level, NULL, format_string, ap); diff --git a/lib/ts/Diags.h b/lib/ts/Diags.h index fc01fc7..0d55e19 100644 --- a/lib/ts/Diags.h +++ b/lib/ts/Diags.h @@ -42,6 +42,7 @@ #include "ContFlags.h" #include "ink_inet.h" #include "BaseLogFile.h" +#include "SourceLocation.h" #define DIAGS_MAGIC 0x12345678 #define BYTES_IN_MB 1000000 @@ -92,45 +93,6 @@ struct DiagsConfigState { ////////////////////////////////////////////////////////////////////////////// // -// class SrcLoc -// -// The SrcLoc class wraps up a source code location, including file -// name, function name, and line number, and contains a method to -// format the result into a string buffer. -// -////////////////////////////////////////////////////////////////////////////// - -#define DiagsMakeLocation() SrcLoc(__FILE__, __FUNCTION__, __LINE__) - -class SrcLoc -{ -public: - const char *file; - const char *func; - int line; - - bool - valid() const - { - return file && line; - } - - SrcLoc(const SrcLoc &rhs) : file(rhs.file), func(rhs.func), line(rhs.line) {} - SrcLoc(const char *_file, const char *_func, int _line) : file(_file), func(_func), line(_line) {} - SrcLoc & - operator=(const SrcLoc &rhs) - { - this->file = rhs.file; - this->func = rhs.func; - this->line = rhs.line; - return *this; - } - - char *str(char *buf, int buflen) const; -}; - -////////////////////////////////////////////////////////////////////////////// -// // class Diags // // The Diags class is used for global configuration of the run-time @@ -194,7 +156,7 @@ public: const char *level_name(DiagsLevel dl) const; - inkcoreapi void print_va(const char *tag, DiagsLevel dl, const SrcLoc *loc, const char *format_string, va_list ap) const; + inkcoreapi void print_va(const char *tag, DiagsLevel dl, const SourceLocation *loc, const char *format_string, va_list ap) const; ////////////////////////////// // user printing interfaces // @@ -207,7 +169,7 @@ public: va_list ap; va_start(ap, format_string); if (show_location) { - SrcLoc lp(file, func, line); + SourceLocation lp(file, func, line); print_va(tag, dl, &lp, format_string, ap); } else { print_va(tag, dl, NULL, format_string, ap); @@ -221,7 +183,7 @@ public: /////////////////////////////////////////////////////////////////////// void - log_va(const char *tag, DiagsLevel dl, const SrcLoc *loc, const char *format_string, va_list ap) + log_va(const char *tag, DiagsLevel dl, const SourceLocation *loc, const char *format_string, va_list ap) { if (!on(tag)) return; diff --git a/lib/ts/Makefile.am b/lib/ts/Makefile.am index 71ae96e..cb0e076 100644 --- a/lib/ts/Makefile.am +++ b/lib/ts/Makefile.am @@ -53,6 +53,8 @@ libtsutil_la_SOURCES = \ ContFlags.h \ Diags.cc \ Diags.h \ + SourceLocation.h \ + SourceLocation.cc \ DynArray.h \ EventNotify.cc \ EventNotify.h \ diff --git a/lib/ts/SourceLocation.cc b/lib/ts/SourceLocation.cc new file mode 100644 index 0000000..7e7ee0f --- /dev/null +++ b/lib/ts/SourceLocation.cc @@ -0,0 +1,54 @@ +/** @file + * + * A brief file description + * + * @section license License + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "SourceLocation.h" +#include "ink_defs.h" +#include <stdio.h> +#include <string.h> + +// This method takes a SourceLocation source location data structure and +// converts it to a human-readable representation, in the buffer <buf> +// with length <buflen>. The buffer will always be NUL-terminated, and +// must always have a length of at least 1. The buffer address is +// returned on success. The routine will only fail if the SourceLocation is +// not valid, or the buflen is less than 1. + +char * +SourceLocation::str(char *buf, int buflen) const +{ + const char *shortname; + + if (!this->valid() || buflen < 1) + return (NULL); + + shortname = strrchr(file, '/'); + shortname = shortname ? (shortname + 1) : file; + + if (func != NULL) { + snprintf(buf, buflen, "%s:%d (%s)", shortname, line, func); + } else { + snprintf(buf, buflen, "%s:%d", shortname, line); + } + buf[buflen - 1] = NUL; + return (buf); +} diff --git a/lib/ts/SourceLocation.h b/lib/ts/SourceLocation.h new file mode 100644 index 0000000..cda2eeb --- /dev/null +++ b/lib/ts/SourceLocation.h @@ -0,0 +1,60 @@ +/** @file + * + * A brief file description + * + * @section license License + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SOURCELOCATION_H_88F6E38C_ACBB_4EFE_8819_71FCB162AE9B +#define SOURCELOCATION_H_88F6E38C_ACBB_4EFE_8819_71FCB162AE9B + +// The SourceLocation class wraps up a source code location, including +// file name, function name, and line number, and contains a method to +// format the result into a string buffer. + +#define MakeSourceLocation() SourceLocation(__FILE__, __FUNCTION__, __LINE__) + +class SourceLocation +{ +public: + const char *file; + const char *func; + int line; + + bool + valid() const + { + return file && line; + } + + SourceLocation(const SourceLocation &rhs) : file(rhs.file), func(rhs.func), line(rhs.line) {} + SourceLocation(const char *_file, const char *_func, int _line) : file(_file), func(_func), line(_line) {} + SourceLocation & + operator=(const SourceLocation &rhs) + { + this->file = rhs.file; + this->func = rhs.func; + this->line = rhs.line; + return *this; + } + + char *str(char *buf, int buflen) const; +}; + +#endif /* SOURCELOCATION_H_88F6E38C_ACBB_4EFE_8819_71FCB162AE9B */ diff --git a/proxy/shared/Error.cc b/proxy/shared/Error.cc index cb44d12..265b7c9 100644 --- a/proxy/shared/Error.cc +++ b/proxy/shared/Error.cc @@ -54,7 +54,7 @@ ErrorClass::operator()(const char *aformat_string, ...) void ErrorClass::raise(va_list ap, const char * /* prefix ATS_UNUSED */) { - SrcLoc loc(filename, function_name, line_number); + SourceLocation loc(filename, function_name, line_number); diags->print_va(NULL, DL_Fatal, &loc, format_string, ap); } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
