Skip to content

Commit

Permalink
found out how to make gtk 'thread-aware'... good enough.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil Samith Bysani committed Dec 23, 2008
1 parent 9e1c480 commit 4717e11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -6,7 +6,7 @@ EXENAME=bang-machine

CC=gcc
COPTS=-Wall -Werror -g -D_REENTRANT -lpthread
GTKOPTS=`pkg-config --cflags --libs gtk+-2.0`
GTKOPTS=`pkg-config --cflags --libs gtk+-2.0` -lgthread-2.0

OBJS=bang-com.o bang-net.o bang-signals.o bang-module.o core.o main.o

Expand Down
15 changes: 11 additions & 4 deletions src/app/main.c
Expand Up @@ -32,6 +32,7 @@
#include"../base/bang-types.h"
#include<stdio.h>
#include<stdlib.h>
#include<glib.h>
#include<gtk/gtk.h>

GtkWidget *window;
Expand All @@ -55,20 +56,24 @@ GtkWidget *ssserver;
* NOTE: GTK IS NOT THREAD SAFE! Umm, let me think how we should fix this.
*/
void bind_status(int signal, int sig_id, void *args) {
//guint context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar),"bind_status");
//gtk_statusbar_pop(GTK_STATUSBAR(statusbar),context_id);
gdk_threads_enter();
guint context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar),"bind_status");
gtk_statusbar_pop(GTK_STATUSBAR(statusbar),context_id);
if (signal == BANG_BIND_SUC) {
//gtk_statusbar_push(GTK_STATUSBAR(statusbar),context_id,"!bang Machine has been bound.");
gtk_statusbar_push(GTK_STATUSBAR(statusbar),context_id,"!bang Machine has been bound.");
} else {
//gtk_statusbar_push(GTK_STATUSBAR(statusbar),context_id,"!bang Machine could not bind.");
gtk_statusbar_push(GTK_STATUSBAR(statusbar),context_id,"!bang Machine could not bind.");
}
gdk_threads_leave();
free(args);
}

void client_con(int signal, int sig_id, void *args) {
gdk_threads_enter();
guint context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar),"peer_status");
gtk_statusbar_pop(GTK_STATUSBAR(statusbar),context_id);
gtk_statusbar_push(GTK_STATUSBAR(statusbar),context_id,"A peer has connected.");
gdk_threads_leave();
free(args);
}

Expand Down Expand Up @@ -109,6 +114,8 @@ int main(int argc, char **argv) {

///Note: gtk expects that as a process, you do not need to free its memory
///So, it lets the operating system free all memory when the process closes.
g_thread_init(NULL);
gdk_threads_init();
gtk_init(&argc,&argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
Expand Down

0 comments on commit 4717e11

Please sign in to comment.