~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/atomic/pthread_traits.h

  • Committer: Brian Aker
  • Date: 2009-08-18 07:20:29 UTC
  • mfrom: (1117.1.9 merge)
  • Revision ID: brian@gaz-20090818072029-s9ch5lcmltxwidn7
Merge of Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2009 Sun Microsystems
5
5
 *  Copyright 2005-2008 Intel Corporation.  All Rights Reserved.
6
6
 *
7
7
 *  This program is free software; you can redistribute it and/or modify
31
31
  pthread_mutex_t the_mutex;
32
32
  bool locked;
33
33
public:
34
 
  mutex_wrapper(void)
35
 
   : the_mutex(),
36
 
     locked(false)
 
34
  mutex_wrapper(void): locked(false)
37
35
  {
 
36
    locked= false;
38
37
    (void) pthread_mutex_init(&the_mutex,  NULL);
39
38
  }
40
39
  ~mutex_wrapper(void)
67
66
 
68
67
  pthread_traits() {}
69
68
 
70
 
  inline value_type add_and_fetch(volatile value_type *value, D addend )
71
 
  {
72
 
    my_lock.lock();
73
 
    *value += addend;
74
 
    value_type ret= *value;
75
 
    my_lock.unlock();
76
 
    return ret;
77
 
  }
78
 
 
79
69
  inline value_type fetch_and_add(volatile value_type *value, D addend )
80
70
  {
81
71
    my_lock.lock();
 
72
    *value += addend;
82
73
    value_type ret= *value;
83
 
    *value += addend;
84
74
    my_lock.unlock();
85
75
    return ret;
86
76
  }
88
78
  inline value_type fetch_and_increment(volatile value_type *value)
89
79
  {
90
80
    my_lock.lock();
 
81
    *value++;
91
82
    value_type ret= *value;
92
 
    (*value)++;
93
83
    my_lock.unlock();
94
84
    return ret;
95
85
  }
97
87
  inline value_type fetch_and_decrement(volatile value_type *value)
98
88
  {
99
89
    my_lock.lock();
 
90
    *value--;
100
91
    value_type ret= *value;
101
 
    (*value)--;
102
92
    my_lock.unlock();
103
93
    return ret;
104
94
  }
107
97
                                    value_type new_value )
108
98
  {
109
99
    my_lock.lock();
 
100
    *value= new_value;
110
101
    value_type ret= *value;
111
 
    *value= new_value;
112
102
    my_lock.unlock();
113
103
    return ret;
114
104
  }
115
105
 
116
 
  inline bool compare_and_swap(volatile value_type *value,
 
106
  inline value_type compare_and_swap(volatile value_type *value,
117
107
                                     value_type new_value,
118
108
                                     value_type comparand )
119
109
  {
120
110
    my_lock.lock();
121
 
    bool ret= (*value == comparand);
122
 
    if (ret)
 
111
    if (*value == comparand)
123
112
      *value= new_value;
 
113
    value_type ret= *value;
124
114
    my_lock.unlock();
125
115
    return ret;
126
116
  }
127
117
 
128
118
  inline value_type fetch(const volatile value_type *value) const volatile
129
119
  {
130
 
    const_cast<pthread_traits *>(this)->my_lock.lock();
131
 
    value_type ret= *value;
132
 
    const_cast<pthread_traits *>(this)->my_lock.unlock();
133
 
    return ret;
 
120
    return *value;
134
121
  }
135
122
 
136
123
  inline value_type store_with_release(volatile value_type *value,