gtk_tree_store_set stalls when using threads
- From: Sam <expires200310 software manicsadness com>
- To: gtk-app-devel-list gnome org
- Subject: gtk_tree_store_set stalls when using threads
- Date: 01 Jun 2003 16:23:39 +0200
Hello,
I have built a directory tree function and I'm using the
treeview_expanded signal to add subdirectories.
This works fine without threads, but when I use threads the program
stalls at random points. Since for now this is the only thread there
can't be any collisions.
I'm using GTK 2.2.1-6 and pthreads and I have initialized gdk_threads
using this:
...
g_thread_init(NULL);
gdk_threads_init();
gtk_init(&argc, &argv);
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
...
Below is my code, I hope it doesn't loose format.
I've added a comment at the point where it stalls.
Can anyone point me to what I'm doing wrong?
Thanks!
-Sam
-------------------------
void
on_treeview_addfiles_files_directories_row_expanded
(GtkTreeView *treeview,
GtkTreeIter *iter,
GtkTreePath *path,
gpointer user_data)
{
dirtree_expand(gtk_tree_view_get_model(treeview), path,
gui.showhidden);
}
void
dirtree_expand(GtkTreeModel *model, GtkTreePath *path, gboolean
showhidden)
{
GtkTreeIter parent;
GtkTreeIter child;
GtkTreeIter trash;
DIR *dirstream = NULL;
struct dirent *dirstruct = NULL;
gchar *directory = NULL;
gchar subdirectory[4096];
gchar *name = NULL;
/* Get the directory name of the given gtk path. */
if (!gtk_tree_model_get_iter(model, &parent, path)) {
fprintf(stderr, "Error: dirtree_expand(): Failed receiving the tree
iter.");
return;
}
gtk_tree_model_get(model, &parent, PATH_COLUMN, &directory, -1);
/* Open the directory. */
if (!(dirstream = opendir(directory))) {
printf("Error: dirtree_expand(): Failed opening path. (%s)\n",
directory);
return;
}
/* Look if there is only a dummy node under this parent. */
if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(model), &child,
&parent)) {
printf("Error: dirtree_expand(): Failed fetching the child
iter.\n");
return;
}
gtk_tree_model_get(GTK_TREE_MODEL(model), &child, DIR_COLUMN, &name,
-1);
/* Add each child-dir to the node. */
while ((dirstruct = readdir(dirstream)) != NULL) {
/* Don't show the relative directory links. */
if (strcmp(dirstruct->d_name, "..") == 0 ||
strcmp(dirstruct->d_name, ".") == 0)
continue;
/* Show hidden files? */
if (strncmp(dirstruct->d_name, ".", 1) == 0 && !showhidden)
continue;
/* Create a fullpath. */
snprintf(subdirectory, 4095, "%s%s", directory, dirstruct->d_name);
if (!is_dir(subdirectory))
continue;
strcpy(subdirectory + strlen(subdirectory), "/");
if (!name) {
/* If there is only a dummy node under parent, replace it's name.
*/
// ******************* THIS WORKS FINE ******************
gtk_tree_store_set(GTK_TREE_STORE(model), &child, DIR_COLUMN,
dirstruct->d_name, PATH_COLUMN, subdirectory, -1);
name = (gchar *)1; // Mark the variable as used.
}
else {
/* Add the new node. */
gtk_tree_store_append(GTK_TREE_STORE(model), &child, &parent);
printf("DIR: %s\n", subdirectory);
// ******************* STALL HERE *********************
gtk_tree_store_set(GTK_TREE_STORE(model), &child, DIR_COLUMN,
dirstruct->d_name, PATH_COLUMN, subdirectory, -1);
printf("Done\n");
}
/* If the current directory has a subdir, make the expander visible.
*/
if (!(has_subdir(subdirectory, showhidden)))
continue;
/* Show the expander by adding a dummy node. */
gtk_tree_store_append(GTK_TREE_STORE(model), &trash, &child);
}
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model),
DIR_COLUMN, GTK_SORT_ASCENDING);
closedir(dirstream);
}
-------------------------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]