コード例 #1
0
ファイル: gamma-spline.c プロジェクト: jwahlstrand/kdotp-fke
Gamma * gamma_spline_calc_little_gamma (GammaSpline *gs, double * omega) { // without the one over omega
    if (!gstimer) {
        gstimer = g_timer_new();
        g_timer_start(gstimer);
    }
    else g_timer_continue(gstimer);

    int q=0;
	double kc;
    int Nkc = 16384;
    Gamma * g = gamma_new (Nkc);
    
    double dkc=2*KCMAX/Nkc;
    double denom=pow(KCMAX,4);
	for (kc=-KCMAX+dkc;kc<KCMAX;kc=kc+dkc) {
	    complex double a = gsl_interp_eval(gs->wx_spline_re,gs->k, gs->Wxr, kc,gs->w_accel)+I*gsl_interp_eval(gs->wx_spline_im,gs->k,gs->Wxi,kc,gs->w_accel);
	    double b = gsl_interp_eval_deriv(gs->phi_spline,gs->k, gs->phi, kc,gs->phi_accel);
	    omega[q]=b;
	    double damp = exp(-4*pow(fabs(kc),4)/denom);
	    
	    g->x[q]=a*damp;
	    
	    complex double c = gsl_interp_eval(gs->wy_spline_re,gs->k,gs->Wyr,kc,gs->w_accel)+I*gsl_interp_eval(gs->wy_spline_im,gs->k,gs->Wyi,kc,gs->w_accel);
	    g->y[q]=c*damp;
	    
	    complex double d = gsl_interp_eval(gs->wz_spline_re,gs->k,gs->Wzr,kc,gs->w_accel)+I*gsl_interp_eval(gs->wz_spline_im,gs->k,gs->Wzi,kc,gs->w_accel);
	    g->z[q]=d*damp;
	    
	    q++;
	}
    g_timer_stop(gstimer);
    
	return g;
}
コード例 #2
0
ファイル: pdfpres.c プロジェクト: betagram/pdfPres
/* Starts, pauses  and continues the timer */
static void toggleTimer()
{
	if (prefs.timer_is_clock)
		return;

	switch (timerMode)
	{
		case 0:
			timer = g_timer_new();
			timerMode = 1;
			gtk_widget_set_sensitive(GTK_WIDGET(resetButton), FALSE);
			gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(startButton),
					GTK_STOCK_MEDIA_PAUSE);
			break;
		case 1:
			g_timer_stop(timer);
			timerMode = 2;
			gtk_widget_set_sensitive(GTK_WIDGET(resetButton), TRUE);
			gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(startButton),
					GTK_STOCK_MEDIA_PLAY);
			break;
		case 2:
			g_timer_continue(timer);
			timerMode = 1;
			gtk_widget_set_sensitive(GTK_WIDGET(resetButton), FALSE);
			gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(startButton),
					GTK_STOCK_MEDIA_PAUSE);
			break;
	}
}
コード例 #3
0
ファイル: gamma-spline.c プロジェクト: jwahlstrand/kdotp-fke
complex double * gamma_spline_V(GammaSpline *gs, GList * const sd, double kc, int component)
{
    if (!gstimer) {
        gstimer = g_timer_new();
        g_timer_start(gstimer);
    }
    else g_timer_continue(gstimer);
    
    int NB = model->total_bands;
    
    complex double * V = complex_double_array_calloc (NB*NB);
    
    size_t m, n;

    for (m=0;m<NB;m++) {
        for (n=0;n<NB;n++) {
            gamma_spline_reset(gs,sd,m,n,FALSE);
            if (component==0) {
                V[m+n*NB]=gsl_interp_eval(gs->wx_spline_re,gs->k,gs->Wxr,kc,gs->w_accel)+I*gsl_interp_eval(gs->wx_spline_im,gs->k,gs->Wxi,kc,gs->w_accel);
            }
            else if (component==1) {
                V[m+n*NB]=gsl_interp_eval(gs->wy_spline_re,gs->k,gs->Wyr,kc,gs->w_accel)+I*gsl_interp_eval(gs->wy_spline_im,gs->k,gs->Wyi,kc,gs->w_accel);
            }
            else if (component==2) {
                V[m+n*NB]=gsl_interp_eval(gs->wz_spline_re,gs->k,gs->Wzr,kc,gs->w_accel)+I*gsl_interp_eval(gs->wz_spline_im,gs->k,gs->Wzi,kc,gs->w_accel);
            }
        }
    }
    g_timer_stop(gstimer);
    return V;
}
コード例 #4
0
ファイル: shd-scheduler.c プロジェクト: desphunter/shadow
Event* scheduler_pop(Scheduler* scheduler) {
    MAGIC_ASSERT(scheduler);

    /* this function should block until a non-null event is available for the worker to run.
     * return NULL only to signal the worker thread to quit */

    while(scheduler->isRunning) {
        /* pop from a queue based on the policy */
        Event* nextEvent = scheduler->policy->pop(scheduler->policy, scheduler->currentRound.endTime);

        if(nextEvent != NULL) {
            /* we have an event, let the worker run it */
            return nextEvent;
        } else if(scheduler->policyType == SP_SERIAL_GLOBAL) {
            /* the running thread has no more events to execute this round, but we only have a
             * single, global, serial queue, so returning NULL without blocking is OK. */
            return NULL;
        } else {
            /* the running thread has no more events to execute this round and we need to block it
             * so that we can wait for all threads to finish events from this round. We want to
             * track idle times, so let's start by making sure we have timer elements in place. */
            GTimer* executeEventsBarrierWaitTime = g_hash_table_lookup(scheduler->threadToWaitTimerMap, GUINT_TO_POINTER(pthread_self()));

            /* wait for all other worker threads to finish their events too, and track wait time */
            if(executeEventsBarrierWaitTime) {
                g_timer_continue(executeEventsBarrierWaitTime);
            }
            countdownlatch_countDownAwait(scheduler->executeEventsBarrier);
            if(executeEventsBarrierWaitTime) {
                g_timer_stop(executeEventsBarrierWaitTime);
            }

            /* now all threads reached the current round end barrier time.
             * asynchronously collect some stats that the main thread will use. */
            if(scheduler->policy->getNextTime) {
                SimulationTime nextTime = scheduler->policy->getNextTime(scheduler->policy);
                g_mutex_lock(&(scheduler->globalLock));
                scheduler->currentRound.minNextEventTime = MIN(scheduler->currentRound.minNextEventTime, nextTime);
                g_mutex_unlock(&(scheduler->globalLock));
            }

            /* clear all log messages from the last round */
            logger_flushRecords(logger_getDefault(), pthread_self());

            /* wait for other threads to finish their collect step */
            countdownlatch_countDownAwait(scheduler->collectInfoBarrier);

            /* now wait for main thread to process a barrier update for the next round */
            countdownlatch_countDownAwait(scheduler->prepareRoundBarrier);
        }
    }

    /* scheduler is done, return NULL to stop worker */
    return NULL;
}
コード例 #5
0
ファイル: stopclock.c プロジェクト: tohn/slinp
static void timer_start(struct application_info *app)
{
	if (app->timer.state == TIMER_DEAD)
	{
		app->timer.gtimer = g_timer_new();
		app->timer.state = TIMER_RUNNING;
	}
	else if (app->timer.state == TIMER_PAUSED)
	{
		g_timer_continue(app->timer.gtimer);
		app->timer.state = TIMER_RUNNING;
	}
}
コード例 #6
0
gboolean
timings_start (Timings* t)
{
	TimingsPrivate* priv;

	// sanity checks
	if (!t)
		return FALSE;

	priv = GET_PRIVATE (t);
	if (!priv)
		return FALSE;

	// if we have been started already return early
	if (priv->is_started)
	{
		if (g_getenv ("DEBUG"))
			g_print ("\n*** WARNING: Already started!\n");

		return FALSE;
	}

	// install and start the two timeout-handlers
	priv->timeout_id = g_timeout_add (priv->scheduled_duration,
					  _emit_completed,
					  (gpointer) t);
	priv->max_timeout_id = g_timeout_add (priv->max_duration,
					      _emit_limit_reached,
					      (gpointer) t);

	// let the on-screen- and duration-timers tick
	g_timer_continue (priv->on_screen_timer);
	g_timer_continue (priv->duration_timer);

	// indicate that we started
	priv->is_started = TRUE;

	return TRUE;
}
コード例 #7
0
ファイル: gui.c プロジェクト: vincentdoba/LPlayer
int play(GtkWidget *button, struct arguments *argument) {

    ALenum format;
    ALuint buffer;
    alGetSourcei(source, AL_SOURCE_STATE, &status);

    if(argument->first == 1)
        InitOpenAL();

    if(status == 0 || status == AL_STOPPED) {
        argument->first = 0;
        alDeleteBuffers(1, &buffer);
        alSourcei(source, AL_BUFFER, 0);
        alDeleteSources(1, &source);
        g_timer_start(argument->elapsed);
        alGenBuffers(1, &buffer);
        alGenSources(1, &source);

        format = AL_FORMAT_STEREO16;
        alBufferData(buffer, format, current_sample_array, nSamples * sizeof(ALint), sample_rate);

        alSourcei(source, AL_BUFFER, buffer);
        alSourcePlay(source);
        g_source_remove(argument->tag);
        if(argument->endless_check || argument->continue_count != 0) {
            argument->tag = g_timeout_add_seconds(current_song.duration, endless, argument);
        }
        argument->bartag = g_timeout_add_seconds(1, timer_progressbar, argument);
        return 0;
    }

    if(status == AL_PLAYING) {
        if(argument->endless_check) {
            g_timer_stop(argument->elapsed);
            g_source_remove(argument->tag);
        }
        alSourcePause(source);
        return 0;
    }
    else {
        alSourcePlay(source);
        if(argument->endless_check) {
            g_timer_continue(argument->elapsed);
            argument->tag = g_timeout_add_seconds(current_song.duration - (int)g_timer_elapsed(argument->elapsed, NULL), endless, argument->label);
        }
        return 0;
    }
}
コード例 #8
0
ファイル: fm-progress-dlg.c プロジェクト: lxde/libfm
static FmJobErrorAction on_error(FmFileOpsJob* job, GError* err, FmJobErrorSeverity severity, FmProgressDisplay* data)
{
    GtkTextIter it;
    if(err->domain == G_IO_ERROR)
    {
        if(err->code == G_IO_ERROR_CANCELLED)
            return FM_JOB_ABORT;
        else if(err->code == G_IO_ERROR_FAILED_HANDLED)
            return FM_JOB_CONTINUE;
    }

    if(data->timer)
        g_timer_stop(data->timer);

    data->has_error = TRUE;

    ensure_dlg(data);

/*
    FIXME: Need to mount volumes on demand here, too.
    if( err->domain == G_IO_ERROR )
    {
        if( err->code == G_IO_ERROR_NOT_MOUNTED && severity < FM_JOB_ERROR_CRITICAL )
            if(fm_mount_path(parent, dest_path))
                return FM_JOB_RETRY;
    }
*/

    gtk_text_buffer_get_end_iter(data->error_buf, &it);
    if(data->cur_file == NULL)
        g_warning("FmProgressDialog on_error: assertion `cur_file != NULL' failed");
    if(data->cur_file || data->old_cur_file)
    {
        gtk_text_buffer_insert_with_tags(data->error_buf, &it,
                                     data->cur_file ? data->cur_file : data->old_cur_file,
                                     -1, data->bold_tag, NULL);
        gtk_text_buffer_insert(data->error_buf, &it, _(": "), -1);
    }
    gtk_text_buffer_insert(data->error_buf, &it, err->message, -1);
    gtk_text_buffer_insert(data->error_buf, &it, "\n", 1);

    if(!gtk_widget_get_visible(data->error_pane))
        gtk_widget_show(data->error_pane);

    if(data->timer)
        g_timer_continue(data->timer);
    return FM_JOB_CONTINUE;
}
コード例 #9
0
gboolean
timings_continue (Timings* t)
{
	TimingsPrivate* priv;
	guint           extension;

	// sanity checks
	if (!t)
		return FALSE;

	priv = GET_PRIVATE (t);
	if (!priv)
		return FALSE;

	// only if we have been started it makes sense to move on
	if (!priv->is_started)
	{
		if (g_getenv ("DEBUG"))
			g_print ("\n*** WARNING: Can't continue something, "
				 "which is not started yet!\n");

		return FALSE;
	}

	// don't continue if we are not paused
	if (!priv->is_paused)
	{
		if (g_getenv ("DEBUG"))
			g_print ("\n*** WARNING: Already running!\n");

		return FALSE;
	}

	// make duration-timer tick again, hold paused-timer and update flag
	g_timer_continue (priv->duration_timer);
	g_timer_stop (priv->paused_timer);
	priv->is_paused = FALSE;

	// put new timeout in place
	extension = priv->scheduled_duration -
		    _ms_elapsed (priv->duration_timer);
	priv->timeout_id = g_timeout_add (extension,
					  _emit_completed,
					  (gpointer) t);
	g_assert (priv->timeout_id != 0);

	return TRUE;
}
コード例 #10
0
static void _schedulerpolicyhoststeal_push(SchedulerPolicy* policy, Event* event, Host* srcHost, Host* dstHost, SimulationTime barrier) {
    MAGIC_ASSERT(policy);
    HostStealPolicyData* data = policy->data;

    /* non-local events must be properly delayed so the event wont show up at another host
     * before the next scheduling interval. if the thread scheduler guaranteed to always run
     * the minimum time event accross all of its assigned hosts, then we would only need to
     * do the time adjustment if the srcThread and dstThread are not identical. however,
     * the logic of this policy allows a thread to run all events from a given host before
     * moving on to the next host, so we must adjust the time whenever the srcHost and
     * dstHost are not the same. */
    SimulationTime eventTime = event_getTime(event);

    if(srcHost != dstHost && eventTime < barrier) {
        event_setTime(event, barrier);
        info("Inter-host event time %"G_GUINT64_FORMAT" changed to %"G_GUINT64_FORMAT" "
                "to ensure event causality", eventTime, barrier);
    }

    g_rw_lock_reader_lock(&data->lock);
    /* we want to track how long this thread spends idle waiting to push the event */
    HostStealThreadData* tdata = g_hash_table_lookup(data->threadToThreadDataMap, GUINT_TO_POINTER(pthread_self()));

    /* get the queue for the destination */
    HostStealQueueData* qdata = g_hash_table_lookup(data->hostToQueueDataMap, dstHost);
    g_rw_lock_reader_unlock(&data->lock);
    utility_assert(qdata);

    /* tracking idle time spent waiting for the destination queue lock */
    if(tdata) {
        g_timer_continue(tdata->pushIdleTime);
        g_mutex_lock(&(tdata->lock));
    }
    g_mutex_lock(&(qdata->lock));
    if(tdata) {
        g_timer_stop(tdata->pushIdleTime);
    }

    /* 'deliver' the event to the destination queue */
    priorityqueue_push(qdata->pq, event);
    qdata->nPushed++;

    /* release the destination queue lock */
    g_mutex_unlock(&(qdata->lock));
    if(tdata) {
        g_mutex_unlock(&(tdata->lock));
    }
}
コード例 #11
0
gboolean
timings_pause (Timings* t)
{
	TimingsPrivate* priv;
	gboolean        removed_successfully;

	// sanity checks
	if (!t)
		return FALSE;

	priv = GET_PRIVATE (t);
	if (!priv)
		return FALSE;

	// only if we have been started it makes sense pause
	if (!priv->is_started)
	{
		if (g_getenv ("DEBUG"))
			g_print ("\n*** WARNING: Can't pause something, which "
				 " is not started yet!\n");

		return FALSE;
	}

	// don't halt if we are already paused
	if (priv->is_paused)
	{
		if (g_getenv ("DEBUG"))
			g_print ("\n*** WARNING: Already paused!\n");

		return FALSE;
	}

	// make paused-timer tick again, hold duration-timer and update flag
	g_timer_continue (priv->paused_timer);
	g_timer_stop (priv->duration_timer);
	priv->is_paused = TRUE;

	// try to get rid of old timeout
	removed_successfully = g_source_remove (priv->timeout_id);
	g_assert (removed_successfully);

	return TRUE;
}
コード例 #12
0
ファイル: signal_handler.c プロジェクト: rooi-oog/STM32_PID
G_MODULE_EXPORT
void save_to_flash_btn_clicked_cb ()
{	
	print_status ("Flash write in progress...");
	
	void wait (gulong wait_us)
	{
		gulong timer_us = 0;		
		GTimer *timer = g_timer_new ();
		g_timer_start (timer);
		while (timer_us < wait_us)
		{	
			g_timer_stop (timer);
			timer_us = g_timer_elapsed (timer, NULL);
			g_timer_continue (timer);
			gtk_main_iteration_do (FALSE);
		}
		g_timer_destroy (timer);
	}	
コード例 #13
0
ファイル: gtktimeline.c プロジェクト: Pfiver/gtk
/**
 * gtk_timeline_start:
 * @timeline: A #GtkTimeline
 *
 * Runs the timeline from the current frame.
 **/
void
_gtk_timeline_start (GtkTimeline *timeline)
{
  GtkTimelinePriv *priv;
  GtkSettings *settings;
  gboolean enable_animations = FALSE;

  g_return_if_fail (GTK_IS_TIMELINE (timeline));

  priv = timeline->priv;

  if (!priv->source_id)
    {
      if (priv->timer)
        g_timer_continue (priv->timer);
      else
        priv->timer = g_timer_new ();

      /* sanity check */
      g_assert (priv->fps > 0);

      if (priv->screen)
        {
          settings = gtk_settings_get_for_screen (priv->screen);
          g_object_get (settings, "gtk-enable-animations", &enable_animations, NULL);
        }

      priv->animations_enabled = enable_animations;

      g_signal_emit (timeline, signals [STARTED], 0);

      if (enable_animations)
        priv->source_id = gdk_threads_add_timeout (FRAME_INTERVAL (priv->fps),
                                                   (GSourceFunc) gtk_timeline_run_frame,
                                                   timeline);
      else
        priv->source_id = gdk_threads_add_idle ((GSourceFunc) gtk_timeline_run_frame,
                                                timeline);
    }
}
コード例 #14
0
ファイル: ev-timeline.c プロジェクト: linuxmint/xreader
static void
ev_timeline_real_start (EvTimeline *timeline)
{
	EvTimelinePriv *priv;

	priv = EV_TIMELINE_GET_PRIV (timeline);

	if (!priv->source_id) {
		if (priv->timer)
			g_timer_continue (priv->timer);
		else
			priv->timer = g_timer_new ();

		/* sanity check */
		g_assert (priv->fps > 0);

		g_signal_emit (timeline, signals [STARTED], 0);

		priv->source_id = g_timeout_add (FRAME_INTERVAL (priv->fps),
						 (GSourceFunc) ev_timeline_run_frame,
						 timeline);
	}
}
コード例 #15
0
ファイル: emulate.c プロジェクト: CZ-NIC/dionaea
void emulate_thread(gpointer data, gpointer user_data)
{
	struct emu_emulate_ctx *ctx = user_data;
	struct emu_config *conf = ctx->config;
	struct emu *e = ctx->emu;
	struct emu_env *env = ctx->env;
	int ret;

	g_mutex_lock(&ctx->mutex);

	if( ctx->state == waiting )
		ctx->state = running;


	if( ctx->time == NULL )
		ctx->time = g_timer_new();
	else
		g_timer_continue(ctx->time);

	while( ctx->state == running )
	{
		if( (ctx->steps % (1024*1024)) == 0 )
		{
			g_debug("steps %li", ctx->steps);
			if( ctx->steps > conf->limits.steps )
			{
				g_info("shellcode took too many steps ... (%li steps)",  ctx->steps);
				ctx->state = failed;
				break;
			}
			if( conf->limits.cpu > 0. )
			{
				double elapsed = g_timer_elapsed(ctx->time, NULL);
				if( elapsed > conf->limits.cpu )
				{
					g_info("shellcode took too long ... (%f seconds)",  elapsed);
					ctx->state = failed;
					break;
				}
			}
		}
		ctx->steps++;
		struct emu_env_hook *hook = NULL;
		hook = emu_env_w32_eip_check(env);

		if( hook != NULL )
		{
			if( hook->hook.win->fnhook == NULL )
			{
				g_critical("unhooked call to %s", hook->hook.win->fnname);
				break;
			} else
				if( ctx->state == waiting )
				/* for now, we stop!
				 * had a blocking io call
				 * callback from main will come at a given point
				 * and requeue us to the threadpool
				 */
				goto unlock_and_return;
		} else
		{
			ret = emu_cpu_parse(emu_cpu_get(e));
			struct emu_env_hook *hook =NULL;
			if( ret != -1 )
			{
				hook = emu_env_linux_syscall_check(env);
				if( hook == NULL )
				{
					ret = emu_cpu_step(emu_cpu_get(e));
				} else
				{
					if( hook->hook.lin->fnhook != NULL )
					{
						hook->hook.lin->fnhook(env, hook);
						if( ctx->state == waiting )
							/* stop 
							 * as mentioned previously
							 */
							goto unlock_and_return;
					}
				}
			}

			if( ret == -1 )
			{
				g_debug("cpu error %s", emu_strerror(e));
				break;
			}
		}
	}

	g_timer_stop(ctx->time);

	if( ctx->state == failed )
		g_debug("emulating shellcode failed");

	g_mutex_unlock(&ctx->mutex);

#ifdef DEBUG
	double elapsed = g_timer_elapsed(ctx->time, NULL);
	g_debug("shellcode took %f seconds on cpu, %li steps", elapsed, ctx->steps);
#endif

	GAsyncQueue *aq = g_async_queue_ref(g_dionaea->threads->cmds);
	g_async_queue_push(aq, async_cmd_new(emulate_ctx_free, ctx));
	g_async_queue_unref(aq);
	ev_async_send(g_dionaea->loop, &g_dionaea->threads->trigger);
	return;


	unlock_and_return:
	g_timer_stop(ctx->time);
	g_mutex_unlock(&ctx->mutex);
}
コード例 #16
0
ファイル: fm-progress-dlg.c プロジェクト: afilmore/libfmcore
static gint on_ask_rename (FmFileOpsJob *job, FmFileInfo *src, FmFileInfo *dest, char **new_name, FmProgressDisplay *data)
{
    int res;
    GtkBuilder *builder = gtk_builder_new ();
    GtkWidget *dlg, *src_icon, *dest_icon, *src_fi, *dest_fi, *filename, *apply_all;
    char *tmp;
    const char *disp_size;

    // return default operation if the user has set it
    if (data->default_opt)
        return data->default_opt;

    if (data->timer)
        g_timer_stop (data->timer);

    gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
    ensure_dlg (data);

    gtk_builder_add_from_string  (builder, RENAME_DLG, -1, NULL);
    dlg =       (GtkWidget*)gtk_builder_get_object (builder, "dlg");
    src_icon =  (GtkWidget*)gtk_builder_get_object (builder, "src_icon");
    src_fi =    (GtkWidget*)gtk_builder_get_object (builder, "src_fi");
    dest_icon = (GtkWidget*)gtk_builder_get_object (builder, "dest_icon");
    dest_fi =   (GtkWidget*)gtk_builder_get_object (builder, "dest_fi");
    filename =  (GtkWidget*)gtk_builder_get_object (builder, "filename");
    apply_all = (GtkWidget*)gtk_builder_get_object (builder, "apply_all");
    
    gtk_window_set_transient_for (GTK_WINDOW (dlg), (GtkWindow*) data->dlg);

    gtk_image_set_from_gicon (GTK_IMAGE (src_icon), fm_file_info_get_gicon (src), GTK_ICON_SIZE_DIALOG);
    disp_size = fm_file_info_get_disp_size (src);
    if (disp_size)
    {
        tmp = g_strdup_printf (_("Type: %s\nSize: %s\nModified: %s"),
                              fm_file_info_get_desc (src),
                              disp_size,
                              fm_file_info_get_disp_mtime (src));
    }
    else
    {
        tmp = g_strdup_printf (_("Type: %s\nModified: %s"),
                              fm_file_info_get_desc (src),
                              fm_file_info_get_disp_mtime (src));
    }

    gtk_label_set_text (GTK_LABEL (src_fi), tmp);
    g_free (tmp);

    gtk_image_set_from_gicon (GTK_IMAGE (dest_icon), fm_file_info_get_gicon (src), GTK_ICON_SIZE_DIALOG);
    disp_size = fm_file_info_get_disp_size (dest);
    if (disp_size)
    {
        tmp = g_strdup_printf (_("Type: %s\nSize: %s\nModified: %s"),
                              fm_file_info_get_desc (dest),
                              fm_file_info_get_disp_size (dest),
                              fm_file_info_get_disp_mtime (dest));
    }
    else
    {
        tmp = g_strdup_printf (_("Type: %s\nModified: %s"),
                              fm_file_info_get_desc (dest),
                              fm_file_info_get_disp_mtime (dest));
    }

    gtk_label_set_text (GTK_LABEL (dest_fi), tmp);
    g_free (tmp);

    tmp = g_filename_display_name (dest->path->name);
    gtk_entry_set_text (GTK_ENTRY (filename), tmp);
    g_free (tmp);
    
    g_object_set_data (G_OBJECT (filename), "old_name", dest->disp_name);
    g_signal_connect (filename, "changed", (GCallback) on_filename_changed, gtk_builder_get_object (builder, "rename"));

    g_object_unref (builder);

    res = gtk_dialog_run (GTK_DIALOG (dlg));
    switch (res)
    {
        case RESPONSE_RENAME:
            *new_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (filename)));
            res = FM_FILE_OP_RENAME;
        break;
        
        case RESPONSE_OVERWRITE:
            res = FM_FILE_OP_OVERWRITE;
        break;
        
        case RESPONSE_SKIP:
            res = FM_FILE_OP_SKIP;
        break;
        
        default:
            res = FM_FILE_OP_CANCEL;
    }

    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (apply_all)))
    {
        if (res == RESPONSE_OVERWRITE || res == FM_FILE_OP_SKIP)
            data->default_opt = res;
    }

    gtk_widget_destroy (dlg);

    if (data->timer)
        g_timer_continue (data->timer);

    return res;
}
コード例 #17
0
static gint on_ask_rename(FmFileOpsJob* job, FmFileInfo* src, FmFileInfo* dest, char** new_name, FmProgressDisplay* data)
{
    int res;
    GtkBuilder* builder;
    GtkDialog *dlg;
    GtkImage *src_icon, *dest_icon;
    GtkLabel *src_fi, *dest_fi;
    GtkEntry *filename;
    GtkToggleButton *apply_all;
    char* tmp;
    const char* disp_size;
    FmPath* path;
    FmIcon* icon;

    /* return default operation if the user has set it */
    if(data->default_opt)
        return data->default_opt;

    builder = gtk_builder_new();
    path = fm_file_info_get_path(dest);
    icon = fm_file_info_get_icon(src);

    if(data->timer)
        g_timer_stop(data->timer);

    gtk_builder_set_translation_domain(builder, GETTEXT_PACKAGE);
    ensure_dlg(data);

    gtk_builder_add_from_file(builder, PACKAGE_UI_DIR "/ask-rename.ui", NULL);
    dlg = GTK_DIALOG(gtk_builder_get_object(builder, "dlg"));
    src_icon = GTK_IMAGE(gtk_builder_get_object(builder, "src_icon"));
    src_fi = GTK_LABEL(gtk_builder_get_object(builder, "src_fi"));
    dest_icon = GTK_IMAGE(gtk_builder_get_object(builder, "dest_icon"));
    dest_fi = GTK_LABEL(gtk_builder_get_object(builder, "dest_fi"));
    filename = GTK_ENTRY(gtk_builder_get_object(builder, "filename"));
    apply_all = GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "apply_all"));
    gtk_window_set_transient_for(GTK_WINDOW(dlg), GTK_WINDOW(data->dlg));

    gtk_image_set_from_gicon(src_icon, icon->gicon, GTK_ICON_SIZE_DIALOG);
    disp_size = fm_file_info_get_disp_size(src);
    if(disp_size)
    {
        tmp = g_strdup_printf(_("Type: %s\nSize: %s\nModified: %s"),
                              fm_file_info_get_desc(src),
                              disp_size,
                              fm_file_info_get_disp_mtime(src));
    }
    else
    {
        tmp = g_strdup_printf(_("Type: %s\nModified: %s"),
                              fm_file_info_get_desc(src),
                              fm_file_info_get_disp_mtime(src));
    }

    gtk_label_set_text(src_fi, tmp);
    g_free(tmp);

    gtk_image_set_from_gicon(dest_icon, icon->gicon, GTK_ICON_SIZE_DIALOG);
    disp_size = fm_file_info_get_disp_size(dest);
    if(disp_size)
    {
        tmp = g_strdup_printf(_("Type: %s\nSize: %s\nModified: %s"),
                              fm_file_info_get_desc(dest),
                              fm_file_info_get_disp_size(dest),
                              fm_file_info_get_disp_mtime(dest));
    }
    else
    {
        tmp = g_strdup_printf(_("Type: %s\nModified: %s"),
                              fm_file_info_get_desc(dest),
                              fm_file_info_get_disp_mtime(dest));
    }

    gtk_label_set_text(dest_fi, tmp);
    g_free(tmp);

    tmp = g_filename_display_name(fm_path_get_basename(path));
    gtk_entry_set_text(filename, tmp);
    g_free(tmp);
    tmp = (char*)fm_file_info_get_disp_name(dest); /* FIXME: cast const to char */
    g_object_set_data(G_OBJECT(filename), "old_name", tmp);
    g_signal_connect(filename, "changed", G_CALLBACK(on_filename_changed), gtk_builder_get_object(builder, "rename"));

    g_object_unref(builder);

    res = gtk_dialog_run(dlg);
    switch(res)
    {
    case RESPONSE_RENAME:
        *new_name = g_strdup(gtk_entry_get_text(filename));
        res = FM_FILE_OP_RENAME;
        break;
    case RESPONSE_OVERWRITE:
        res = FM_FILE_OP_OVERWRITE;
        break;
    case RESPONSE_SKIP:
        res = FM_FILE_OP_SKIP;
        break;
    default:
        res = FM_FILE_OP_CANCEL;
    }

    if(gtk_toggle_button_get_active(apply_all))
    {
        if(res == RESPONSE_OVERWRITE || res == FM_FILE_OP_SKIP)
            data->default_opt = res;
    }

    gtk_widget_destroy(GTK_WIDGET(dlg));

    if(data->timer)
        g_timer_continue(data->timer);

    return res;
}
コード例 #18
0
ファイル: coeffs-pert.c プロジェクト: jwahlstrand/kdotp-fke
GList * calc_w_phi_coeffs (const ThreeVector * kperp, const ThreeVector * direction) {
    if(!cptimer) {  /* optimization timer */
        cptimer = g_timer_new();
        g_timer_start(cptimer);
    }
    else {
        g_timer_continue(cptimer);
    }
    
    cp_init();

    g_message ("starting calc_w_phi: {%1.2e, %1.2e}", kperp->x[0], kperp->x[1]);

    if (model->total_bands == 2) /* for checking the two-band PBA model */
        return calc_w_phi_constP (kperp);
    
    double te, he, kc;
    
    size_t qq;
    
	gboolean failed = FALSE;
	
	size_t NB = model->total_bands;
	size_t N2 = (model->total_bands)*(model->total_bands);
	
	pert_ode * po = pert_ode_init (NB);
	
	// generate basis vectors e, f, g
	
	const ThreeVector *g = direction;
	const ThreeVector *e = three_vector_e (g);
	const ThreeVector *f = three_vector_f (g, e);
	
	g_message ("e is %1.2e, %1.2e, %1.2e", e->x[0], e->x[1], e->x[2]);
	g_message ("f is %1.2e, %1.2e, %1.2e", f->x[0], f->x[1], f->x[2]);
	g_message ("g is %1.2e, %1.2e, %1.2e", g->x[0], g->x[1], g->x[2]);
	
	// get kperp in basis x, y, z
	ThreeVector *kperp2 = three_vector_new (0,0,0);
	kperp2->x[0] = kperp->x[0]*e->x[0] + kperp->x[1]*f->x[0] + kperp->x[2]*g->x[0];
	kperp2->x[1] = kperp->x[0]*e->x[1] + kperp->x[1]*f->x[1] + kperp->x[2]*g->x[1];
	kperp2->x[2] = kperp->x[0]*e->x[2] + kperp->x[1]*f->x[2] + kperp->x[2]*g->x[2];
	
    if (trajectory_intersects_bad (kperp2, direction)) {
        g_timer_stop(cptimer);
        return NULL;
    }
	
	complex double * H;
	
	// set up ODE solver
	
	po->syse.function = cfuncall;
	
    odeparams params;
    po->syse.params = (void *) &params;
	
    te = 0.0;//, kc1 = KCMAX/5;
    he = 5e-7;
    
    double * call;
    complex double *callc;
	
    H = model->H(kperp2);
    double * eigval = eigenvalues_herm (H, model->total_bands);
    gsl_matrix_complex * eigvec = eigenvectors_herm (H, model->total_bands);
    m_free(H);
    size_t m, n;
    call = double_array_calloc (2*NB*NB+NB);
    callc = (complex double*) call;
    for (m=0;m<NB;m++) {
        for (n=0;n<NB;n++) {
            callc[m*NB+n]=*(complex double *)(eigvec->data + 2*(m * eigvec->tda + n));
        }
        call[2*NB*NB+m]=eigval[m];
    }
        
    d_free(eigval);
    gsl_matrix_complex_free(eigvec);
        
    params.kperp = *three_vector_copy (kperp2);
    po->syse.params = (void *) &params;
    
	params.pos = TRUE;
	params.dir = *g;
	
	/* make a copy of the initial condition because we will need it to go negative */
	
	double * cinit = double_array_clone(call,2*N2+NB);
	
	// make list of points, add first point
    
    GList * pointlist = g_list_append (NULL, matrix_element_create_from_coeffs(kperp, callc, 0.0));
	
    // evolve in positive g direction
    
    g_message("going in g direction");
	
    te = 0.0;//, kc1 = KCMAX/5;
    he = 5e-7;
    
    qq=1;
    double dkc=5e-5;
    
	for (kc=dkc*COARSENESS;kc<=KCMAX;kc=kc+dkc*COARSENESS) {  // coarse loop for ODE solver for W - positive kc
	  while (te < kc && !failed) {
	    pert_ode_evolve (po, &te, kc, &he, call);
      ThreeVector *kpar = three_vector_copy(direction);
      three_vector_scale(kpar,te);
      ThreeVector *kval = three_vector_add(kperp2,kpar);
      pointlist = g_list_prepend (pointlist, matrix_element_create_from_coeffs(kval, callc, te));
      
      if (qq>100000) {  /* danger with adaptive solver is it might get stuck */
        failed=TRUE;  /* this detects whether the number of points is getting too high */
        g_warning("calc_w_phi_coeffs:  ode solver ran away, positive direction");
      }
      qq++;
	  }
	}
	
	pointlist = g_list_reverse (pointlist); // reverse list
	
	pert_ode_reset(po);  // reset the ode solver, initial condition
	
	d_free(call);
	call = cinit;
	callc = (complex double*) call;
	
	// evolve in negative g direction
	
    params.pos = FALSE;

    qq=0;
    te=0;
    he=5e-7;
    
    for (kc=dkc*COARSENESS;kc<=KCMAX;kc=kc+dkc*COARSENESS) {
	    while (te < kc && !failed) {
    	 	pert_ode_evolve (po, &te, kc, &he, call);
    	 	ThreeVector *kpar = three_vector_copy(direction);
            three_vector_scale(kpar,-te);
            ThreeVector *kval = three_vector_add(kperp2,kpar);
            pointlist = g_list_prepend (pointlist, matrix_element_create_from_coeffs(kval, callc, -te));
    	 	
    	 	if (qq>100000) {
	        	failed=TRUE;
	    	    g_warning("calc_w_phi_coeffs:  ode solver ran away, negative direction");
	    	}
	    	qq++;
    	}
    }
	
	pert_ode_free(po);
	
	d_free(call);
	
    g_timer_stop(cptimer);  /* optimization timer */
	
    m_free(wc);
    if(dHx)
      m_free(dHx);
    if(dHy)
      m_free(dHy);
    if(dHz)
      m_free(dHz);

	return pointlist;
}
コード例 #19
0
static Event* _schedulerpolicyhoststeal_pop(SchedulerPolicy* policy, SimulationTime barrier) {
    MAGIC_ASSERT(policy);
    HostStealPolicyData* data = policy->data;

    /* first, we try to pop a host from this thread's queue */
    g_rw_lock_reader_lock(&data->lock);
    HostStealThreadData* tdata = g_hash_table_lookup(data->threadToThreadDataMap, GUINT_TO_POINTER(pthread_self()));
    g_rw_lock_reader_unlock(&data->lock);

    /* if there is no tdata, that means this thread didn't get any hosts assigned to it */
    if(!tdata) {
        /* this thread will remain idle */
        return NULL;
    }

    /* we only need to lock this thread's lock, since it's our own queue */
    g_timer_continue(tdata->popIdleTime);
    g_mutex_lock(&(tdata->lock));
    g_timer_stop(tdata->popIdleTime);

    if(barrier > tdata->currentBarrier) {
        tdata->currentBarrier = barrier;

        /* make sure all of the hosts that were processed last time get processed in the next round */
        if(g_queue_is_empty(tdata->unprocessedHosts) && !g_queue_is_empty(tdata->processedHosts)) {
            GQueue* swap = tdata->unprocessedHosts;
            tdata->unprocessedHosts = tdata->processedHosts;
            tdata->processedHosts = swap;
        } else {
            while(!g_queue_is_empty(tdata->processedHosts)) {
                g_queue_push_tail(tdata->unprocessedHosts, g_queue_pop_head(tdata->processedHosts));
            }
        }
    }
    /* attempt to get an event from this thread's queue */
    Event* nextEvent = _schedulerpolicyhoststeal_popFromThread(policy, tdata, tdata->unprocessedHosts, barrier);
    g_mutex_unlock(&(tdata->lock));
    if(nextEvent != NULL) {
        return nextEvent;
    }

    /* no more hosts with events on this thread, try to steal a host from the other threads' queues */
    GHashTableIter iter;
    gpointer key, value;
    g_rw_lock_reader_lock(&data->lock);
    guint i, n = data->threadCount;
    g_rw_lock_reader_unlock(&data->lock);
    for(i = 1; i < n; i++) {
        guint stolenTnumber = (i + tdata->tnumber) % n;
        g_rw_lock_reader_lock(&data->lock);
        HostStealThreadData* stolenTdata = g_array_index(data->threadList, HostStealThreadData*, stolenTnumber);
        g_rw_lock_reader_unlock(&data->lock);
        /* We don't need a lock here, because we're only reading, and a misread just means either
         * we read as empty when it's not, in which case the assigned thread (or one of the others)
         * will pick it up anyway, or it reads as non-empty when it is empty, in which case we'll
         * just get a NULL event and move on. Accepting this reduces lock contention towards the end
         * of every round. */
        if(g_queue_is_empty(stolenTdata->unprocessedHosts)) {
            continue;
        }
        /* We need to lock the thread we're stealing from, to be sure that we're not stealing
         * something already being stolen, as well as our own lock, to be sure nobody steals
         * what we just stole. But we also need to do this in a well-ordered manner, to
         * prevent deadlocks. To do this, we always lock the lock with the smaller thread
         * number first. */
        g_timer_continue(tdata->popIdleTime);
        if(tdata->tnumber < stolenTnumber) {
            g_mutex_lock(&(tdata->lock));
            g_mutex_lock(&(stolenTdata->lock));
        } else {
            g_mutex_lock(&(stolenTdata->lock));
            g_mutex_lock(&(tdata->lock));
        }
        g_timer_stop(tdata->popIdleTime);

        /* attempt to get event from the other thread's queue, likely moving a host from its
         * unprocessedHosts into this threads runningHost (and eventually processedHosts) */
        nextEvent = _schedulerpolicyhoststeal_popFromThread(policy, tdata, stolenTdata->unprocessedHosts, barrier);

        /* must unlock in reverse order of locking */
        if(tdata->tnumber < stolenTnumber) {
            g_mutex_unlock(&(stolenTdata->lock));
            g_mutex_unlock(&(tdata->lock));
        } else {
            g_mutex_unlock(&(tdata->lock));
            g_mutex_unlock(&(stolenTdata->lock));
        }

        if(nextEvent != NULL) {
            break;
        }
    }
    return nextEvent;
}
コード例 #20
0
ファイル: scrobbler-module.c プロジェクト: sdelafond/mpdcron
static void
song_continued(void)
{
	g_timer_continue(timer);
}