|
发表于 2004-6-10 10:12:40
|
显示全部楼层
我的代码:
[code:1]
static int curadsnum;
//static int mutex_flag = 1;
static int parent_status;
static pthread_t thread_id;
static int thread_status;
G_LOCK_DEFINE_STATIC(belocked);
static volatile int belocked = 0;
....
void *change_begin(void *obj)
{
assert(obj);
struct frontend *meobj = (struct frontend *)obj;
GdkPixbuf *bgPf = NULL;
int adsnumber = ((struct frontend_data*)meobj->data)->adsnumber;
char abadsimg[8092];
gboolean canRun;
for(;;)
{
/* sleep a while */
sleep(20);
/* lock the yes_or_no_variable */
G_LOCK(belocked);
/* do we have to say something? */
canRun = (belocked != parent_status);
if(canRun)
{
/* set the variable */
belocked = parent_status;
}
/* Unlock the yes_or_no variable */
G_UNLOCK(belocked);
if(canRun)
{
/* get GTK thread lock */
gdk_threads_enter ();
printf("current adsnum is: %d. \n", curadsnum);
memset(abadsimg, 0, sizeof(abadsimg));
strcat(abadsimg, ADSDIR);
strcat(abadsimg, ((struct frontend_data*)meobj->data)->adsimage[curadsnum]);
printf("the ad image is: %s\n", abadsimg);
bgPf = gdk_pixbuf_new_from_file(abadsimg, NULL);
if(bgPf != NULL)
gtk_image_set_from_pixbuf(GTK_IMAGE(((struct frontend_data*)meobj->data)->\
backgndImg), bgPf);
else
printf("bgPf is NULL. PLZ check.\n");
curadsnum++;
if (curadsnum > (adsnumber-2))
curadsnum = 1;
printf("next ads number is:%d.\n", curadsnum);
gtk_widget_show_all(((struct frontend_data*)meobj->data)->commonWin);
while (gtk_events_pending ())
gtk_main_iteration ();
/* release GTK thread lock */
gdk_threads_leave ();
}
}
printf("current parent status is:%d\n", parent_status);
pthread_exit(NULL);
return NULL;
}
....
static void gtk_progress_start(struct frontend *obj, int min, int max, const char *title)
{
printf("\nHEADER: %s, %s, %d\n", __FUNCTION__, __FILE__, __LINE__ );
assert(obj);
assert(title);
.......
while (gtk_events_pending ())
gtk_main_iteration ();
/* create change ad.Img thread */
parent_status = 1;
curadsnum = 1;
thread_status = pthread_create(&thread_id, NULL, change_begin,(void *)obj);
/* debug */
printf("TAILER: %s, %s, %d\n", __FUNCTION__, __FILE__, __LINE__ );
}
[/code:1]
我还在测试,这是目前的代码。 |
|