1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: fnd_Backoff.h 4 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. 5 These coded instructions, statements, and computer programs contain 6 proprietary information of Nintendo of America Inc. and/or Nintendo 7 Company Ltd., and are protected by Federal copyright law. They may 8 not be disclosed to third parties or copied or duplicated in any form, 9 in whole or in part, without the prior written consent of Nintendo. 10 $Rev: 12449 $ 11 *--------------------------------------------------------------------------- 12 13 14 */ 15 16 #ifndef NN_FND_FND_BACKOFF_H_ 17 #define NN_FND_FND_BACKOFF_H_ 18 19 #ifdef __cplusplus 20 21 #include <nn/types.h> 22 23 namespace nn { namespace fnd { 24 25 class BackOffManager 26 { 27 private: 28 const u32 m_order; 29 u32 m_count; 30 void BackOffImpl(); 31 32 public: BackOffManager(u32 order)33 BackOffManager(u32 order) : m_order(order), m_count(0) {} 34 BackOff()35 void BackOff() 36 { 37 // The first contention (m_count == 0) is likely to be the result of thread switching, and not contention between cores. Passes without backing off. 38 // 39 // 40 if (m_count++ > 0) 41 { 42 BackOffImpl(); 43 } 44 } 45 }; 46 47 }} 48 49 #endif // __cplusplus 50 51 #endif // NN_FND_FND_BACKOFF_H_ 52