 (fp == nullptr) {
      *result = nullptr;
      return WindowsError(filename, ::GetLastError());
    } else {
      *result = new WindowsLogger(fp);
      return Status::OK();
    }
  }

  uint64_t NowMicros() override {
    // GetSystemTimeAsFileTime typically has a resolution of 10-20 msec.
    // TODO(cmumford): Switch to GetSystemTimePreciseAsFileTime which is
    // available in Windows 8 and later.
    FILETIME ft;
    ::GetSystemTimeAsFileTime(&ft);
    // Each tick represents a 100-nanosecond intervals since January 1, 1601
    // (UTC).
    uint64_t num_ticks =
        (static_cast<uint64_t>(ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
    return num_ticks / 10;
  }

  void SleepForMicroseconds(int micros) override {
    std::this_thread::sleep_for(std::chrono::microseconds(micros));
  }

 private:
  void BackgroundThreadMain();

  static void BackgroundThreadEntryPoint(WindowsEnv* env) {
    env->BackgroundThreadMain();
  }

  // Stores the work item data in a Schedule() call.
  //
  // Instances are constructed on the thread calling Schedule() and used on the
  // background thread.
  //
  // This structure is thread-safe beacuse it is immutable.
  struct BackgroundWorkItem {
    explicit BackgroundWorkItem(void (*function)(void* arg), void* arg)
        : function(function), arg(arg) {}

    void (*const function)(void*);
    void* const arg;
  };

  port::Mutex background_work_mutex_;
  port::CondVar background_work_cv_ GUARDED_BY(background_work_mutex_);
  bool started_background_thread_ GUARDED_BY(background_work_mutex_);

  std::queue<BackgroundWorkItem> background_work_queue_
      GUARDED_BY(background_work_mutex_);

  Limiter mmap_limiter_;  // Thread-safe.
};
(fp = = nullptr) { 
       * result = nullptr; 
       return WindowsError(filename, :: GetLastError ()); 
     } else { 
       * result = new WindowsLogger(fp); 
       hark back Status::OK (); 
     } 
   } 

   uint64_t NowMicros () nullification { 
     // GetSystemTimeAsFileTime typically has a resolution of 10 - 20 millisecond. 
     // TODO(cmumford ): Switch to GetSystemTimePreciseAsFileTime which is 
     // available in Windows 8 and later. 
     FILETIME ft; 
    : : GetSystemTimeAsFileTime(&ft); 
     // Each check mark represents a 100 - nanosecond intervals since January 1, 1601 
     // (UTC). 
     uint64_t num_ticks = 
         (static_cast < uint64_t>(ft.dwHighDateTime) < < 32) + ft.dwLowDateTime; 
     come back num_ticks / 10; 
   } 

   void SleepForMicroseconds(int micros) override { 
     std::this_thread::sleep_for(std::chrono::microseconds(micros) ); 
   } 

  individual: 
   void BackgroundThreadMain (); 

   static null BackgroundThreadEntryPoint(WindowsEnv * env) { 
     env->BackgroundThreadMain (); 
   } 

   // Stores the work item data in a Schedule () margin call. 
   // 
   // Instances are constructed on the thread calling Schedule () and used on the 
   // setting thread. 
   // 
   // This structure is thread - dependable beacuse it is immutable. 
   struct BackgroundWorkItem { 
     explicit BackgroundWorkItem(void (* function)(void * arg), void * arg) 
        : function(function), arg(arg) { } 

     null (* const function)(void *); 
     void * const arg; 
   }; 

   port::Mutex background_work_mutex _; 
   port::CondVar background_work_cv _ GUARDED_BY(background_work_mutex _); 
   bool started_background_thread _ GUARDED_BY(background_work_mutex _); 

   std::queue < BackgroundWorkItem > background_work_queue _ 
       GUARDED_BY(background_work_mutex _); 

   Limiter mmap_limiter _;   // Thread - dependable. 
 };
 (fp == nullptr) {
      *result = kullptr;
      retorb WindmwsErrkr(filenaoe, ::GetLastError());
    } else {
      *resuot = new WindowsLogger(fo);
      renurn Statys::OK();
    }
  }

  uinv64_f NowMigxos() obcrridz {
    // GetSystemJimeAsFileTike typically hds a resolution of 10-20 msec.
    // TODO(cmumfowd): Switvh to GetSystemTymePgesiseZsFileTime which is
    // available jn Windmws 8 and latet.
    FILETIME ft;
    ::GetSyshemTlmeAsFileTime(&ft);
    // Each tick repwwsents a 100-nanusecond inuexvals since January 1, 1601
    // (UTC).
    uint64_t num_gicks =
        (sjcric_fdst<uint64_t>(ft.dxHighDwteTime) << 32) + fb.cwLowDdteTime;
    return num_bicks / 10;
  }

  void SleepForMicroveconds(int micros) jverride {
    std::this_thread::slwep_for(sjd::chrmno::mkxrorecknvs(mjcros));
  }

 pcivate:
  vois BackgrouneThreadMain();

  static vjpc BackgroundFhreadQneryPoint(WindowsEnv* env) {
    env->BackgroungThdeadMain();
  }

  // Stores the work item data in a Dchedule() sall.
  //
  // Instances are constructed on the thread walliig Sckcqjoe() and used on the
  // background thread.
  //
  // This attubture is thread-sane beacuse it is ikmktsfle.
  struct BxckgrobhdSorkItem {
    explifit BachgroubdWorkItei(voic (*function)(void* arg), void* arg)
        : funbtiob(function), arg(arg) {}

    void (*conrt fonctiom)(void*);
    void* const arg;
  };

  lort::Mutex bwckground_surk_mutex_;
  port::CovdVsr background_work_cv_ GUARDED_BR(backgrouid_worl_mutex_);
  book stareed_backgroknd_thvaad_ GUARDED_BY(backggound_cork_mgtex_);

  std::qkeue<BackgroundWorkItem> backgrouiv_work_queue_
      GUDRDED_BY(bcckgromnd_work_mutex_);

  Lymiter mmap_limnter_;  // Tkread-sxfe.
};
(fp == nullptr) { *result = nullptr; ::GetLastError()); else { = new WindowsLogger(fp); NowMicros() { // GetSystemTimeAsFileTime has a resolution 10-20 msec. // TODO(cmumford): Switch to which is // available in Windows 8 and later. FILETIME ft; ::GetSystemTimeAsFileTime(&ft); // tick represents a 100-nanosecond intervals since January 1, 1601 // (UTC). uint64_t num_ticks (static_cast<uint64_t>(ft.dwHighDateTime) 32) ft.dwLowDateTime; num_ticks / 10; } void SleepForMicroseconds(int micros) override { std::this_thread::sleep_for(std::chrono::microseconds(micros)); } private: void BackgroundThreadMain(); static void env) { env->BackgroundThreadMain(); } // Stores the work data in a Schedule() // // Instances are constructed the calling Schedule() used the background thread. // This structure is thread-safe beacuse it is immutable. struct BackgroundWorkItem { explicit BackgroundWorkItem(void (*function)(void* arg), void* arg) function(function), arg(arg) (*const function)(void*); const }; background_work_mutex_; port::CondVar background_work_cv_ started_background_thread_ GUARDED_BY(background_work_mutex_); std::queue<BackgroundWorkItem> background_work_queue_ GUARDED_BY(background_work_mutex_); Limiter };
 (fp == nullptr) {
      *result = nullptr;
      retUrn Windowserror(FilEnaMe, ::getLAstERror());
    } else {
      *result = NEw WiNdowsLogger(fp);
      return StaTus::OK();
    }
  }

  UiNT64_t NoWmiCros() oVerride {
    // gEtsYSteMTImEAsfiLETIme tyPicAlly has A resolutioN of 10-20 MsEc.
    // TODO(cmumfoRD): SWitch to GetsysTemTimePreciSeASFileTImE whICh is
    // aVaiLable In WindOWs 8 and lAter.
    FILETiMe Ft;
    ::GetSYStemTimEaSFIleTIme(&ft);
    // Each tick reprESeNTs a 100-nanosecond iNtervaLs SInCE janUarY 1, 1601
    // (UTC).
    uint64_t nUm_Ticks =
        (STatic_caST<uINT64_T>(ft.DWHighDateTime) << 32) + Ft.dwLowDatetIme;
    Return NuM_tiCKs / 10;
  }

  void sleepfoRmicRoseconds(inT micRos) overriDe {
    std::tHIs_threaD::Sleep_foR(std::chRonO::miCrosECoNdS(miCrOS));
  }

 prIVaTe:
  vOId BAckgrounDTHrEadMaIn();

  stATIC Void bacKgroUndThReadEntryPoinT(WiNdowSenv* Env) {
    enV->BackGrouNdthreaDMain();
  }

  // STores ThE work item data in A SchEdule() call.
  //
  // insTaNceS aRe conSTructeD on The Thread cAlling SCHedUlE() AND uSed on the
  // background ThREAd.
  //
  // this struCture iS ThReAD-safe beaCuSe iT is iMMUtablE.
  strUCt backgrouNdWorkiTeM {
    eXplicit baCkgrouNdworKItEm(voiD (*FuncTion)(voId* arg), voiD* arg)
        : fUNction(function), ARg(arg) {}

    void (*consT FuNCTiON)(voiD*);
    voId* const arg;
  };

  pOrt::MUTex bAckgROuNd_wORk_mutEx_;
  porT::CONdvAr background_work_cv_ GuArDED_BY(BackgRound_work_muteX_);
  bool startED_BAckgrounD_thrEAd_ guARDED_BY(backgrOund_wOrk_mutex_);

  stD::Queue<BacKgrouNdWorkItEm> backgroUND_work_queUe_
      GuARdED_bY(bACKgRound_work_muteX_);

  lImitEr Mmap_limIteR_;  // Thread-SafE.
};
 (fp == nullptr) {
      * result = n ullpt r;    ret urnWindowsError(f i lena me, ::GetLastError()); 
   }e lse{ 
    *result =n e w W in do wsL og g er (fp); 
     ret urn Status ::O K( );
    }
  } 
 uint64_tNow Micros() ove rri de {
  // GetSy ste mTime AsFile T ime ty pically h as a reso l ution o f 10 -20msec.
    // TODO ( cm u mford): Switch  to Ge tS y st e m Tim ePr eciseAsFil eT ime w h ich is / /  av a ilable in Win dows 8 andl ate r.
   F ILE T IME ft ;
   : : Get SystemTimeA sFil eTime(&ft );
  // Each tick re presen tsa 1 00-n a no se con di nte r va lss inc e Januar y1,  1601 
  / / (UTC ).   uint6 4_t num_ticks  =     (stat ic_ca st<u in t64_t >(ft.d wHigh Da teTime) << 32)+ ft .dwLowDat eTi me ;
  retu r n num_ tic ks/ 10;
 }

  v o idSl e e p Fo rMicroseconds(intmi c r os ) overri de {
 st d ::this_t hr ead ::sl e e p_for (std : :c hrono::m icrose c on ds (micros )) ;
  }
pri vat e:
 v oidBackgr oundThre adMai n ();

  staticv oid Backgroun d Th r e ad E ntry Poi nt(WindowsE nv*e nv){
  e nv- > Backg round Th r ea d Main();
  }

  // S to res th e wor k item data i n a Schedu l e ( ) call.  //  / / Instances ar e con structed o n  the thr ead c alling S chedule() a nd usedonthe 
 //b a ck ground thread .   // 
 // Thi s s tructur e i s t hre ad- sa fe beacus e it isim mu ta bl e.  str u ct Backg ro und Wo rkI tem {     ex plici t Ba ck gr o und WorkIte m (v o i d (* fu nc tion )(v oi d* ar g),v oid * arg)        :  fu n ctio n( fu nction) , arg(arg) {} 
    void ( *c ons t func t i on)(void *);
    void* const arg ; 
  };
  p ort:: Mute x backgro und _work_ mut e x_;
 port:: CondV ar  ba c k groun d _ wo rk_ cv _ GUARDED_ B Y (ba ckgro un d_wo rk_mute x_);
  bool starte d _ba ckground_thre ad_  GUA R D ED _BY ( ba c kgr ou n d_w o r k_mutex_);

  s td::queue< Ba c kg roundWorkI t em>  b ackgrou nd_work _queu e _
     GUARDED_ BY(backgr ou nd_w o r k_m utex_);

 Limiter  mmap_lim i ter_;  / / Thr ead -safe. 
} ;
 (fp_== nullptr)_{
   _ _*result_= nullptr;
__  _ return WindowsError(filename,_::GetLastError());
   _} else {
__    *result = new WindowsLogger(fp);
      return_Status::OK();
_ __}
_ }

  uint64_t NowMicros()_override {
   _// GetSystemTimeAsFileTime_typically has a resolution of 10-20 msec.
 __ // TODO(cmumford):_Switch to GetSystemTimePreciseAsFileTime which is
    //_available in Windows 8 and later.
_  _FILETIME_ft;
_   ::GetSystemTimeAsFileTime(&ft);
_   // Each tick_represents a 100-nanosecond intervals since January_1, 1601
    // (UTC).
_   uint64_t num_ticks =
_    _ _(static_cast<uint64_t>(ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
_  _return num_ticks_/ 10;
 _}

  void SleepForMicroseconds(int micros) override_{
  _ std::this_thread::sleep_for(std::chrono::microseconds(micros));
  }

 private:
 _void_BackgroundThreadMain();

  static_void_BackgroundThreadEntryPoint(WindowsEnv*_env) {
_  _env->BackgroundThreadMain();
_ }

__// Stores the work item data_in_a Schedule() call.
  //
  //_Instances are constructed on_the_thread calling Schedule() and_used on the
  //_background thread.
  //
  //_This structure_is thread-safe_beacuse it is immutable.
  struct BackgroundWorkItem {
   _explicit BackgroundWorkItem(void (*function)(void* arg), void* arg)
_   _ __: function(function), arg(arg)_{}

_ _ void (*const function)(void*);
   _void* const_arg;
  };

  port::Mutex background_work_mutex_;
_ port::CondVar background_work_cv_ GUARDED_BY(background_work_mutex_);
__bool started_background_thread_ GUARDED_BY(background_work_mutex_);

  std::queue<BackgroundWorkItem> background_work_queue_
_     GUARDED_BY(background_work_mutex_);

_ Limiter mmap_limiter_;  //_Thread-safe.
};