~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/thr_lock.cc

  • Committer: Monty Taylor
  • Date: 2010-09-29 04:27:16 UTC
  • mfrom: (1800.1.9 build)
  • Revision ID: mordred@inaugust.com-20100929042716-q9sb3re31iwti87z
Merged doc fixes, lock fixes, path fixes and bath fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
 
79
79
#include <drizzled/util/test.h>
80
80
 
 
81
#include <boost/interprocess/sync/lock_options.hpp>
 
82
 
81
83
using namespace std;
82
84
 
83
85
namespace drizzled
152
154
  internal::st_my_thread_var *thread_var= session->getThreadVar();
153
155
 
154
156
  boost::condition_variable *cond= &thread_var->suspend;
155
 
  struct timespec wait_timeout;
156
157
  enum enum_thr_lock_result result= THR_LOCK_ABORTED;
157
158
  bool can_deadlock= test(data->owner->info->n_cursors);
158
159
 
170
171
  thread_var->current_cond=  &thread_var->suspend;
171
172
  data->cond= &thread_var->suspend;;
172
173
 
173
 
  if (can_deadlock)
174
 
    set_timespec(wait_timeout, table_lock_wait_timeout);
175
174
  while (!thread_var->abort || in_wait_list)
176
175
  {
177
 
    int rc= (can_deadlock ?
178
 
             pthread_cond_timedwait(cond->native_handle(), data->lock->native_handle()->native_handle(), &wait_timeout) :
179
 
             pthread_cond_wait(cond->native_handle(), data->lock->native_handle()->native_handle()));
 
176
    boost::mutex::scoped_lock scoped(*data->lock->native_handle(), boost::adopt_lock_t());
 
177
 
 
178
    if (can_deadlock)
 
179
    {
 
180
      boost::xtime xt; 
 
181
      xtime_get(&xt, boost::TIME_UTC); 
 
182
      xt.sec += table_lock_wait_timeout; 
 
183
      if (not cond->timed_wait(scoped, xt))
 
184
      {
 
185
        result= THR_LOCK_WAIT_TIMEOUT;
 
186
        scoped.release();
 
187
        break;
 
188
      }
 
189
    }
 
190
    else
 
191
    {
 
192
      cond->wait(scoped);
 
193
    }
180
194
    /*
181
195
      We must break the wait if one of the following occurs:
182
196
      - the connection has been aborted (!thread_var->abort), but
192
206
    */
193
207
    if (data->cond == NULL)
194
208
    {
195
 
      break;
196
 
    }
197
 
    if (rc == ETIMEDOUT || rc == ETIME)
198
 
    {
199
 
      result= THR_LOCK_WAIT_TIMEOUT;
200
 
      break;
201
 
    }
 
209
      scoped.release();
 
210
      break;
 
211
    }
 
212
    scoped.release();
202
213
  }
203
214
  if (data->cond || data->type == TL_UNLOCK)
204
215
  {