Overview   API Reference  

lock.hpp

00001 #if !defined(__SYSTEM_L4_LOCK_HPP__)
00002 #define __SYSTEM_L4_LOCK_HPP__
00003 
00004 //
00005 // L4 includes
00006 //
00007 #include <l4/lock/lock.h>
00008 
00009 //
00010 // local includes
00011 //
00012 #include "core/util/noncopyable.hpp"
00013 
00014 //
00015 // a l4lock wrapped into a C++ class.
00016 //
00017 struct lock : protected l4lock, private noncopyable
00018 {
00019     //
00020     // constructors
00021     //
00022     inline lock(void)
00023         : l4lock(L4LOCK_UNLOCKED)
00024     {}
00025 
00026     // do *NOT* copy another used l4lock (for L4LOCK_LOCKED/L4LOCK_UNLOCKED only).
00027     inline lock(const l4lock &initial_state)
00028         : l4lock(initial_state)
00029     {}
00030 
00031     //
00032     // typecast operators
00033     //
00034     inline int operator ()(void) const
00035     {
00036         return ref_count;
00037     }
00038 
00039     inline operator int(void) const
00040     {
00041         return (*this)();
00042     }
00043 
00044     //
00045     // map l4lock functions to methods ...
00046     //
00047     inline int acquire(void)
00048     {
00049         l4lock_lock(this);
00050         return 0;
00051     }
00052 
00053     inline int try_acquire(void)
00054     {
00055         return l4lock_try_lock(this);
00056     }
00057 
00058     inline void release(void)
00059     {
00060         l4lock_unlock(this);
00061     }
00062 
00063     inline l4thread_t owner(void) const
00064     {
00065         return l4lock_owner(this);
00066     }
00067 
00068     //
00069     // prefix increment operators
00070     //
00071     inline lock &operator ++(void)
00072     {
00073         release();
00074         return *this;
00075     }
00076 
00077     inline lock &operator --(void)
00078     {
00079         acquire();
00080         return *this;
00081     }
00082 
00083     //
00084     // postfix increment operators: these ones return void to avoid to copy the entire object,
00085     //     thus violating standard compliance. DO NOT return a reference here.
00086     //
00087     inline void operator ++(int)
00088     {
00089         ++*this;
00090     }
00091 
00092     inline void operator --(int)
00093     {
00094         --*this;
00095     }
00096 };
00097 
00098 #endif
00099 
00100 // ***** end of source ***** //
00101 

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