~ubuntu-branches/ubuntu/trusty/deal.ii/trusty

« back to all changes in this revision

Viewing changes to contrib/tbb/tbb22_20090809oss/include/tbb/queuing_mutex.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV, Adam C. Powell, IV, Denis Barbier
  • Date: 2010-07-29 13:47:01 UTC
  • mfrom: (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100729134701-akb8jb3stwge8tcm
Tags: 6.3.1-1
[ Adam C. Powell, IV ]
* Changed to source format 3.0 (quilt).
* Changed maintainer to debian-science with Adam Powell as uploader.
* Added source lintian overrides about Adam Powell's name.
* Added Vcs info on git repository.
* Bumped Standards-Version.
* Changed stamp-patch to patch target and fixed its application criterion.
* Moved make_dependencies and expand_instantiations to a versioned directory
  to avoid shlib package conflicts.

[ Denis Barbier ]
* New upstream release (closes: #562332).
  + Added libtbb support.
  + Forward-ported all patches.
* Updates for new PETSc version, including workaround for different versions
  of petsc and slepc.
* Add debian/watch.
* Update to debhelper 7.
* Added pdebuild patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright 2005-2009 Intel Corporation.  All Rights Reserved.
 
3
 
 
4
    This file is part of Threading Building Blocks.
 
5
 
 
6
    Threading Building Blocks is free software; you can redistribute it
 
7
    and/or modify it under the terms of the GNU General Public License
 
8
    version 2 as published by the Free Software Foundation.
 
9
 
 
10
    Threading Building Blocks is distributed in the hope that it will be
 
11
    useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 
12
    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
    GNU General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU General Public License
 
16
    along with Threading Building Blocks; if not, write to the Free Software
 
17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 
 
19
    As a special exception, you may use this file as part of a free software
 
20
    library without restriction.  Specifically, if other files instantiate
 
21
    templates or use macros or inline functions from this file, or you compile
 
22
    this file and link it with other files to produce an executable, this
 
23
    file does not by itself cause the resulting executable to be covered by
 
24
    the GNU General Public License.  This exception does not however
 
25
    invalidate any other reasons why the executable file might be covered by
 
26
    the GNU General Public License.
 
27
*/
 
28
 
 
29
#ifndef __TBB_queuing_mutex_H
 
30
#define __TBB_queuing_mutex_H
 
31
 
 
32
#include <cstring>
 
33
#include "atomic.h"
 
34
#include "tbb_profiling.h"
 
35
 
 
36
namespace tbb {
 
37
 
 
38
//! Queuing lock with local-only spinning.
 
39
/** @ingroup synchronization */
 
40
class queuing_mutex {
 
41
public:
 
42
    //! Construct unacquired mutex.
 
43
    queuing_mutex() {
 
44
        q_tail = NULL;
 
45
#if TBB_USE_THREADING_TOOLS
 
46
        internal_construct();
 
47
#endif
 
48
    }
 
49
 
 
50
    //! The scoped locking pattern
 
51
    /** It helps to avoid the common problem of forgetting to release lock.
 
52
        It also nicely provides the "node" for queuing locks. */
 
53
    class scoped_lock: internal::no_copy {
 
54
        //! Initialize fields to mean "no lock held".
 
55
        void initialize() {
 
56
            mutex = NULL;
 
57
#if TBB_USE_ASSERT
 
58
            internal::poison_pointer(next);
 
59
#endif /* TBB_USE_ASSERT */
 
60
        }
 
61
    public:
 
62
        //! Construct lock that has not acquired a mutex.
 
63
        /** Equivalent to zero-initialization of *this. */
 
64
        scoped_lock() {initialize();}
 
65
 
 
66
        //! Acquire lock on given mutex.
 
67
        /** Upon entry, *this should not be in the "have acquired a mutex" state. */
 
68
        scoped_lock( queuing_mutex& m ) {
 
69
            initialize();
 
70
            acquire(m);
 
71
        }
 
72
 
 
73
        //! Release lock (if lock is held).
 
74
        ~scoped_lock() {
 
75
            if( mutex ) release();
 
76
        }
 
77
 
 
78
        //! Acquire lock on given mutex.
 
79
        void __TBB_EXPORTED_METHOD acquire( queuing_mutex& m );
 
80
 
 
81
        //! Acquire lock on given mutex if free (i.e. non-blocking)
 
82
        bool __TBB_EXPORTED_METHOD try_acquire( queuing_mutex& m );
 
83
 
 
84
        //! Release lock.
 
85
        void __TBB_EXPORTED_METHOD release();
 
86
 
 
87
    private:
 
88
        //! The pointer to the mutex owned, or NULL if not holding a mutex.
 
89
        queuing_mutex* mutex;
 
90
 
 
91
        //! The pointer to the next competitor for a mutex
 
92
        scoped_lock *next;
 
93
 
 
94
        //! The local spin-wait variable
 
95
        /** Inverted (0 - blocked, 1 - acquired the mutex) for the sake of 
 
96
            zero-initialization.  Defining it as an entire word instead of
 
97
            a byte seems to help performance slightly. */
 
98
        internal::uintptr going;
 
99
    };
 
100
 
 
101
    void __TBB_EXPORTED_METHOD internal_construct();
 
102
 
 
103
    // Mutex traits
 
104
    static const bool is_rw_mutex = false;
 
105
    static const bool is_recursive_mutex = false;
 
106
    static const bool is_fair_mutex = true;
 
107
 
 
108
    friend class scoped_lock;
 
109
private:
 
110
    //! The last competitor requesting the lock
 
111
    atomic<scoped_lock*> q_tail;
 
112
 
 
113
};
 
114
 
 
115
__TBB_DEFINE_PROFILING_SET_NAME(queuing_mutex)
 
116
 
 
117
} // namespace tbb
 
118
 
 
119
#endif /* __TBB_queuing_mutex_H */