X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FLogging.h;h=404ca80e4d83dc093904be927a1f27fbbf31766d;hb=d2c8a36b6b96eea44e9e92fa6946d607f8530b07;hp=0c34de24b8e18511ed582092e85bfd01194c7772;hpb=0a52fd7bf776aad7b217f16039a6d12f673c9f69;p=folly.git diff --git a/folly/Logging.h b/folly/Logging.h index 0c34de24..404ca80e 100644 --- a/folly/Logging.h +++ b/folly/Logging.h @@ -1,5 +1,5 @@ /* - * Copyright 2014 Facebook, Inc. + * Copyright 2016 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef FOLLY_LOGGING_H_ -#define FOLLY_LOGGING_H_ +#pragma once #include #include @@ -31,24 +30,26 @@ * * The implementation uses for statements to introduce variables in * a nice way that doesn't mess surrounding statements. It is thread - * safe. + * safe. Non-positive intervals will always log. */ #define FB_LOG_EVERY_MS(severity, milli_interval) \ - for (bool FB_LEM_once = true; FB_LEM_once; ) \ + for (decltype(milli_interval) FB_LEM_once = 1, \ + FB_LEM_interval = (milli_interval); \ + FB_LEM_once; ) \ for (::std::chrono::milliseconds::rep FB_LEM_prev, FB_LEM_now = \ + FB_LEM_interval <= 0 ? 0 : \ ::std::chrono::duration_cast< ::std::chrono::milliseconds>( \ ::std::chrono::system_clock::now().time_since_epoch() \ ).count(); \ FB_LEM_once; ) \ for (static ::std::atomic< ::std::chrono::milliseconds::rep> \ - FB_LEM_hist; FB_LEM_once; FB_LEM_once = false) \ - if (FB_LEM_now - (FB_LEM_prev = \ - FB_LEM_hist.load(std::memory_order_acquire)) < \ - milli_interval || \ - !FB_LEM_hist.compare_exchange_strong(FB_LEM_prev, FB_LEM_now)) { \ + FB_LEM_hist; FB_LEM_once; FB_LEM_once = 0) \ + if (FB_LEM_interval > 0 && \ + (FB_LEM_now - (FB_LEM_prev = \ + FB_LEM_hist.load(std::memory_order_acquire)) < \ + FB_LEM_interval || \ + !FB_LEM_hist.compare_exchange_strong(FB_LEM_prev,FB_LEM_now))) {\ } else \ LOG(severity) #endif - -#endif // FOLLY_LOGGING_H_