Google Base's Lockimpl

Source: Internet
Author: User

In order to be compatible with different platforms, this class uses the Impl mode, win platform through the critical_section, such words or relatively simple, specific to the unknown solution, but have to say that the way to achieve the boost will be complex to where to go, of course, the benefits are powerful, The disadvantage is the high cost of learning, will use less people.

#if defined (os_win) #include <windows.h> #elif defined (os_posix) #include <pthread.h> #endif # include "base/ Base_export.h "#include" base/basictypes.h "namespace base {namespace Internal {//This class implements the underlying PLA  Tform-specific Spin-lock mechanism//used for the lock class. Most users should not use Lockimpl directly, but//should instead use Lock.class base_export lockimpl {public: #if defined (os_win) typedef critical_section NATIVEHANDLE, #elif defined (os_posix) typedef pthread_mutex_t Nativehandle; #endif Loc  Kimpl ();  ~lockimpl ();  If The lock is not a held, take it and return true.  If the lock is already//held by something else, immediately return false.  BOOL Try ();  Take the lock and blocking until it is available if necessary.  void Lock ();  Release the lock.  This must is called by the Lock's holder:after//a successful call to Try, or a call to lock.  void Unlock ();  Return the native underlying lock. TODO (awalker): Refactor lock and condition variables So, this is//unnecessary.  nativehandle* Native_handle () {return &native_handle_;} private:nativehandle native_handle_;  Disallow_copy_and_assign (Lockimpl);};} namespace internal}//namespace BASE#ENDIF//Base_synchronization_lock_impl_h_

  

Google Base's Lockimpl

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.