GNU Radio 3.3.0 C++ API
cond_wait.h
Go to the documentation of this file.
00001 /* --------------------------------------------------------------  */
00002 /* (C)Copyright 2001,2007,                                         */
00003 /* International Business Machines Corporation,                    */
00004 /* Sony Computer Entertainment, Incorporated,                      */
00005 /* Toshiba Corporation,                                            */
00006 /*                                                                 */
00007 /* All Rights Reserved.                                            */
00008 /*                                                                 */
00009 /* Redistribution and use in source and binary forms, with or      */
00010 /* without modification, are permitted provided that the           */
00011 /* following conditions are met:                                   */
00012 /*                                                                 */
00013 /* - Redistributions of source code must retain the above copyright*/
00014 /*   notice, this list of conditions and the following disclaimer. */
00015 /*                                                                 */
00016 /* - Redistributions in binary form must reproduce the above       */
00017 /*   copyright notice, this list of conditions and the following   */
00018 /*   disclaimer in the documentation and/or other materials        */
00019 /*   provided with the distribution.                               */
00020 /*                                                                 */
00021 /* - Neither the name of IBM Corporation nor the names of its      */
00022 /*   contributors may be used to endorse or promote products       */
00023 /*   derived from this software without specific prior written     */
00024 /*   permission.                                                   */
00025 /*                                                                 */
00026 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND          */
00027 /* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,     */
00028 /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF        */
00029 /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE        */
00030 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR            */
00031 /* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    */
00032 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT    */
00033 /* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;    */
00034 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)        */
00035 /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN       */
00036 /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR    */
00037 /* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  */
00038 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              */
00039 /* --------------------------------------------------------------  */
00040 /* PROLOG END TAG zYx                                              */
00041 #ifndef _PPU_COND_WAIT_H_
00042 #define _PPU_COND_WAIT_H_
00043 
00044 #include <ppu_intrinsics.h>
00045 #include "sync_utils.h"
00046 #include "mutex_lock.h"
00047 #include "mutex_unlock.h"
00048 #include "cond.h"
00049 
00050 static __inline void _cond_wait (cond_ea_t cond, mutex_ea_t  mutex)
00051 {
00052   int delta, cur_delta;
00053   unsigned int val, cond_val, signaled_cnt;
00054   void *p;
00055 
00056 
00057   SYNC_ULL_TO_PTR(cond, p);
00058 
00059   /* Atomically signal we have entered the condition wait by incrementing
00060    * the waiting count.
00061    */
00062   do {
00063     val = __lwarx(p);
00064     val = (val & ~0xFFFF) | ((val+1) & 0xFFFF);
00065   } while (__stwcx(p, val) == 0);
00066 
00067 
00068   /* Release the lock
00069    */
00070   _mutex_unlock (mutex);
00071 
00072   /* Determine the signal count needed for this 
00073    * participant to be signaled.
00074    */
00075 
00076   signaled_cnt = val >> 16;
00077   delta = (int)(val & 0xFFFF) - (int)signaled_cnt;
00078   if (delta < 0) delta = -delta;
00079 
00080   /* Wait until the signaled count reaches the count
00081    * previously determined.
00082    */
00083   do {
00084     cond_val = __lwarx(p);
00085 
00086     cur_delta = (int)(cond_val >> 16) - signaled_cnt;
00087     if (cur_delta < 0) cur_delta = -cur_delta;
00088    
00089   } while (cur_delta < delta);
00090 
00091   /* Relock the mutex 
00092    */
00093   _mutex_lock (mutex);
00094 }
00095 
00096 #endif /* _PPU_COND_WAIT_H_ */