~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to drizzled/atomic/pthread_traits.h

  • Committer: Padraig O'Sullivan
  • Date: 2010-04-17 01:38:47 UTC
  • mfrom: (1237.9.238 bad-staging)
  • Revision ID: osullivan.padraig@gmail.com-20100417013847-ibjioqsfbmf5yg4g
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
 
68
68
  pthread_traits() {}
69
69
 
 
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
 
70
79
  inline value_type fetch_and_add(volatile value_type *value, D addend )
71
80
  {
72
81
    my_lock.lock();
 
82
    value_type ret= *value;
73
83
    *value += addend;
74
 
    value_type ret= *value;
75
84
    my_lock.unlock();
76
85
    return ret;
77
86
  }
79
88
  inline value_type fetch_and_increment(volatile value_type *value)
80
89
  {
81
90
    my_lock.lock();
 
91
    value_type ret= *value;
82
92
    *value++;
83
 
    value_type ret= *value;
84
93
    my_lock.unlock();
85
94
    return ret;
86
95
  }
88
97
  inline value_type fetch_and_decrement(volatile value_type *value)
89
98
  {
90
99
    my_lock.lock();
 
100
    value_type ret= *value;
91
101
    *value--;
92
 
    value_type ret= *value;
93
102
    my_lock.unlock();
94
103
    return ret;
95
104
  }
98
107
                                    value_type new_value )
99
108
  {
100
109
    my_lock.lock();
 
110
    value_type ret= *value;
101
111
    *value= new_value;
102
 
    value_type ret= *value;
103
112
    my_lock.unlock();
104
113
    return ret;
105
114
  }
106
115
 
107
 
  inline value_type compare_and_swap(volatile value_type *value,
 
116
  inline bool compare_and_swap(volatile value_type *value,
108
117
                                     value_type new_value,
109
118
                                     value_type comparand )
110
119
  {
111
120
    my_lock.lock();
112
 
    if (*value == comparand)
 
121
    bool ret= (*value == comparand);
 
122
    if (ret)
113
123
      *value= new_value;
114
 
    value_type ret= *value;
115
124
    my_lock.unlock();
116
125
    return ret;
117
126
  }
118
127
 
119
128
  inline value_type fetch(const volatile value_type *value) const volatile
120
129
  {
121
 
    return *value;
 
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;
122
134
  }
123
135
 
124
136
  inline value_type store_with_release(volatile value_type *value,