Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
Jeff Johnson | 32d95a3 | 2012-09-10 13:15:23 -0700 | [diff] [blame] | 2 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /**========================================================================= |
| 23 | |
| 24 | \file vos_threads.c |
| 25 | |
| 26 | \brief virtual Operating System Services (vOSS) Threading APIs |
| 27 | |
| 28 | Copyright 2008 (c) Qualcomm, Incorporated. All Rights Reserved. |
| 29 | |
| 30 | Qualcomm Confidential and Proprietary. |
| 31 | |
| 32 | ========================================================================*/ |
| 33 | |
| 34 | /* $Header$ */ |
| 35 | |
| 36 | /*-------------------------------------------------------------------------- |
| 37 | Include Files |
| 38 | ------------------------------------------------------------------------*/ |
| 39 | #include <vos_threads.h> |
| 40 | #include <vos_trace.h> |
| 41 | #include <linux/jiffies.h> |
| 42 | #include <linux/sched.h> |
| 43 | #include <linux/delay.h> |
| 44 | #include <linux/interrupt.h> |
| 45 | |
| 46 | /*-------------------------------------------------------------------------- |
| 47 | Preprocessor definitions and constants |
| 48 | ------------------------------------------------------------------------*/ |
| 49 | |
| 50 | |
| 51 | /*-------------------------------------------------------------------------- |
| 52 | Type declarations |
| 53 | ------------------------------------------------------------------------*/ |
| 54 | |
| 55 | |
| 56 | /*------------------------------------------------------------------------- |
| 57 | Function declarations and documenation |
| 58 | ------------------------------------------------------------------------*/ |
| 59 | |
| 60 | /*---------------------------------------------------------------------------- |
| 61 | |
| 62 | \brief vos_sleep() - sleep |
| 63 | |
| 64 | The \a vos_sleep() function suspends the execution of the current thread |
| 65 | until the specified time out interval elapses. |
| 66 | |
| 67 | \param msInterval - the number of milliseconds to suspend the current thread. |
| 68 | A value of 0 may or may not cause the current thread to yield. |
| 69 | |
| 70 | \return Nothing. |
| 71 | |
| 72 | \sa |
| 73 | |
| 74 | --------------------------------------------------------------------------*/ |
| 75 | v_VOID_t vos_sleep( v_U32_t msInterval ) |
| 76 | { |
| 77 | if (in_interrupt()) |
| 78 | { |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame^] | 79 | VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR, "%s cannot be called from interrupt context!!!", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 80 | return; |
| 81 | } |
| 82 | msleep_interruptible(msInterval); |
| 83 | } |
| 84 | |
| 85 | /*---------------------------------------------------------------------------- |
| 86 | |
| 87 | \brief vos_sleep_us() - sleep |
| 88 | |
| 89 | The \a vos_sleep_us() function suspends the execution of the current thread |
| 90 | until the specified time out interval elapses. |
| 91 | |
| 92 | \param usInterval - the number of microseconds to suspend the current thread. |
| 93 | A value of 0 may or may not cause the current thread to yield. |
| 94 | |
| 95 | \return Nothing. |
| 96 | |
| 97 | \sa |
| 98 | |
| 99 | --------------------------------------------------------------------------*/ |
| 100 | v_VOID_t vos_sleep_us( v_U32_t usInterval ) |
| 101 | { |
| 102 | unsigned long timeout = usecs_to_jiffies(usInterval) + 1; |
| 103 | if (in_interrupt()) |
| 104 | { |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame^] | 105 | VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR, "%s cannot be called from interrupt context!!!", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 106 | return; |
| 107 | } |
| 108 | while (timeout && !signal_pending(current)) |
| 109 | timeout = schedule_timeout_interruptible(timeout); |
| 110 | } |
| 111 | |
| 112 | |
| 113 | /*---------------------------------------------------------------------------- |
| 114 | |
| 115 | \brief vos_busy_wait() - busy wait |
| 116 | |
| 117 | The \a vos_busy_wait() function places the current thread in busy wait |
| 118 | until the specified time out interval elapses. If the interval is greater |
| 119 | than 50us on WM, the behaviour is undefined. |
| 120 | |
| 121 | \param usInterval - the number of microseconds to busy wait. |
| 122 | |
| 123 | \return Nothing. |
| 124 | |
| 125 | \sa |
| 126 | |
| 127 | --------------------------------------------------------------------------*/ |
| 128 | v_VOID_t vos_busy_wait( v_U32_t usInterval ) |
| 129 | { |
| 130 | udelay(usInterval); |
| 131 | } |