Tree @upstream/1.13.1651.102 (Download .tar.gz)
- ..
- protobuf
- android_jni_mock.cc
- android_jni_mock.h
- android_jni_proxy.cc
- android_jni_proxy.h
- android_jni_proxy_test.cc
- android_util.cc
- android_util.h
- android_util_test.cc
- base.gyp
- base.h
- base_test.gyp
- bitarray.h
- bitarray_test.cc
- clock_mock.cc
- clock_mock.h
- clock_mock_test.cc
- codegen_bytearray_stream.h
- codegen_bytearray_stream_test.cc
- compiler_specific.h
- config_file_stream.cc
- config_file_stream.h
- config_file_stream_test.cc
- const.h
- coordinates.h
- cpu_stats.cc
- cpu_stats.h
- cpu_stats_main.cc
- cpu_stats_test.cc
- crash_report_handler.cc
- crash_report_handler.h
- crash_report_handler_mac.mm
- crash_report_util.cc
- crash_report_util.h
- crash_report_util_test.cc
- debug.cc
- debug.h
- encryptor.cc
- encryptor.h
- encryptor_main.cc
- encryptor_test.cc
- file_stream.cc
- file_stream.h
- file_util.cc
- file_util.h
- file_util_test.cc
- flags.cc
- flags.h
- flags_test.cc
- freelist.h
- gen_character_set.py
- gen_config_file_stream_data.py
- hash.cc
- hash_tables.h
- hash_tables_test.cc
- iconv.cc
- init.cc
- init.h
- init_test.cc
- iterator_adapter.h
- iterator_adapter_test.cc
- japanese_util_rule.h
- linked_ptr.h
- logging.cc
- logging.h
- logging_test.cc
- mac_process.h
- mac_process.mm
- mac_util.h
- mac_util.mm
- mac_util_main.cc
- mac_util_test.mm
- mmap.cc
- mmap.h
- mmap_test.cc
- multifile.cc
- multifile.h
- multifile_test.cc
- mutex.cc
- mutex.h
- mutex_test.cc
- namespace.h
- number_util.cc
- number_util.h
- number_util_test.cc
- openssl_config.sh
- password_manager.cc
- password_manager.h
- password_manager_main.cc
- password_manager_test.cc
- pepper_file_system_mock.cc
- pepper_file_system_mock.h
- pepper_file_util.cc
- pepper_file_util.h
- pepper_scoped_obj.h
- port.h
- process.cc
- process.h
- process_main.cc
- process_mutex.cc
- process_mutex.h
- process_mutex_main.cc
- process_mutex_test.cc
- run_level.cc
- run_level.h
- run_level_main.cc
- scheduler.cc
- scheduler.h
- scheduler_stub.cc
- scheduler_stub.h
- scheduler_stub_test.cc
- scheduler_test.cc
- scoped_cftyperef.h
- scoped_handle.cc
- scoped_handle.h
- scoped_nsobject.h
- scoped_ptr.h
- singleton.cc
- singleton.h
- singleton_test.cc
- stl_util.h
- stl_util_test.cc
- stopwatch.cc
- stopwatch.h
- stopwatch_main.cc
- stopwatch_test.cc
- string_piece.cc
- string_piece.h
- string_piece_test.cc
- system_util.cc
- system_util.h
- system_util_test.cc
- task_manager.cc
- task_manager.h
- task_manager_test.cc
- task_runner.cc
- task_runner.h
- task_runner_test.cc
- task_token.cc
- task_token.h
- task_token_test.cc
- text_converter.cc
- text_converter.h
- text_converter_compiler.cc
- text_normalizer.cc
- text_normalizer.h
- text_normalizer_test.cc
- thread.cc
- thread.h
- thread_annotations.h
- thread_test.cc
- timer.cc
- timer.h
- timer_test.cc
- trie.h
- trie_test.cc
- unnamed_event.cc
- unnamed_event.h
- unnamed_event_test.cc
- update_checker.cc
- update_checker.h
- update_util.cc
- update_util.h
- update_util_test.cc
- url.cc
- url.h
- url_test.cc
- util.cc
- util.h
- util_test.cc
- version.cc
- version.h
- version_def_template.h
- version_test.cc
- win_api_test_helper.cc
- win_api_test_helper.h
- win_api_test_helper_test.cc
- win_font_test_helper.cc
- win_font_test_helper.h
- win_sandbox.cc
- win_sandbox.h
- win_sandbox_test.cc
- win_util.cc
- win_util.h
- winmain.h
timer.cc @upstream/1.13.1651.102 — raw · history · blame
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | // Copyright 2010-2014, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "base/timer.h" #include "base/logging.h" #include "base/thread.h" #include "base/unnamed_event.h" #include "base/util.h" namespace mozc { class Timer::TimerThread : public Thread { public: TimerThread(uint32 due_time, uint32 interval, Timer *timer) : Thread(), due_time_(due_time), interval_(interval), timer_(timer), event_(new UnnamedEvent) {} virtual ~TimerThread() { SignalQuit(); Join(); } virtual void Run() { if (event_->Wait(due_time_)) { VLOG(1) << "Received notification event"; return; } VLOG(2) << "call TimerCallback()"; timer_->TimerCallback(); if (interval_ == 0) { VLOG(2) << "Run() end"; return; } else { while (true) { if (event_->Wait(interval_)) { VLOG(1) << "Received notification event"; return; } VLOG(2) << "call TimerCallback()"; timer_->TimerCallback(); } } } void SignalQuit() { const bool result = event_->Notify(); DCHECK(result); } private: uint32 due_time_; uint32 interval_; Timer *timer_; scoped_ptr<UnnamedEvent> event_; DISALLOW_COPY_AND_ASSIGN(TimerThread); }; void Timer::TimerCallback() { num_signaled_++; Signaled(); } bool Timer::Start(uint32 due_time, uint32 interval) { VLOG(1) << "Starting " << due_time << " " << interval; // Note: We can simply destroy |*timer_thread_.get()| since // TimerThread::~TimerThread internally joins its background thread. timer_thread_.reset(new TimerThread(due_time, interval, this)); timer_thread_->Start(); return true; } void Timer::Stop() { // Note: We can simply destroy |*timer_thread_.get()| since // TimerThread::~TimerThread internally joins its background thread. timer_thread_.reset(NULL); } Timer::Timer() : num_signaled_(0) {} Timer::~Timer() { Stop(); } void Timer::Signaled() { // Note: This code can be called back even if a subclass overrides this // method when the main thread reached to Timer::~Timer. Do not make this // method pure-virtual. } } // namespace mozc |