Exemplo n.º 1
0
static gboolean
invoice_opened_handler (xmlNodePtr node, gpointer invoice_pdata)
{
    struct invoice_pdata *pdata = invoice_pdata;

    return set_timespec (node, pdata->invoice, gncInvoiceSetDateOpened);
}
Exemplo n.º 2
0
static gboolean
invoice_posted_handler (xmlNodePtr node, gpointer invoice_pdata)
{
    struct invoice_pdata* pdata = static_cast<decltype (pdata)> (invoice_pdata);

    return set_timespec (node, pdata->invoice, gncInvoiceSetDatePosted);
}
Exemplo n.º 3
0
static gboolean
order_opened_handler (xmlNodePtr node, gpointer order_pdata)
{
    struct order_pdata* pdata = static_cast<decltype (pdata)> (order_pdata);

    return set_timespec (node, pdata->order, gncOrderSetDateOpened);
}
Exemplo n.º 4
0
static gboolean
entry_dateentered_handler (xmlNodePtr node, gpointer entry_pdata)
{
    struct entry_pdata *pdata = entry_pdata;

    return set_timespec(node, pdata->entry, gncEntrySetDateEntered);
}
Exemplo n.º 5
0
static gboolean
entry_date_handler (xmlNodePtr node, gpointer entry_pdata)
{
    struct entry_pdata* pdata = static_cast<decltype (pdata)> (entry_pdata);

    return set_timespec (node, pdata->entry, gncEntrySetDate);
}
Exemplo n.º 6
0
static gboolean
order_closed_handler (xmlNodePtr node, gpointer order_pdata)
{
    struct order_pdata *pdata = order_pdata;

    return set_timespec (node, pdata->order, gncOrderSetDateClosed);
}
Exemplo n.º 7
0
static TDHS_INLINE int wait_server_to_start(THD *thd) {
    int r = 0;
    tdhs_mysql_mutex_lock(&LOCK_server_started);
    while (!mysqld_server_started) {
        timespec abstime = { };
        set_timespec(abstime, 1);
        tdhs_mysql_cond_timedwait(&COND_server_started, &LOCK_server_started,
                                  &abstime);
        tdhs_mysql_mutex_unlock(&LOCK_server_started);
        tdhs_mysql_mutex_lock(&thd->mysys_var->mutex);
        THD::killed_state st = thd->killed;
        tdhs_mysql_mutex_unlock(&thd->mysys_var->mutex);
        tdhs_mysql_mutex_lock(&LOCK_server_started);
        if (st != THD::NOT_KILLED) {
            r = -1;
            break;
        }
        if (tdhs_share->shutdown) {
            r = -1;
            break;
        }
    }

    tdhs_mysql_mutex_unlock(&LOCK_server_started);
    return r;
}
Exemplo n.º 8
0
void my_thread_global_end(void)
{
  struct timespec abstime;
  my_bool all_threads_killed= 1;

  set_timespec(&abstime, my_thread_end_wait_time);
  mysql_mutex_lock(&THR_LOCK_threads);
  while (THR_thread_count > 0)
  {
    int error= mysql_cond_timedwait(&THR_COND_threads, &THR_LOCK_threads,
                                    &abstime);
    if (error == ETIMEDOUT || error == ETIME)
    {
#ifndef _WIN32
      /*
        We shouldn't give an error here, because if we don't have
        pthread_kill(), programs like mysqld can't ensure that all threads
        are killed when we enter here.
      */
      if (THR_thread_count)
        /* purecov: begin inspected */
        my_message_local(ERROR_LEVEL, "Error in my_thread_global_end(): "
                         "%d threads didn't exit", THR_thread_count);
        /* purecov: end */
#endif
      all_threads_killed= 0;
      break;
    }
  }
  mysql_mutex_unlock(&THR_LOCK_threads);

  DBUG_ASSERT(THR_KEY_mysys_initialized);
  my_delete_thread_local_key(THR_KEY_mysys);
  THR_KEY_mysys_initialized= FALSE;
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
  pthread_mutexattr_destroy(&my_fast_mutexattr);
#endif
#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
  pthread_mutexattr_destroy(&my_errorcheck_mutexattr);
#endif
  mysql_mutex_destroy(&THR_LOCK_malloc);
  mysql_mutex_destroy(&THR_LOCK_open);
  mysql_mutex_destroy(&THR_LOCK_lock);
  mysql_mutex_destroy(&THR_LOCK_myisam);
  mysql_mutex_destroy(&THR_LOCK_myisam_mmap);
  mysql_mutex_destroy(&THR_LOCK_heap);
  mysql_mutex_destroy(&THR_LOCK_net);
  mysql_mutex_destroy(&THR_LOCK_charset);
  if (all_threads_killed)
  {
    mysql_mutex_destroy(&THR_LOCK_threads);
    mysql_cond_destroy(&THR_COND_threads);
  }

  my_thread_global_init_done= 0;
}
Exemplo n.º 9
0
static status_t
checksumfs_read_stat(fs_volume* fsVolume, fs_vnode* vnode, struct stat* st)
{
	Node* node = (Node*)vnode->private_node;

    st->st_mode = node->Mode();
    st->st_nlink = node->HardLinks();
    st->st_uid = node->UID();
    st->st_gid = node->GID();
    st->st_size = node->Size();
    st->st_blksize = B_PAGE_SIZE * 16;	// random number
    set_timespec(st->st_mtim, node->ModificationTime());
    set_timespec(st->st_ctim, node->ChangeTime());
    set_timespec(st->st_crtim, node->CreationTime());
    st->st_atim = st->st_ctim;
		// we don't support access time
    st->st_type = 0;        /* attribute/index type */
    st->st_blocks = 1 + (st->st_size + B_PAGE_SIZE - 1) / B_PAGE_SIZE;
		// TODO: That does neither count management structures for the content
		// nor attributes.

	return B_OK;
}
Exemplo n.º 10
0
void my_thread_global_end(void)
{
  struct timespec abstime;
  my_bool all_threads_killed= 1;

  set_timespec(abstime, my_thread_end_wait_time);
  mysql_mutex_lock(&THR_LOCK_threads);
  while (THR_thread_count > 0)
  {
    int error= mysql_cond_timedwait(&THR_COND_threads, &THR_LOCK_threads,
                                    &abstime);
    if (error == ETIMEDOUT || error == ETIME)
    {
#ifdef HAVE_PTHREAD_KILL
      /*
        We shouldn't give an error here, because if we don't have
        pthread_kill(), programs like mysqld can't ensure that all threads
        are killed when we enter here.
      */
      if (THR_thread_count)
        fprintf(stderr,
                "Error in my_thread_global_end(): %d threads didn't exit\n",
                THR_thread_count);
#endif
      all_threads_killed= 0;
      break;
    }
  }
  mysql_mutex_unlock(&THR_LOCK_threads);

  my_thread_destroy_common_mutex();

  /*
    Only destroy the mutex & conditions if we don't have other threads around
    that could use them.
  */
  if (all_threads_killed)
  {
    my_thread_destroy_internal_mutex();
  }
  my_thread_global_init_done= 0;
}
Exemplo n.º 11
0
static
void audit_log_flush(audit_log_buffer_t *log)
{
  mysql_mutex_lock(&log->mutex);
  while (log->flush_pos == log->write_pos)
  {
    struct timespec abstime;
    if (log->stop)
    {
      mysql_mutex_unlock(&log->mutex);
      return;
    }
    set_timespec(abstime, 1);
    mysql_cond_timedwait(&log->written_cond, &log->mutex, &abstime);
  }

  if (log->flush_pos > log->write_pos % log->size)
  {
    mysql_mutex_unlock(&log->mutex);
    log->write_func(log->write_func_data,
                    log->buf + log->flush_pos,
                    log->size - log->flush_pos,
                    LOG_RECORD_INCOMPLETE);
    mysql_mutex_lock(&log->mutex);
    log->flush_pos= 0;
    log->write_pos%= log->size;
  }
  else
  {
    size_t flushlen= log->write_pos - log->flush_pos;
    mysql_mutex_unlock(&log->mutex);
    log->write_func(log->write_func_data,
                    log->buf + log->flush_pos, flushlen,
                    LOG_RECORD_COMPLETE);
    mysql_mutex_lock(&log->mutex);
    log->flush_pos+= flushlen;
  }
  DBUG_ASSERT(log->write_pos >= log->flush_pos);
  mysql_cond_broadcast(&log->flushed_cond);
  mysql_mutex_unlock(&log->mutex);
}
Exemplo n.º 12
0
int main(int ac, char **av)
{
  int i, tfd;
  long ticks;
  unsigned long long tnow, ttmr;
  u_int64_t uticks;
  struct itimerspec tmr;
  struct tmr_type clks[] =
  {
#if defined(HAVE_CLOCK_MONOTONIC)
    { CLOCK_MONOTONIC, "CLOCK MONOTONIC" },
#endif
    { CLOCK_REALTIME, "CLOCK REALTIME" },
  };

  for (i = 0; i < sizeof(clks) / sizeof(clks[0]); i++)
  {
    fprintf(stdout, "\n\n---------------------------------------\n");
    fprintf(stdout, "| testing %s\n", clks[i].name);
    fprintf(stdout, "---------------------------------------\n\n");

    fprintf(stdout, "relative timer test (at 500 ms) ...\n");
    set_timespec(&tmr.it_value, 500 * 1000);
    set_timespec(&tmr.it_interval, 0);
    tnow = getustime(clks[i].id);
    if ((tfd = timerfd_create(clks[i].id, 0)) == -1)
    {
      perror("timerfd_create");
      return 1;
    }

    if (timerfd_settime(tfd, 0, &tmr, NULL))
    {
      perror("timerfd_settime");
      return 1;
    }

    fprintf(stdout, "wating timer ...\n");
    ticks = waittmr(tfd, -1);
    ttmr = getustime(clks[i].id);
    if (ticks <= 0)
      fprintf(stdout, "whooops! no timer showed up!\n");
    else
      fprintf(stdout, "got timer ticks (%ld) after %.1f s\n",
              ticks, (ttmr - tnow) * 1e-6);


    fprintf(stdout, "absolute timer test (at 500 ms) ...\n");
    tnow = getustime(clks[i].id);
    set_timespec(&tmr.it_value, tnow + 500 * 1000);
    set_timespec(&tmr.it_interval, 0);
    if (timerfd_settime(tfd, TFD_TIMER_ABSTIME, &tmr, NULL))
    {
      perror("timerfd_settime");
      return 1;
    }

    fprintf(stdout, "wating timer ...\n");
    ticks = waittmr(tfd, -1);
    ttmr = getustime(clks[i].id);
    if (ticks <= 0)
      fprintf(stdout, "whooops! no timer showed up!\n");
    else
      fprintf(stdout, "got timer ticks (%ld) after %.1f s\n",
              ticks, (ttmr - tnow) * 1e-6);

    fprintf(stdout, "sequential timer test (100 ms clock) ...\n");
    tnow = getustime(clks[i].id);
    set_timespec(&tmr.it_value, tnow + 100 * 1000);
    set_timespec(&tmr.it_interval, 100 * 1000);
    if (timerfd_settime(tfd, TFD_TIMER_ABSTIME, &tmr, NULL))
    {
      perror("timerfd_settime");
      return 1;
    }

    fprintf(stdout, "sleeping one second ...\n");
    sleep(1);
    if (timerfd_gettime(tfd, &tmr))
    {
      perror("timerfd_gettime");
      return 1;
    }
    fprintf(stdout, "timerfd_gettime returned:\n"
            "\tit_value = %.1f it_interval = %.1f\n",
            tmr.it_value.tv_sec + 1e-9 * tmr.it_value.tv_nsec,
            tmr.it_interval.tv_sec + 1e-9 * tmr.it_interval.tv_nsec);
    fprintf(stdout, "sleeping 1 second ...\n");
    sleep(1);

    fprintf(stdout, "wating timer ...\n");
    ticks = waittmr(tfd, -1);
    ttmr = getustime(clks[i].id);
    if (ticks <= 0)
      fprintf(stdout, "whooops! no timer showed up!\n");
    else
      fprintf(stdout, "got timer ticks (%ld) after %.1f s\n",
              ticks, (ttmr - tnow) * 1e-6);


    fprintf(stdout, "O_NONBLOCK test ...\n");
    tnow = getustime(clks[i].id);
    set_timespec(&tmr.it_value, 100 * 1000);
    set_timespec(&tmr.it_interval, 0);
    if (timerfd_settime(tfd, 0, &tmr, NULL))
    {
      perror("timerfd_settime");
      return 1;
    }
#if 0
    fprintf(stdout, "timerfd = %d\n", tfd);
#endif

    fprintf(stdout, "wating timer (flush the single tick) ...\n");
    ticks = waittmr(tfd, -1);
    ttmr = getustime(clks[i].id);
    if (ticks <= 0)
      fprintf(stdout, "whooops! no timer showed up!\n");
    else
      fprintf(stdout, "got timer ticks (%ld) after %.1f s\n",
              ticks, (ttmr - tnow) * 1e-6);

    fcntl(tfd, F_SETFL, fcntl(tfd, F_GETFL, 0) | O_NONBLOCK);

    if (read(tfd, &uticks, sizeof(uticks)) > 0)
      fprintf(stdout, "whooops! timer ticks not zero when should have been\n");
    else if (errno != EAGAIN)
      fprintf(stdout, "whooops! bad errno value (%d = '%s')!\n",
              errno, strerror(errno));
    else
      fprintf(stdout, "success\n");

    fcntl(tfd, F_SETFL, fcntl(tfd, F_GETFL, 0) & ~O_NONBLOCK);

    close(tfd);
  }

  return 0;
}
Exemplo n.º 13
0
static enum enum_thr_lock_result
wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data,
              my_bool in_wait_list)
{
  struct st_my_thread_var *thread_var= my_thread_var;
  pthread_cond_t *cond= &thread_var->suspend;
  struct timespec wait_timeout;
  enum enum_thr_lock_result result= THR_LOCK_ABORTED;
  my_bool can_deadlock= test(data->owner->info->n_cursors);

  if (!in_wait_list)
  {
    (*wait->last)=data;				/* Wait for lock */
    data->prev= wait->last;
    wait->last= &data->next;
  }

  /* Set up control struct to allow others to abort locks */
  thread_var->current_mutex= &data->lock->mutex;
  thread_var->current_cond=  cond;
  data->cond= cond;

  if (can_deadlock)
    set_timespec(wait_timeout, table_lock_wait_timeout);
  while (!thread_var->abort || in_wait_list)
  {
    int rc= (can_deadlock ?
             pthread_cond_timedwait(cond, &data->lock->mutex,
                                    &wait_timeout) :
             pthread_cond_wait(cond, &data->lock->mutex));
    /*
      We must break the wait if one of the following occurs:
      - the connection has been aborted (!thread_var->abort), but
        this is not a delayed insert thread (in_wait_list). For a delayed
        insert thread the proper action at shutdown is, apparently, to
        acquire the lock and complete the insert.
      - the lock has been granted (data->cond is set to NULL by the granter),
        or the waiting has been aborted (additionally data->type is set to
        TL_UNLOCK).
      - the wait has timed out (rc == ETIMEDOUT)
      Order of checks below is important to not report about timeout
      if the predicate is true.
    */
    if (data->cond == 0)
      break;
    if (rc == ETIMEDOUT || rc == ETIME)
    {
      result= THR_LOCK_WAIT_TIMEOUT;
      break;
    }
  }

  if (data->cond || data->type == TL_UNLOCK)
  {
    if (data->cond)                             /* aborted or timed out */
    {
      if (((*data->prev)=data->next))		/* remove from wait-list */
	data->next->prev= data->prev;
      else
	wait->last=data->prev;
      data->type= TL_UNLOCK;                    /* No lock */
      check_locks(data->lock, "killed or timed out wait_for_lock", 1);
      wake_up_waiters(data->lock);
    }
    else
    {
      check_locks(data->lock, "aborted wait_for_lock", 0);
    }
  }
  else
  {
    result= THR_LOCK_SUCCESS;
    statistic_increment(locks_waited, &THR_LOCK_lock);
    if (data->lock->get_status)
      (*data->lock->get_status)(data->status_param, 0);
    check_locks(data->lock,"got wait_for_lock",0);
  }
  pthread_mutex_unlock(&data->lock->mutex);

  /* The following must be done after unlock of lock->mutex */
  pthread_mutex_lock(&thread_var->mutex);
  thread_var->current_mutex= 0;
  thread_var->current_cond=  0;
  pthread_mutex_unlock(&thread_var->mutex);
  return result;
}
Exemplo n.º 14
0
 void set_expires_in(std::chrono::nanoseconds duration) { set_timespec(Deadline, duration); }
Exemplo n.º 15
0
int main(int ac, char **av)
{
	int i, tfd;
	long ticks;
	unsigned long long tnow, ttmr;
	u_int64_t uticks;
	struct itimerspec tmr;
	struct tmr_type clks[] = {
		{CLOCK_MONOTONIC, "CLOCK MONOTONIC"},
		{CLOCK_REALTIME, "CLOCK REALTIME"},
	};

	if ((tst_kvercmp(2, 6, 25)) < 0) {
		tst_resm(TCONF, "This test can only run on kernels that are ");
		tst_resm(TCONF, "2.6.25 and higher");
		exit(0);
	}

	for (i = 0; i < sizeof(clks) / sizeof(clks[0]); i++) {
		fprintf(stdout,
			"\n\n---------------------------------------\n");
		fprintf(stdout, "| testing %s\n", clks[i].name);
		fprintf(stdout, "---------------------------------------\n\n");

		fprintf(stdout, "relative timer test (at 500 ms) ...\n");
		set_timespec(&tmr.it_value, 500 * 1000);
		set_timespec(&tmr.it_interval, 0);
		tnow = getustime(clks[i].id);
		if ((tfd = timerfd_create(clks[i].id, 0)) == -1) {
			perror("timerfd");
			return 1;
		}
		fprintf(stdout, "timerfd = %d\n", tfd);

		if (timerfd_settime(tfd, 0, &tmr, NULL)) {
			perror("timerfd_settime");
			return 1;
		}

		fprintf(stdout, "wating timer ...\n");
		ticks = waittmr(tfd, -1);
		ttmr = getustime(clks[i].id);
		if (ticks <= 0)
			fprintf(stdout, "whooops! no timer showed up!\n");
		else
			fprintf(stdout, "got timer ticks (%ld) after %llu ms\n",
				ticks, (ttmr - tnow) / 1000);

		fprintf(stdout, "absolute timer test (at 500 ms) ...\n");
		tnow = getustime(clks[i].id);
		set_timespec(&tmr.it_value, tnow + 500 * 1000);
		set_timespec(&tmr.it_interval, 0);
		if (timerfd_settime(tfd, TFD_TIMER_ABSTIME, &tmr, NULL)) {
			perror("timerfd_settime");
			return 1;
		}

		fprintf(stdout, "wating timer ...\n");
		ticks = waittmr(tfd, -1);
		ttmr = getustime(clks[i].id);
		if (ticks <= 0)
			fprintf(stdout, "whooops! no timer showed up!\n");
		else
			fprintf(stdout, "got timer ticks (%ld) after %llu ms\n",
				ticks, (ttmr - tnow) / 1000);

		fprintf(stdout, "sequential timer test (100 ms clock) ...\n");
		tnow = getustime(clks[i].id);
		set_timespec(&tmr.it_value, tnow + 100 * 1000);
		set_timespec(&tmr.it_interval, 100 * 1000);
		if (timerfd_settime(tfd, TFD_TIMER_ABSTIME, &tmr, NULL)) {
			perror("timerfd_settime");
			return 1;
		}

		fprintf(stdout, "sleeping 1 second ...\n");
		sleep(1);
		if (timerfd_gettime(tfd, &tmr)) {
			perror("timerfd_gettime");
			return 1;
		}
		fprintf(stdout, "timerfd_gettime returned:\n"
			"\tit_value = { %ld, %ld } it_interval = { %ld, %ld }\n",
			(long)tmr.it_value.tv_sec, (long)tmr.it_value.tv_nsec,
			(long)tmr.it_interval.tv_sec,
			(long)tmr.it_interval.tv_nsec);
		fprintf(stdout, "sleeping 1 second ...\n");
		sleep(1);

		fprintf(stdout, "wating timer ...\n");
		ticks = waittmr(tfd, -1);
		ttmr = getustime(clks[i].id);
		if (ticks <= 0)
			fprintf(stdout, "whooops! no timer showed up!\n");
		else
			fprintf(stdout, "got timer ticks (%ld) after %llu ms\n",
				ticks, (ttmr - tnow) / 1000);

		fprintf(stdout, "O_NONBLOCK test ...\n");
		tnow = getustime(clks[i].id);
		set_timespec(&tmr.it_value, 100 * 1000);
		set_timespec(&tmr.it_interval, 0);
		if (timerfd_settime(tfd, 0, &tmr, NULL)) {
			perror("timerfd_settime");
			return 1;
		}
		fprintf(stdout, "timerfd = %d\n", tfd);

		fprintf(stdout, "wating timer (flush the single tick) ...\n");
		ticks = waittmr(tfd, -1);
		ttmr = getustime(clks[i].id);
		if (ticks <= 0)
			fprintf(stdout, "whooops! no timer showed up!\n");
		else
			fprintf(stdout, "got timer ticks (%ld) after %llu ms\n",
				ticks, (ttmr - tnow) / 1000);

		fcntl(tfd, F_SETFL, fcntl(tfd, F_GETFL, 0) | O_NONBLOCK);

		if (read(tfd, &uticks, sizeof(uticks)) > 0)
			fprintf(stdout,
				"whooops! timer ticks not zero when should have been\n");
		else if (errno != EAGAIN)
			fprintf(stdout,
				"whooops! bad errno value (%d = '%s')!\n",
				errno, strerror(errno));
		else
			fprintf(stdout, "success\n");

		fcntl(tfd, F_SETFL, fcntl(tfd, F_GETFL, 0) & ~O_NONBLOCK);

		close(tfd);
	}

	tst_exit();
}
Exemplo n.º 16
0
static enum enum_thr_lock_result
wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data,
              my_bool in_wait_list, ulong lock_wait_timeout,
              struct st_my_thread_var *thread_var)
{
  struct timespec wait_timeout;
  enum enum_thr_lock_result result= THR_LOCK_ABORTED;
  PSI_stage_info old_stage;
  DBUG_ENTER("wait_for_lock");

  /*
    One can use this to signal when a thread is going to wait for a lock.
    See debug_sync.cc.

    Beware of waiting for a signal here. The lock has aquired its mutex.
    While waiting on a signal here, the locking thread could not aquire
    the mutex to release the lock. One could lock up the table
    completely.

    In detail it works so: When thr_lock() tries to acquire a table
    lock, it locks the lock->mutex, checks if it can have the lock, and
    if not, it calls wait_for_lock(). Here it unlocks the table lock
    while waiting on a condition. The sync point is located before this
    wait for condition. If we have a waiting action here, we hold the
    the table locks mutex all the time. Any attempt to look at the table
    lock by another thread blocks it immediately on lock->mutex. This
    can easily become an unexpected and unobvious blockage. So be
    warned: Do not request a WAIT_FOR action for the 'wait_for_lock'
    sync point unless you really know what you do.
  */
  DEBUG_SYNC_C("wait_for_lock");

  if (!in_wait_list)
  {
    (*wait->last)=data;				/* Wait for lock */
    data->prev= wait->last;
    wait->last= &data->next;
  }

  locks_waited++;

  /* Set up control struct to allow others to abort locks */
  data->cond= &thread_var->suspend;

  enter_cond_hook(NULL, data->cond, &data->lock->mutex,
                  &stage_waiting_for_table_level_lock, &old_stage,
                  __func__, __FILE__, __LINE__);

  /*
    Since before_lock_wait potentially can create more threads to
    scheduler work for, we don't want to call the before_lock_wait
    callback unless it will really start to wait.

    For similar reasons, we do not want to call before_lock_wait and
    after_lock_wait for each lap around the loop, so we restrict
    ourselves to call it before_lock_wait once before starting to wait
    and once after the thread has exited the wait loop.
   */
  if ((!thread_var->abort || in_wait_list) && before_lock_wait)
    (*before_lock_wait)();

  set_timespec(&wait_timeout, lock_wait_timeout);
  while (!thread_var->abort || in_wait_list)
  {
    int rc= mysql_cond_timedwait(data->cond, &data->lock->mutex, &wait_timeout);
    /*
      We must break the wait if one of the following occurs:
      - the connection has been aborted (!thread_var->abort),
      - the lock has been granted (data->cond is set to NULL by the granter),
        or the waiting has been aborted (additionally data->type is set to
        TL_UNLOCK).
      - the wait has timed out (rc == ETIMEDOUT)
      Order of checks below is important to not report about timeout
      if the predicate is true.
    */
    if (data->cond == 0)
    {
      DBUG_PRINT("thr_lock", ("lock granted/aborted"));
      break;
    }
    if (rc == ETIMEDOUT || rc == ETIME)
    {
      /* purecov: begin inspected */
      DBUG_PRINT("thr_lock", ("lock timed out"));
      result= THR_LOCK_WAIT_TIMEOUT;
      break;
      /* purecov: end */
    }
  }

  /*
    We call the after_lock_wait callback once the wait loop has
    finished.
   */
  if (after_lock_wait)
    (*after_lock_wait)();

  DBUG_PRINT("thr_lock", ("aborted: %d  in_wait_list: %d",
                          thread_var->abort, in_wait_list));

  if (data->cond || data->type == TL_UNLOCK)
  {
    if (data->cond)                             /* aborted or timed out */
    {
      if (((*data->prev)=data->next))		/* remove from wait-list */
	data->next->prev= data->prev;
      else
	wait->last=data->prev;
      data->type= TL_UNLOCK;                    /* No lock */
      check_locks(data->lock, "killed or timed out wait_for_lock", 1);
      wake_up_waiters(data->lock);
    }
    else
    {
      DBUG_PRINT("thr_lock", ("lock aborted"));
      check_locks(data->lock, "aborted wait_for_lock", 0);
    }
  }
  else
  {
    result= THR_LOCK_SUCCESS;
    if (data->lock->get_status)
      (*data->lock->get_status)(data->status_param, 0);
    check_locks(data->lock,"got wait_for_lock",0);
  }
  mysql_mutex_unlock(&data->lock->mutex);

  exit_cond_hook(NULL, &old_stage, __func__, __FILE__, __LINE__);

  DBUG_RETURN(result);
}
Exemplo n.º 17
0
 void set_interval(std::chrono::nanoseconds interval) { set_timespec(Periodic, interval); }