~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/lock.cc

  • Committer: Brian Aker
  • Date: 2010-02-14 01:56:51 UTC
  • mto: (1273.16.5 fix_is)
  • mto: This revision was merged to the branch mainline in revision 1300.
  • Revision ID: brian@gaz-20100214015651-ror9j0xu7dccz0ct
Two fixes for "make dist"

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
#include "drizzled/pthread_globals.h"
84
84
#include "drizzled/internal/my_sys.h"
85
85
 
86
 
#include <set>
87
 
#include <vector>
88
 
#include <algorithm>
89
 
#include <functional>
90
 
 
91
 
using namespace std;
92
 
 
93
86
namespace drizzled
94
87
{
95
88
 
179
172
{
180
173
  DRIZZLE_LOCK *sql_lock;
181
174
  Table *write_lock_used;
182
 
  vector<plugin::StorageEngine *> involved_engines;
183
175
  int rc;
184
176
 
185
177
  *need_reopen= false;
210
202
        goto retry;
211
203
      }
212
204
    }
213
 
    
214
 
    session->set_proc_info("Notify start statement");
215
 
    /*
216
 
     * Here, we advise all storage engines involved in the
217
 
     * statement that we are starting a new statement
218
 
     */
219
 
    if (sql_lock->table_count)
220
 
    {
221
 
      size_t num_tables= sql_lock->table_count;
222
 
      plugin::StorageEngine *engine;
223
 
      set<size_t> involved_slots;
224
 
      for (size_t x= 1; x <= num_tables; x++, tables++)
225
 
      {
226
 
        engine= (*tables)->cursor->engine;
227
 
        if (involved_slots.count(engine->getId()) > 0)
228
 
          continue; /* already added to involved engines */
229
 
        involved_engines.push_back(engine);
230
 
        involved_slots.insert(engine->getId());
231
 
      }
232
 
 
233
 
      for_each(involved_engines.begin(),
234
 
               involved_engines.end(),
235
 
               bind2nd(mem_fun(&plugin::StorageEngine::startStatement), session));
236
 
    }
237
 
 
238
 
    session->set_proc_info("External lock");
239
 
    /*
240
 
     * Here, the call to lock_external() informs the
241
 
     * all engines for all tables used in this statement
242
 
     * of the type of lock that Drizzle intends to take on a 
243
 
     * specific table.
244
 
     */
 
205
 
 
206
    session->set_proc_info("System lock");
245
207
    if (sql_lock->table_count && lock_external(session, sql_lock->table,
246
208
                                               sql_lock->table_count))
247
209
    {
301
263
      type for other tables preserved.
302
264
    */
303
265
    reset_lock_data_and_free(&sql_lock);
304
 
 
305
 
    /*
306
 
     * Notify all involved engines that the
307
 
     * SQL statement has ended
308
 
     */
309
 
    for_each(involved_engines.begin(),
310
 
             involved_engines.end(),
311
 
             bind2nd(mem_fun(&plugin::StorageEngine::endStatement), session));
312
266
retry:
313
267
    if (flags & DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN)
314
268
    {
328
282
      sql_lock= NULL;
329
283
    }
330
284
  }
 
285
 
331
286
  session->set_time_after_lock();
332
287
  return (sql_lock);
333
288
}
528
483
  return result;
529
484
}
530
485
 
 
486
 
531
487
/** Unlock a set of external. */
532
488
 
533
489
static int unlock_external(Session *session, Table **table,uint32_t count)
1048
1004
  session->global_read_lock= 0;
1049
1005
}
1050
1006
 
1051
 
static inline bool must_wait(bool is_not_commit)
1052
 
{
1053
 
  return (global_read_lock &&
1054
 
          (is_not_commit ||
1055
 
          global_read_lock_blocks_commit));
1056
 
}
 
1007
#define must_wait (global_read_lock &&                             \
 
1008
                   (is_not_commit ||                               \
 
1009
                    global_read_lock_blocks_commit))
1057
1010
 
1058
1011
bool wait_if_global_read_lock(Session *session, bool abort_on_refresh,
1059
1012
                              bool is_not_commit)
1069
1022
  safe_mutex_assert_not_owner(&LOCK_open);
1070
1023
 
1071
1024
  (void) pthread_mutex_lock(&LOCK_global_read_lock);
1072
 
  if ((need_exit_cond= must_wait(is_not_commit)))
 
1025
  if ((need_exit_cond= must_wait))
1073
1026
  {
1074
1027
    if (session->global_read_lock)              // This thread had the read locks
1075
1028
    {
1086
1039
    }
1087
1040
    old_message=session->enter_cond(&COND_global_read_lock, &LOCK_global_read_lock,
1088
1041
                                "Waiting for release of readlock");
1089
 
    while (must_wait(is_not_commit) && ! session->killed &&
 
1042
    while (must_wait && ! session->killed &&
1090
1043
           (!abort_on_refresh || session->version == refresh_version))
1091
1044
    {
1092
1045
      (void) pthread_cond_wait(&COND_global_read_lock, &LOCK_global_read_lock);