1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems, Inc.
5
* Copyright 2005-2008 Intel Corporation. All Rights Reserved.
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; version 2 of the License.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#ifndef DRIZZLED_ATOMIC_PTHREAD_TRAITS_H
22
#define DRIZZLED_ATOMIC_PTHREAD_TRAITS_H
31
pthread_mutex_t the_mutex;
38
(void) pthread_mutex_init(&the_mutex, NULL);
44
pthread_mutex_destroy(&the_mutex);
48
pthread_mutex_lock(&the_mutex);
53
pthread_mutex_unlock(&the_mutex);
58
template<typename T, typename D>
62
mutex_wrapper my_lock;
70
inline value_type add_and_fetch(volatile value_type *value, D addend )
74
value_type ret= *value;
79
inline value_type fetch_and_add(volatile value_type *value, D addend )
82
value_type ret= *value;
88
inline value_type fetch_and_increment(volatile value_type *value)
91
value_type ret= *value;
97
inline value_type fetch_and_decrement(volatile value_type *value)
100
value_type ret= *value;
106
inline value_type fetch_and_store(volatile value_type *value,
107
value_type new_value )
110
value_type ret= *value;
116
inline bool compare_and_swap(volatile value_type *value,
117
value_type new_value,
118
value_type comparand )
121
bool ret= (*value == comparand);
128
inline value_type fetch(const volatile value_type *value) const volatile
130
const_cast<pthread_traits *>(this)->my_lock.lock();
131
value_type ret= *value;
132
const_cast<pthread_traits *>(this)->my_lock.unlock();
136
inline value_type store_with_release(volatile value_type *value,
137
value_type new_value)
141
value_type ret= *value;
146
}; /* pthread_traits */
149
} /* namespace internal */
150
} /* namespace drizzled */
153
#endif /* DRIZZLED_ATOMIC_PTHREAD_TRAITS_H */