~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzletest.cc

  • Committer: Monty Taylor
  • Date: 2008-09-05 23:33:24 UTC
  • Revision ID: monty@inaugust.com-20080905233324-hhdhdmmdk5i47ikc
Removed EMBEDDED_LIBRARY.

Show diffs side-by-side

added added

removed removed

Lines of Context:
433
433
                  const char *err_sqlstate, string *ds);
434
434
void handle_no_error(struct st_command*);
435
435
 
436
 
#ifdef EMBEDDED_LIBRARY
437
 
 
438
 
/* attributes of the query thread */
439
 
pthread_attr_t cn_thd_attrib;
440
 
 
441
 
/*
442
 
  send_one_query executes query in separate thread, which is
443
 
  necessary in embedded library to run 'send' in proper way.
444
 
  This implementation doesn't handle errors returned
445
 
  by drizzle_send_query. It's technically possible, though
446
 
  I don't see where it is needed.
447
 
*/
448
 
pthread_handler_t send_one_query(void *arg)
449
 
{
450
 
  struct st_connection *cn= (struct st_connection*)arg;
451
 
 
452
 
  drizzle_thread_init();
453
 
  VOID(drizzle_send_query(&cn->drizzle, cn->cur_query, cn->cur_query_len));
454
 
 
455
 
  drizzle_thread_end();
456
 
  pthread_mutex_lock(&cn->mutex);
457
 
  cn->query_done= 1;
458
 
  VOID(pthread_cond_signal(&cn->cond));
459
 
  pthread_mutex_unlock(&cn->mutex);
460
 
  pthread_exit(0);
461
 
  return 0;
462
 
}
463
 
 
464
 
static int do_send_query(struct st_connection *cn, const char *q, int q_len,
465
 
                         int flags)
466
 
{
467
 
  pthread_t tid;
468
 
 
469
 
  if (flags & QUERY_REAP_FLAG)
470
 
    return drizzle_send_query(&cn->drizzle, q, q_len);
471
 
 
472
 
  if (pthread_mutex_init(&cn->mutex, NULL) ||
473
 
      pthread_cond_init(&cn->cond, NULL))
474
 
    die("Error in the thread library");
475
 
 
476
 
  cn->cur_query= q;
477
 
  cn->cur_query_len= q_len;
478
 
  cn->query_done= 0;
479
 
  if (pthread_create(&tid, &cn_thd_attrib, send_one_query, (void*)cn))
480
 
    die("Cannot start new thread for query");
481
 
 
482
 
  return 0;
483
 
}
484
 
 
485
 
static void wait_query_thread_end(struct st_connection *con)
486
 
{
487
 
  if (!con->query_done)
488
 
  {
489
 
    pthread_mutex_lock(&con->mutex);
490
 
    while (!con->query_done)
491
 
      pthread_cond_wait(&con->cond, &con->mutex);
492
 
    pthread_mutex_unlock(&con->mutex);
493
 
  }
494
 
}
495
 
 
496
 
#else /*EMBEDDED_LIBRARY*/
497
436
 
498
437
#define do_send_query(cn,q,q_len,flags) drizzle_send_query(&cn->drizzle, q, q_len)
499
438
 
500
 
#endif /*EMBEDDED_LIBRARY*/
501
 
 
502
439
void do_eval(string *query_eval, const char *query,
503
440
             const char *query_end, bool pass_through_escape_chars)
504
441
{