Shadowrun: Awakened 29 September 2011 - Build 871
queuing_mutex.h
Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2010 Intel Corporation.  All Rights Reserved.
00003 
00004     This file is part of Threading Building Blocks.
00005 
00006     Threading Building Blocks is free software; you can redistribute it
00007     and/or modify it under the terms of the GNU General Public License
00008     version 2 as published by the Free Software Foundation.
00009 
00010     Threading Building Blocks is distributed in the hope that it will be
00011     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00012     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with Threading Building Blocks; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019     As a special exception, you may use this file as part of a free software
00020     library without restriction.  Specifically, if other files instantiate
00021     templates or use macros or inline functions from this file, or you compile
00022     this file and link it with other files to produce an executable, this
00023     file does not by itself cause the resulting executable to be covered by
00024     the GNU General Public License.  This exception does not however
00025     invalidate any other reasons why the executable file might be covered by
00026     the GNU General Public License.
00027 */
00028 
00029 #ifndef __TBB_queuing_mutex_H
00030 #define __TBB_queuing_mutex_H
00031 
00032 #include "tbb_config.h"
00033 
00034 #if !TBB_USE_EXCEPTIONS && _MSC_VER
00035     // Suppress "C++ exception handler used, but unwind semantics are not enabled" warning in STL headers
00036     #pragma warning (push)
00037     #pragma warning (disable: 4530)
00038 #endif
00039 
00040 #include <cstring>
00041 
00042 #if !TBB_USE_EXCEPTIONS && _MSC_VER
00043     #pragma warning (pop)
00044 #endif
00045 
00046 #include "atomic.h"
00047 #include "tbb_profiling.h"
00048 
00049 namespace tbb {
00050 
00052 
00053 class queuing_mutex {
00054 public:
00056     queuing_mutex() {
00057         q_tail = NULL;
00058 #if TBB_USE_THREADING_TOOLS
00059         internal_construct();
00060 #endif
00061     }
00062 
00064 
00066     class scoped_lock: internal::no_copy {
00068         void initialize() {
00069             mutex = NULL;
00070 #if TBB_USE_ASSERT
00071             internal::poison_pointer(next);
00072 #endif /* TBB_USE_ASSERT */
00073         }
00074     public:
00076 
00077         scoped_lock() {initialize();}
00078 
00080         scoped_lock( queuing_mutex& m ) {
00081             initialize();
00082             acquire(m);
00083         }
00084 
00086         ~scoped_lock() {
00087             if( mutex ) release();
00088         }
00089 
00091         void __TBB_EXPORTED_METHOD acquire( queuing_mutex& m );
00092 
00094         bool __TBB_EXPORTED_METHOD try_acquire( queuing_mutex& m );
00095 
00097         void __TBB_EXPORTED_METHOD release();
00098 
00099     private:
00101         queuing_mutex* mutex;
00102 
00104         scoped_lock *next;
00105 
00107 
00110         uintptr_t going;
00111     };
00112 
00113     void __TBB_EXPORTED_METHOD internal_construct();
00114 
00115     // Mutex traits
00116     static const bool is_rw_mutex = false;
00117     static const bool is_recursive_mutex = false;
00118     static const bool is_fair_mutex = true;
00119 
00120     friend class scoped_lock;
00121 private:
00123     atomic<scoped_lock*> q_tail;
00124 
00125 };
00126 
00127 __TBB_DEFINE_PROFILING_SET_NAME(queuing_mutex)
00128 
00129 } // namespace tbb
00130 
00131 #endif /* __TBB_queuing_mutex_H */

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net