15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met: 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * documentation and/or other materials provided with the distribution. 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#ifndef SharedTimer_h 271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#define SharedTimer_h 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/PlatformExport.h" 307757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch#include "wtf/FastAllocBase.h" 317757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch#include "wtf/Noncopyable.h" 325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 33c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)// Each thread has its own single instance of shared timer, which implements this interface. 361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)// This instance is shared by all timers in the thread. 371e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)// Not intended to be used directly; use the Timer class instead. 381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)class PLATFORM_EXPORT SharedTimer { 391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) WTF_MAKE_NONCOPYABLE(SharedTimer); WTF_MAKE_FAST_ALLOCATED; 401e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)public: 411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) SharedTimer() { } 421e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) virtual ~SharedTimer() {} 431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) virtual void setFiredFunction(void (*)()) = 0; 441e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 451e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) // The fire interval is in seconds relative to the current monotonic clock time. 461e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) virtual void setFireInterval(double) = 0; 471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) virtual void stop() = 0; 481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}; 491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)PLATFORM_EXPORT void setSharedTimerFiredFunction(void (*)()); 521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)PLATFORM_EXPORT void setSharedTimerFireInterval(double); 531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)PLATFORM_EXPORT void stopSharedTimer(); 541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)class PLATFORM_EXPORT MainThreadSharedTimer : public SharedTimer { 565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public: 5709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) virtual void setFiredFunction(void (*function)()) OVERRIDE 581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) { 591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) setSharedTimerFiredFunction(function); 601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) } 611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 6209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) virtual void setFireInterval(double interval) OVERRIDE 631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) { 641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) setSharedTimerFireInterval(interval); 651e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) } 661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 6709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) virtual void stop() OVERRIDE 681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) { 691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) stopSharedTimer(); 701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) } 715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}; 725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 73c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#endif // SharedTimer_h 76