~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/atomic/pthread_traits.h

  • Committer: Brian Aker
  • Date: 2010-03-19 01:45:39 UTC
  • mto: This revision was merged to the branch mainline in revision 1362.
  • Revision ID: brian@gaz-20100319014539-jv38vkd8h9a4axzr
Another pass through the interface...

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