Overview   API Reference  

bitops.hpp

00001 #if !defined(__SYSTEM_L4_BITOPS_HPP__)
00002 #define __SYSTEM_L4_BITOPS_HPP__
00003 
00004 //
00005 // L4 includes
00006 //
00007 #include <l4/util/bitops.h>
00008 
00009 //
00010 // local includes
00011 //
00012 #include "core/util/operators.hpp"
00013 
00014 //
00015 // l4util bitops functions wrapped into a C++ class.
00016 //
00017 struct bitops
00018 {
00019     //
00020     // attribute to store the value
00021     //
00022     l4_umword_t bits;
00023 
00024     //
00025     // constructor
00026     //
00027     inline bitops(const l4_umword_t bits=0)
00028         : bits(bits)
00029     {}
00030 
00031     //
00032     // atomic bit modifying functions
00033     //
00034     inline void set_bit(const uint8_t bit)
00035     {
00036         return set_bit(bit, &bits);
00037     }
00038 
00039     inline int test_bit(const uint8_t bit) const
00040     {
00041         return test_bit(bit, &bits);
00042     }
00043 
00044     inline void clear_bit(const uint8_t bit)
00045     {
00046         return clear_bit(bit, &bits);
00047     }
00048 
00049     inline int test_and_set_bit(const uint8_t bit)
00050     {
00051         return test_and_set_bit(bit, &bits);
00052     }
00053 
00054     inline int test_and_clear_bit(const uint8_t bit)
00055     {
00056         return test_and_clear_bit(bit, &bits);
00057     }
00058 
00059     inline int lowest_set_bit(void) const
00060     {
00061         return lowest_set_bit(bits);
00062     }
00063 
00064     inline int highest_set_bit(void) const
00065     {
00066         return highest_set_bit(bits);
00067     }
00068 
00069     //
00070     // atomic bit access operator (read-only, writing this way is not desired)
00071     //
00072     inline int operator [](const uint8_t bit) const
00073     {
00074         return test_bit(bit, &bits);
00075     }
00076 
00077     //
00078     // non-atomic access operators
00079     //
00080     ACCESS_FUNCTORS(bitops&, l4_umword_t, bits)
00081     ACCESS_OPERATORS(bitops&, l4_umword_t, bits)
00082 
00083     //
00084     // static helper functions for general use
00085     //
00086     static inline void set_bit(const int bit, volatile l4_umword_t *word)
00087     {
00088         return l4util_set_bit(bit, word);
00089     }
00090 
00091     static inline int test_bit(const int bit, const volatile l4_umword_t *word)
00092     {
00093         return l4util_test_bit(bit, word);
00094     }
00095 
00096     static inline void clear_bit(const int bit, volatile l4_umword_t *word)
00097     {
00098         return l4util_clear_bit(bit, word);
00099     }
00100 
00101     static inline int test_and_set_bit(const int bit, volatile l4_umword_t *word)
00102     {
00103         return l4util_test_and_set_bit(bit, word);
00104     }
00105 
00106     static inline int test_and_clear_bit(const int bit, volatile l4_umword_t *word)
00107     {
00108         return l4util_test_and_clear_bit(bit, word);
00109     }
00110 
00111     static inline int lowest_set_bit(const l4_umword_t word)
00112     {
00113         return l4util_bsf(word);
00114     }
00115 
00116     static inline int highest_set_bit(const l4_umword_t word)
00117     {
00118         return l4util_bsr(word);
00119     }
00120 };
00121 
00122 #endif
00123 
00124 // ***** end of source ***** //
00125 

L4vmm Reference Manual, written by Mario Schwalbe  © 2006-2008