lRUMoves.h
Go to the documentation of this file.
00001 /* lRUMoves.h
00002  */
00003 #ifndef OSL_SEARCH_LRUMOVES_H
00004 #define OSL_SEARCH_LRUMOVES_H
00005 
00006 #include "osl/move.h"
00007 #include "osl/misc/carray.h"
00008 #ifdef OSL_SMP
00009 #  include "osl/misc/lightMutex.h"
00010 #endif
00011 
00012 namespace osl
00013 {
00014   namespace search
00015   {
00016     class LRUMoves
00017     {
00018       typedef CArray<Move, 2> moves_t;
00019       moves_t moves;
00020 #ifdef OSL_SMP
00021       typedef osl::misc::LightMutex Mutex;
00022       mutable Mutex mutex;
00023 #endif
00024     public:
00025       LRUMoves() {}
00026       LRUMoves(const LRUMoves& src)
00027         : moves(src.moves)
00028       {
00029       }
00030       LRUMoves& operator=(const LRUMoves& src)
00031       {
00032         if (this != &src)
00033           moves = src.moves;
00034         return *this;
00035       }
00036 
00037       void clear()
00038       {
00039 #ifdef OSL_SMP
00040         SCOPED_LOCK(lk,mutex);
00041 #endif
00042         moves.fill(Move::INVALID());
00043       }
00044       void setMove(Move best_move)
00045       {
00046 #ifdef OSL_SMP
00047         SCOPED_LOCK(lk,mutex);
00048 #endif
00049         if (best_move.isNormal() && moves[0] != best_move)
00050         {
00051           moves[1] = moves[0];
00052           moves[0] = best_move;
00053         }
00054       }
00055       const Move operator[](size_t i) const
00056       {
00057 #ifdef OSL_USE_RACE_DETECTOR
00058         SCOPED_LOCK(lk,mutex);
00059 #endif
00060         return moves[i];
00061       }
00062       static size_t size() { return moves_t::size(); }
00063     };
00064   }
00065 } // namespace osl
00066 
00067 #endif /* OSL_SEARCH_LRUMOVES_H */
00068 // ;;; Local Variables:
00069 // ;;; mode:c++
00070 // ;;; c-basic-offset:2
00071 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines