static void* messageHandler(void *arg) { MessageHeader *header = (MessageHeader*)arg; printf("Start Message Handler: %s!\n", header->tag); while (1) { pending(); printf("waitting!\n"); test(header->fd); Message *msg = popupMessage(header, 0); if (NULL != msg) { fire(header->cb, (void*)msg); } /* pthread_mutex_lock(&(header->mutex)); if (p->next == NULL) { printf("Empty Message Queue...\n"); } else { printf("yuzhou debug\n"); p->next = q->next; //应该增加一个线程通知 //popupMessage(); fire(cb, (void*)q); //cb((void*)q); } pthread_mutex_unlock(&(header->mutex)); */ } return NULL; }
int WINAPI newMessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType) { if (CallService(MS_POPUP_QUERY, PUQS_GETSTATUS, 0) == CALLSERVICE_NOTFOUND || (uType & 0x0F)) return prevMessageBox(hWnd, lpText, lpCaption, uType); popupMessage(lpText, lpCaption, uType); return IDOK; }
void* writeThreadHandler(void* p) { ShareResourceOfWriteAndMainThread* pShareResource = (ShareResourceOfWriteAndMainThread*) p; struct timespec waitInterval; Message* pMsg; while(1){ pMsg = NULL; clock_gettime(CLOCK_REALTIME, &waitInterval); waitInterval.tv_sec += 2; if(pthread_mutex_timedlock(&(pShareResource->mutex),&waitInterval)){ //if(pShareResource->rank == 0){ printf("child thread wait timed out. Will terminat session.\n"); }else{ pMsg = popupMessage(&(pShareResource->msgList)); pthread_mutex_unlock(&(pShareResource->mutex)); } if(pMsg){ printf("------MyRank:%d, writeThread message:%d\n", pShareResource->myRank, pMsg->type); // printMessage(pMsg); // sleep(1); Packet packet = {pMsg->type, pMsg->size}; int dataBytes = pMsg->size; if(pMsg->type == STEP1_STATISTICS || pMsg->type == STEP2_STATISTICS){ dataBytes = sizeof(Statistics) * pMsg->size; } void* buffer = (void*) calloc (sizeof(Packet) + dataBytes, sizeof(char)); memcpy(buffer, (void*)&packet, sizeof(Packet)); if(pMsg->data){ memcpy(buffer + sizeof(Packet), pMsg->data, dataBytes); free(pMsg->data); } free(pMsg); MPI_Send(buffer, sizeof(Packet) + dataBytes, MPI_CHAR, pMsg->receiver, 0, MPI_COMM_WORLD); free(buffer); }else{ if(pShareResource->keepWriting){ usleep(1000); }else{ break; } } } printf("------MyRank:%d write thread finished\n", pShareResource->myRank); pShareResource->isWriting = 0; return NULL; }
Qtwitter::Qtwitter( QWidget *parent ) : MainWindow( parent ) { connect( this, SIGNAL(switchModel(QString)), SLOT(setCurrentModel(QString)) ); connect( this, SIGNAL(switchToPublicTimelineModel()), SLOT(setPublicTimelineModel()) ); core = new Core( this ); connect( this, SIGNAL(updateTweets()), core, SLOT(forceGet()) ); connect( this, SIGNAL(openBrowser(QUrl)), core, SLOT(openBrowser(QUrl)) ); connect( this, SIGNAL(post(QString,QString,int)), core, SLOT(post(QString,QString,int)) ); connect( this, SIGNAL(resizeView(int,int)), core, SIGNAL(resizeData(int,int))); connect( this, SIGNAL(shortenUrl(QString)), core, SLOT(shortenUrl(QString))); connect( core, SIGNAL(twitterAccountsChanged(QList<TwitterAccount>,bool)), this, SLOT(setupTwitterAccounts(QList<TwitterAccount>,bool)) ); connect( core, SIGNAL(urlShortened(QString)), this, SLOT(replaceUrl(QString))); connect( core, SIGNAL(about()), this, SLOT(about()) ); connect( core, SIGNAL(addReplyString(QString,int)), this, SIGNAL(addReplyString(QString,int)) ); connect( core, SIGNAL(addRetweetString(QString)), this, SIGNAL(addRetweetString(QString)) ); connect( core, SIGNAL(errorMessage(QString)), this, SLOT(popupError(QString)) ); connect( core, SIGNAL(resetUi()), this, SLOT(resetStatusEdit()) ); connect( core, SIGNAL(requestStarted()), this, SLOT(showProgressIcon()) ); if ( QSystemTrayIcon::supportsMessages() ) connect( core, SIGNAL(sendNewsReport(QString)), this, SLOT(popupMessage(QString)) ); twitpic = new TwitPicView( this ); connect( twitpic, SIGNAL(uploadPhoto(QString,QString,QString)), core, SLOT(uploadPhoto(QString,QString,QString)) ); connect( twitpic, SIGNAL(abortUpload()), core, SLOT(abortUploadPhoto()) ); connect( this, SIGNAL(openTwitPicDialog()), twitpic, SLOT(show()) ); connect( core, SIGNAL(twitPicResponseReceived()), twitpic, SLOT(resetForm()) ); connect( core, SIGNAL(twitPicDataSendProgress(int,int)), twitpic, SLOT(showUploadProgress(int,int)) ); settingsDialog = new Settings( this, core, twitpic, this ); connect( this, SIGNAL(settingsDialogRequested()), settingsDialog, SLOT( show() ) ); QSignalMapper *mapper = new QSignalMapper( this ); mapper->setMapping( qApp, 1 ); connect( qApp, SIGNAL(aboutToQuit()), mapper, SLOT(map()) ); connect( mapper, SIGNAL(mapped(int)), settingsDialog, SLOT(saveConfig(int)) ); }