~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_plugin.cc

  • Committer: Brian Aker
  • Date: 2009-04-06 16:55:13 UTC
  • mfrom: (970.1.5 merge)
  • Revision ID: brian@tangent.org-20090406165513-0r9u2bo1438u970k
Merge refactoring around plugin_ref

Show diffs side-by-side

added added

removed removed

Lines of Context:
134
134
static DYNAMIC_ARRAY plugin_array;
135
135
 
136
136
static bool reap_needed= false;
137
 
static int plugin_array_version=0;
138
137
 
139
138
/*
140
139
  write-lock on LOCK_system_variables_hash is required before modifying
231
230
static void plugin_vars_free_values(sys_var *vars);
232
231
static void plugin_opt_set_limits(struct my_option *options,
233
232
                                  const struct st_mysql_sys_var *opt);
234
 
static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref plugin);
 
233
static plugin_ref intern_plugin_lock(st_plugin_int *rc);
235
234
static void reap_plugins(void);
236
235
 
237
236
 
499
498
}
500
499
 
501
500
 
502
 
static plugin_ref intern_plugin_lock(LEX *, plugin_ref rc)
 
501
static plugin_ref intern_plugin_lock(st_plugin_int *rc)
503
502
{
504
 
  st_plugin_int *pi= plugin_ref_to_int(rc);
505
503
  plugin_ref plugin;
506
504
 
507
 
  assert(pi);
508
505
  assert(rc);
509
506
 
510
507
  /*
512
509
    memory manager and/or valgrind to track locked references and
513
510
    double unlocks to aid resolving reference counting.problems.
514
511
  */
515
 
  if (!(plugin= (plugin_ref) malloc(sizeof(pi))))
 
512
  if (!(plugin= (plugin_ref) malloc(sizeof(plugin_ref))))
 
513
  {
 
514
    assert(1);
516
515
    return(NULL);
 
516
  }
517
517
 
518
 
  *plugin= pi;
 
518
  *plugin= rc;
519
519
 
520
520
  return(plugin);
521
521
}
522
522
 
523
523
 
524
 
plugin_ref plugin_lock(Session *session, plugin_ref *ptr)
 
524
plugin_ref plugin_lock(plugin_ref *ptr)
525
525
{
526
 
  LEX *lex= session ? session->lex : 0;
527
 
  plugin_ref rc;
528
 
  rc= intern_plugin_lock(lex, *ptr);
529
 
  return(rc);
 
526
  return ptr[0];
530
527
}
531
528
 
532
529
 
533
 
plugin_ref plugin_lock_by_name(Session *session, const LEX_STRING *name, int type)
 
530
plugin_ref plugin_lock_by_name(const LEX_STRING *name, int type)
534
531
{
535
532
  Plugin_registry registry= Plugin_registry::get_plugin_registry();
536
533
 
537
 
  LEX *lex= session ? session->lex : 0;
538
534
  plugin_ref rc= NULL;
539
535
  st_plugin_int *plugin;
540
536
  if (! initialized)
541
537
    return(0);
542
538
 
543
539
  if ((plugin= registry.find(name, type)))
544
 
    rc= intern_plugin_lock(lex, plugin_int_to_ref(plugin));
 
540
    rc= intern_plugin_lock(plugin);
545
541
  return(rc);
546
542
}
547
543
 
606
602
      {
607
603
        if ((tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
608
604
        {
609
 
          plugin_array_version++;
610
605
          registry.add(plugin, tmp_plugin_ptr);
611
606
          init_alloc_root(&tmp_plugin_ptr->mem_root, 4096, 4096);
612
607
          return(false);
655
650
  if (plugin->plugin_dl)
656
651
    plugin_dl_del(&plugin->plugin_dl->dl);
657
652
  plugin->isInited= false;
658
 
  plugin_array_version++;
659
653
  pthread_rwlock_wrlock(&LOCK_system_variables_hash);
660
654
  mysql_del_sys_var_chain(plugin->system_vars);
661
655
  pthread_rwlock_unlock(&LOCK_system_variables_hash);
802
796
      if (my_strcasecmp(&my_charset_utf8_general_ci, plugin->name, "MyISAM") == 0)
803
797
      {
804
798
        assert(!global_system_variables.table_plugin);
805
 
        global_system_variables.table_plugin=
806
 
          intern_plugin_lock(NULL, plugin_int_to_ref(plugin_ptr));
 
799
        global_system_variables.table_plugin= &plugin_ptr;
807
800
      }
808
801
    }
809
802
  }
1001
994
  uint32_t idx;
1002
995
  struct st_plugin_int *plugin;
1003
996
  vector<st_plugin_int *> plugins;
1004
 
  int version=plugin_array_version;
1005
997
 
1006
998
  if (!initialized)
1007
999
    return(false);
1029
1021
       plugin_iter != plugins.end();
1030
1022
       plugin_iter++)
1031
1023
  {
1032
 
    if (unlikely(version != plugin_array_version))
1033
 
    {
1034
 
      vector<st_plugin_int *>::iterator reset_iter;
1035
 
      for (reset_iter= plugin_iter;
1036
 
           reset_iter != plugins.end();
1037
 
           reset_iter++)
1038
 
        if (*reset_iter && (*reset_iter)->isInited && all)
1039
 
          *reset_iter=0;
1040
 
    }
1041
1024
    plugin= *plugin_iter;
1042
1025
    /* It will stop iterating on first engine error when "func" returns true */
1043
1026
    if (plugin && func(session, plugin_int_to_ref(plugin), arg))
1355
1338
****************************************************************************/
1356
1339
 
1357
1340
 
1358
 
sys_var *find_sys_var(Session *session, const char *str, uint32_t length)
 
1341
sys_var *find_sys_var(Session *, const char *str, uint32_t length)
1359
1342
{
1360
1343
  sys_var *var;
1361
1344
  sys_var_pluginvar *pi= NULL;
1366
1349
      (pi= var->cast_pluginvar()))
1367
1350
  {
1368
1351
    pthread_rwlock_unlock(&LOCK_system_variables_hash);
1369
 
    LEX *lex= session ? session->lex : 0;
1370
 
    if (!(plugin= intern_plugin_lock(lex, plugin_int_to_ref(pi->plugin))))
 
1352
    if (!(plugin= intern_plugin_lock(pi->plugin)))
1371
1353
      var= NULL; /* failed to lock it, it must be uninstalling */
1372
1354
    else if (plugin[0]->isInited == false)
1373
1355
    {
1675
1657
  session->variables.dynamic_variables_size= 0;
1676
1658
  session->variables.dynamic_variables_ptr= 0;
1677
1659
 
1678
 
  session->variables.table_plugin=
1679
 
    intern_plugin_lock(NULL, global_system_variables.table_plugin);
 
1660
  session->variables.table_plugin= global_system_variables.table_plugin;
1680
1661
}
1681
1662
 
1682
1663