~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/atomic/pthread_traits.h

* Fixes drizzled's atomics:

- fetch_and_add() was actually add_and_fetch() - fixed to have both methods correct
- compare_and_swap() was incorrect for all traits classes.  Fixed to return a bool
true only when the supplied value is actually swapped
- fixes increment() and decrement() methods and operator+=() in outer atomics class
template to call proper add_and_fetch() methods on traits classes
- Now that above are fixed, removed the hacks in Query_id and TransactionLog to
have query ID and the new transactoin ID start properly at 1.

* Transaction messages sent over replication stream now use
a real transaction ID, managed by drizzled::TransactionServices.  Previously, 
the Query_id was being used, resulting in SELECT statements incrementing the
transaction ID.

* Added a test case to ensure that DDL ops are given a transaction ID and SELECT
ops do not increment the transaction ID.

The transaction ID will be paired with a channel ID to become the global
transaction identifier.  ReplicationServices will manage the pairing of
channel and transaction ID and understand how far a particular subscriber
node has applied.

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<mutex_wrapper>(my_lock).lock();
 
131
    value_type ret= *value;
 
132
    const_cast<mutex_wrapper>(my_lock).unlock();
 
133
    return ret;
122
134
  }
123
135
 
124
136
  inline value_type store_with_release(volatile value_type *value,