Skip to content

Commit

Permalink
thread low priority exec io #107
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnorantGuru committed Jun 23, 2012
1 parent 68cf9aa commit 644f1f0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 55 deletions.
10 changes: 5 additions & 5 deletions src/main-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -2759,11 +2759,11 @@ static gboolean delayed_focus( GtkWidget* widget )
{
if ( GTK_IS_WIDGET( widget ) )
{
gdk_threads_enter();
///gdk_threads_enter();
//printf( "delayed_focus %#x\n", widget);
if ( GTK_IS_WIDGET( widget ) )
gtk_widget_grab_focus( widget );
gdk_threads_leave();
///gdk_threads_leave();
}
return FALSE;
}
Expand All @@ -2772,14 +2772,14 @@ static gboolean delayed_focus_file_browser( PtkFileBrowser* file_browser )
{
if ( GTK_IS_WIDGET( file_browser ) && GTK_IS_WIDGET( file_browser->folder_view ) )
{
gdk_threads_enter();
///gdk_threads_enter();
//printf( "delayed_focus_file_browser fb=%#x\n", file_browser );
if ( GTK_IS_WIDGET( file_browser ) && GTK_IS_WIDGET( file_browser->folder_view ) )
{
gtk_widget_grab_focus( file_browser->folder_view );
set_panel_focus( NULL, file_browser );
}
gdk_threads_leave();
///gdk_threads_leave();
}
return FALSE;
}
Expand Down Expand Up @@ -3223,7 +3223,7 @@ void on_file_browser_sel_change( PtkFileBrowser* file_browser,
void on_file_browser_content_change( PtkFileBrowser* file_browser,
FMMainWindow* main_window )
{
//printf("content_change panel %d\n", file_browser->mypanel );
printf("content_change panel %d\n", file_browser->mypanel );
fm_main_window_update_status_bar( main_window, file_browser );
}

Expand Down
15 changes: 8 additions & 7 deletions src/ptk/ptk-file-browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2172,6 +2172,7 @@ gboolean ptk_file_browser_chdir( PtkFileBrowser* file_browser,
}
else
file_browser->busy = TRUE;

g_signal_connect( file_browser->dir, "file-listed",
G_CALLBACK(on_dir_file_listed), file_browser );

Expand Down Expand Up @@ -2302,16 +2303,16 @@ void on_folder_content_update ( FolderContent* content,

static gboolean ptk_file_browser_content_changed( PtkFileBrowser* file_browser )
{
gdk_threads_enter();
//gdk_threads_enter(); not needed because g_idle_add runs in main loop thread
g_signal_emit( file_browser, signals[ CONTENT_CHANGE_SIGNAL ], 0 );
gdk_threads_leave();
//gdk_threads_leave();
return FALSE;
}

static void on_folder_content_changed( VFSDir* dir, VFSFileInfo* file,
PtkFileBrowser* file_browser )
{
g_idle_add( ( GSourceFunc ) ptk_file_browser_content_changed,
g_idle_add( ( GSourceFunc ) ptk_file_browser_content_changed,
file_browser );
}

Expand Down Expand Up @@ -3133,7 +3134,7 @@ static gboolean on_dir_tree_update_sel ( PtkFileBrowser* file_browser )

if ( !file_browser->side_dir )
return FALSE;
gdk_threads_enter();
//gdk_threads_enter(); //sfm not needed because g_idle_add runs in main loop thread
dir_path = ptk_dir_tree_view_get_selected_dir( GTK_TREE_VIEW(
file_browser->side_dir ) );

Expand All @@ -3150,7 +3151,7 @@ static gboolean on_dir_tree_update_sel ( PtkFileBrowser* file_browser )
}
g_free( dir_path );
}
gdk_threads_leave();
//gdk_threads_leave();
return FALSE;
}

Expand Down Expand Up @@ -4068,7 +4069,7 @@ gboolean on_folder_view_auto_scroll( GtkScrolledWindow* scroll )
GtkAdjustment * vadj;
gdouble vpos;

gdk_threads_enter();
//gdk_threads_enter(); //sfm why is this here?

vadj = gtk_scrolled_window_get_vadjustment( scroll ) ;
vpos = gtk_adjustment_get_value( vadj );
Expand All @@ -4090,7 +4091,7 @@ gboolean on_folder_view_auto_scroll( GtkScrolledWindow* scroll )
gtk_adjustment_set_value ( vadj, ( vadj->upper - vadj->page_size ) );
}

gdk_threads_leave();
//gdk_threads_leave();
return TRUE;
}

Expand Down
29 changes: 11 additions & 18 deletions src/ptk/ptk-file-task.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ printf("ptk_file_task_destroy ptask=%#x\n", ptask);
}
if ( ptask->task->type == VFS_FILE_TASK_EXEC )
{
//printf(" g_io_channel_shutdown\n");
printf(" g_io_channel_shutdown\n");
// channel shutdowns are needed to stop channel reads after task ends.
// Can't be placed in cb_exec_child_watch because it causes single
// line output to be lost
Expand All @@ -163,7 +163,7 @@ printf("ptk_file_task_destroy ptask=%#x\n", ptask);
if ( ptask->task->exec_channel_err )
g_io_channel_shutdown( ptask->task->exec_channel_err, TRUE, NULL );
ptask->task->exec_channel_out = ptask->task->exec_channel_err = 0;
//printf(" g_io_channel_shutdown DONE\n");
printf(" g_io_channel_shutdown DONE\n");
}

if ( ptask->task )
Expand Down Expand Up @@ -328,8 +328,13 @@ gboolean ptk_file_task_kill_cpids( char* cpids )

gboolean ptk_file_task_cancel( PtkFileTask* ptask )
{
GThread *self = g_thread_self ();
printf("CANCEL_THREAD = %#x\n", self );
//GThread *self = g_thread_self ();
//printf("CANCEL_THREAD = %#x\n", self );
if ( ptask->timeout )
{
g_source_remove( ptask->timeout );
ptask->timeout = 0;
}
ptask->aborted = TRUE;
if ( ptask->task->type == VFS_FILE_TASK_EXEC )
{
Expand Down Expand Up @@ -390,24 +395,12 @@ gboolean ptk_file_task_cancel( PtkFileTask* ptask )
ptk_file_task_run( ptask2 );
}
}
/*
//printf("ptk_file_task_cancel\n g_io_channel_shutdown\n");
// channel shutdowns are needed to stop channel reads after task ends.
// Can't be placed in cb_exec_child_watch because it causes single
// line output to be lost
if ( ptask->task->exec_channel_out )
g_io_channel_shutdown( ptask->task->exec_channel_out, TRUE, NULL );
if ( ptask->task->exec_channel_err )
g_io_channel_shutdown( ptask->task->exec_channel_err, TRUE, NULL );
ptask->task->exec_channel_out = ptask->task->exec_channel_err = 0;
//printf(" g_io_channel_shutdown DONE\n");
*/

if ( ptask->task->exec_cond )
{
g_mutex_lock( ptask->task->mutex );
if ( ptask->task->exec_cond )
g_cond_broadcast( ptask->task->exec_cond );
//g_cond_signal( ptask->task->exec_cond );
g_mutex_unlock( ptask->task->mutex );
}
}
Expand Down Expand Up @@ -1110,7 +1103,7 @@ printf("UPDATE LOCKED @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
if ( !ptask->progress_dlg && task->type == VFS_FILE_TASK_EXEC
&& task->exec_show_output )
{
//task->exec_show_output = FALSE; // only open once
task->exec_show_output = FALSE; // only open once
ptask->keep_dlg = TRUE;
ptk_file_task_progress_open( ptask );
}
Expand Down
6 changes: 3 additions & 3 deletions src/vfs/vfs-async-task.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ void vfs_async_task_finalize(GObject *object)
gboolean on_idle( gpointer _task )
{
VFSAsyncTask *task = VFS_ASYNC_TASK(_task);
GDK_THREADS_ENTER();
//GDK_THREADS_ENTER(); // not needed because this runs in main thread
vfs_async_thread_cleanup( task, FALSE );
GDK_THREADS_LEAVE();
//GDK_THREADS_LEAVE();
return TRUE; /* the idle handler is removed in vfs_async_thread_cleanup. */
}

Expand All @@ -147,7 +147,7 @@ gpointer vfs_async_task_thread( gpointer _task )
ret = task->func( task, task->user_data );

vfs_async_task_lock( task );
task->idle_id = g_idle_add( on_idle, task );
task->idle_id = g_idle_add( on_idle, task ); // runs in main loop thread
task->ret_val = ret;
task->finished = TRUE;
vfs_async_task_unlock( task );
Expand Down
45 changes: 23 additions & 22 deletions src/vfs/vfs-file-task.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,6 @@ static void cb_exec_child_cleanup( GPid pid, gint status, char* tmp_file )
static void cb_exec_child_watch( GPid pid, gint status, VFSFileTask* task )
{
gboolean bad_status = FALSE;
printf("child finished pid=%d exit_status=%d\n", pid, status);
g_spawn_close_pid( pid );
task->exec_pid = 0;

Expand All @@ -961,22 +960,23 @@ printf("child finished pid=%d exit_status=%d\n", pid, status);
if ( task->exec_script )
unlink( task->exec_script );
}

printf("child finished pid=%d exit_status=%d\n", pid,
bad_status ? -1 : task->exec_exit_status );
if ( !task->exec_exit_status && !bad_status )
{
task->percent = 100;
}
else
{
call_state_callback( task, VFS_FILE_TASK_ERROR );
}

if ( task->state_cb && !task->exec_channel_out && !task->exec_channel_err )
call_state_callback( task, VFS_FILE_TASK_FINISH );
}

static gboolean cb_exec_out_watch( GIOChannel *channel, GIOCondition cond,
VFSFileTask* task )
{
GThread *self = g_thread_self ();
printf("cb_exec_out_watch-THREAD = %#x\n", self );

/*
printf("cb_exec_out_watch %d\n", channel);
if ( cond & G_IO_IN )
Expand Down Expand Up @@ -1168,7 +1168,7 @@ char* get_sha256sum( char* path )
void vfs_file_task_exec_error( VFSFileTask* task, int errnox, char* action )
{
char* msg;

if ( errnox )
msg = g_strdup_printf( "%s\n%s\n", action, g_strerror( errnox ) );
else
Expand Down Expand Up @@ -1662,7 +1662,7 @@ printf("vfs_file_task_exec\n");

task->exec_pid = pid;

// catch termination
// catch termination - is run in the main loop thread
guint child_watch = g_child_watch_add( pid,
(GChildWatchFunc)cb_exec_child_watch, task );

Expand All @@ -1675,31 +1675,32 @@ printf("vfs_file_task_exec\n");
g_io_channel_set_close_on_unref( task->exec_channel_err, TRUE );

// Add watches to channels
g_io_add_watch( task->exec_channel_out, G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR, //want ERR?
(GIOFunc)cb_exec_out_watch, task );
//g_io_add_watch( task->exec_channel_out, G_IO_IN | G_IO_OUT | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL, (GIOFunc)cb_exec_out_watch, task );
g_io_add_watch( task->exec_channel_err, G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
(GIOFunc)cb_exec_out_watch, task );
// These are run in the main loop thread so use G_PRIORITY_LOW to not
// interfere with g_idle_add in vfs-dir/vfs-async-task etc
// "Use this for very low priority background tasks. It is not used within
// GLib or GTK+."
g_io_add_watch_full( task->exec_channel_out, G_PRIORITY_LOW,
G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR, //want ERR?
(GIOFunc)cb_exec_out_watch, task, NULL );
//g_io_add_watch( task->exec_channel_out, G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR, //want ERR?
// (GIOFunc)cb_exec_out_watch, task );
g_io_add_watch_full( task->exec_channel_err, G_PRIORITY_LOW,
G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR, //want ERR?
(GIOFunc)cb_exec_out_watch, task, NULL );
//g_io_add_watch( task->exec_channel_err, G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
// (GIOFunc)cb_exec_out_watch, task );

// running
task->state = VFS_FILE_TASK_RUNNING;
//call_progress_callback( task );

// wait for channels
// wait
printf("Waiting...\n");
task->exec_cond = g_cond_new();
g_mutex_lock( task->mutex );
g_cond_wait( task->exec_cond, task->mutex );
g_cond_free( task->exec_cond );
task->exec_cond = NULL;

// close channels
printf("Closing...\n");
if ( task->exec_channel_out )
g_io_channel_shutdown( task->exec_channel_out, TRUE, NULL );
if ( task->exec_channel_err )
g_io_channel_shutdown( task->exec_channel_err, TRUE, NULL );
task->exec_channel_out = task->exec_channel_err = 0;
g_source_remove( child_watch );
g_mutex_unlock( task->mutex );

Expand Down

0 comments on commit 644f1f0

Please sign in to comment.