timer-generic.cpp revision d428342802b081b076970ddb499d215b79f087cc
f0e0bfede101cfa5fbfb4ffe85a839033657b5d7Allen Rabinovich * IPRT - Timers, Generic.
6e847ed42c6e59e53bca347d80876b6ecb5a60f7Allen Rabinovich * Copyright (C) 2006-2007 Sun Microsystems, Inc.
21257820ee962f4f2275b39088c43fcfd76f7fdeAllen Rabinovich * This file is part of VirtualBox Open Source Edition (OSE), as
f0e0bfede101cfa5fbfb4ffe85a839033657b5d7Allen Rabinovich * available from http://www.virtualbox.org. This file is free software;
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * you can redistribute it and/or modify it under the terms of the GNU
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * General Public License (GPL) as published by the Free Software
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * Foundation, in version 2 as it comes in the "COPYING" file of the
87fff29257e74dac31f23eac9e31c028a551057fAllen Rabinovich * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * The contents of this file may alternatively be used under the terms
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * of the Common Development and Distribution License Version 1.0
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * VirtualBox OSE distribution, in which case the provisions of the
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * CDDL are applicable instead of those of the GPL.
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * You may elect to license modified versions of this file under the
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * terms and conditions of either the GPL or the CDDL or both.
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * Clara, CA 95054 USA or visit http://www.sun.com if you need
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * additional information or have any questions.
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich/*******************************************************************************
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich* Header Files *
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich*******************************************************************************/
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich/*******************************************************************************
21257820ee962f4f2275b39088c43fcfd76f7fdeAllen Rabinovich* Structures and Typedefs *
21257820ee962f4f2275b39088c43fcfd76f7fdeAllen Rabinovich*******************************************************************************/
21257820ee962f4f2275b39088c43fcfd76f7fdeAllen Rabinovich * The internal representation of a timer handle.
21257820ee962f4f2275b39088c43fcfd76f7fdeAllen Rabinovich * This is RTTIMER_MAGIC, but changes to something else before the timer
21257820ee962f4f2275b39088c43fcfd76f7fdeAllen Rabinovich * is destroyed to indicate clearly that thread should exit. */
21257820ee962f4f2275b39088c43fcfd76f7fdeAllen Rabinovich /** Flag indicating the the timer is suspended. */
21257820ee962f4f2275b39088c43fcfd76f7fdeAllen Rabinovich /** Flag indicating that the timer has been destroyed. */
f0e0bfede101cfa5fbfb4ffe85a839033657b5d7Allen Rabinovich /** Callback. */
21257820ee962f4f2275b39088c43fcfd76f7fdeAllen Rabinovich /** User argument. */
9c46bf9bc0ac9bab8d409ae4ab6d2a2ddc4dc55bJeff Conniff /** The timer thread. */
9c46bf9bc0ac9bab8d409ae4ab6d2a2ddc4dc55bJeff Conniff /** Event semaphore on which the thread is blocked. */
9c46bf9bc0ac9bab8d409ae4ab6d2a2ddc4dc55bJeff Conniff /** The timer interval. 0 if one-shot. */
f0e0bfede101cfa5fbfb4ffe85a839033657b5d7Allen Rabinovich /** The start of the current run (ns).
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * This is used to calculate when the timer ought to fire the next time. */
21257820ee962f4f2275b39088c43fcfd76f7fdeAllen Rabinovich /** The start of the current run (ns).
} RTTIMER;
RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_t u64NanoInterval, unsigned fFlags, PFNRTTIMER pfnTimer, void *pvUser)
if (!pTimer)
return VERR_NO_MEMORY;
rc = RTThreadCreate(&pTimer->Thread, rtTimerThread, pTimer, 0, RTTHREADTYPE_TIMER, RTTHREADFLAGS_WAITABLE, "TIMER");
return VINF_SUCCESS;
return rc;
return VINF_SUCCESS;
return VERR_INVALID_HANDLE;
return VINF_SUCCESS;
return VERR_INVALID_HANDLE;
return VERR_TIMER_ACTIVE;
return rc;
return VERR_INVALID_HANDLE;
return VERR_TIMER_SUSPENDED;
return rc;
return VINF_SUCCESS;
return VERR_NOT_SUPPORTED;
return VERR_NOT_SUPPORTED;