GNU Radio 3.3.0 C++ API
libsync.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 _SPU_LIB_SYNC_H_
00042 #define _SPU_LIB_SYNC_H_
00043 #include "sync_utils.h"
00044 
00045 #ifdef __cplusplus
00046 extern "C" {
00047 #endif
00048 
00049 typedef unsigned long long atomic_ea_t;
00050 
00051 extern void atomic_set(atomic_ea_t v, int val);
00052 extern void atomic_add(int a, atomic_ea_t v);
00053 extern void atomic_sub(int a, atomic_ea_t v);
00054 extern void atomic_inc(atomic_ea_t v);
00055 extern void atomic_dec(atomic_ea_t v);
00056 
00057 extern int atomic_read(atomic_ea_t v);
00058 extern int atomic_add_return(int a, atomic_ea_t v);
00059 extern int atomic_sub_return(int a, atomic_ea_t v);
00060 extern int atomic_inc_return(atomic_ea_t v);
00061 extern int atomic_dec_return(atomic_ea_t v);
00062 extern int atomic_sub_and_test(int a, atomic_ea_t v);
00063 extern int atomic_dec_and_test(atomic_ea_t v);
00064 extern int atomic_dec_if_positive(atomic_ea_t v);
00065 
00066 typedef unsigned long long mutex_ea_t;
00067 
00068 extern void mutex_init(mutex_ea_t lock);
00069 extern void mutex_lock(mutex_ea_t lock);
00070 extern int mutex_trylock(mutex_ea_t ea);
00071 extern void mutex_unlock(mutex_ea_t lock);
00072 
00073 
00074 typedef struct
00075 {
00076   int num_threads_signal;       /* the number of threads that are going to be waken up.
00077                                  * There are 3 values possible for this parameter, 0, 1, 
00078                                  * or num_threads_waiting
00079                                  */
00080   int num_threads_waiting;      /* the number of threads that are waiting to be awaken 
00081                                  */ 
00082 } condition_variable_t __attribute__ ((aligned (128)));  
00083 
00084 typedef eaddr_t cond_ea_t;      /* a system memory 64 bit address that points to
00085                                  * a valid condition_variable_t 
00086                                  */
00087 
00088 
00089 extern void cond_init (cond_ea_t  cond);
00090 extern void cond_signal (cond_ea_t cond);
00091 extern void cond_broadcast (cond_ea_t cond);
00092 extern void cond_wait (cond_ea_t cond, mutex_ea_t  mutex);
00093 
00094 typedef unsigned long long completion_ea_t;
00095 
00096 extern void init_completion(completion_ea_t completion);
00097 extern void wait_for_completion(completion_ea_t completion);
00098 extern void complete(completion_ea_t completion);
00099 extern void complete_all(completion_ea_t completion);
00100 
00101 #ifdef __SPU__
00102   /* Function only implemented for the SPU
00103    */
00104   extern void read_lock(eaddr_t ea);
00105   extern void read_unlock(eaddr_t ea);
00106   extern int  read_trylock(eaddr_t ea);
00107   extern void write_lock(eaddr_t ea);
00108   extern void write_unlock(eaddr_t ea);
00109   extern int  write_trylock(eaddr_t ea);
00110 #endif
00111 
00112 #ifdef __cplusplus
00113 }
00114 #endif
00115 
00116 #endif /* _SPU_LIB_SYNC_H_ */