+
+
+void clearDeadThreadsNotification()
+{
+
+#ifdef DEBUG
+ printf("%s -> Entered\n",__func__);
+#endif
+// clear all the threadnotify request first
+
+ if(waitThreadID != -1) {
+#ifdef DEBUG
+ printf("%s -> I was waitng for %s\n",__func__,midtoIPString(waitThreadMid));
+#endif
+ int waitThreadIndex = findHost(waitThreadMid);
+ int i;
+ notifydata_t *ndata;
+
+ if(liveHosts[waitThreadIndex] == 0) // the thread waiting for is dead
+ {
+ if((ndata = (notifydata_t*)notifyhashSearch(waitThreadID)) == NULL) {
+ return;
+ }
+
+ for(i =0 ; i < ndata->numoid; i++) {
+ clearNotifyList(ndata->oidarry[i]); // clear thread object's notifylist
+ }
+
+ pthread_mutex_lock(&(ndata->threadnotify));
+ pthread_cond_signal(&(ndata->threadcond));
+ pthread_mutex_unlock(&(ndata->threadnotify));
+
+ waitThreadMid = -1;
+ waitThreadID = -1;
+ }
+ }
+
+#ifdef DEBUG
+ printf("%s -> Finished\n",__func__);
+#endif
+}
+
+/* request the primary and the backup machines to clear
+ thread obj's notify list */
+void reqClearNotifyList(unsigned int oid)
+{
+ int psock,bsock,i;
+ int mid,pmid,bmid;
+ objheader_t *objheader;
+ struct sockaddr_in premoteAddr, bremoteAddr;
+ char msg[1 + sizeof(unsigned int)];
+
+ if((mid = lhashSearch(oid)) == 0) {
+ printf("%s -> No such machine found for oid %x\n",__func__,oid);
+ return;
+ }
+
+ pmid = getPrimaryMachine(mid);
+ bmid = getBackupMachine(mid);
+
+ if((psock = socket(AF_INET, SOCK_STREAM, 0)) < 0 ||
+ (bsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+ perror("clearNotifyList() : socket()");
+ return ;
+ }
+
+ /* for primary machine */
+ bzero(&premoteAddr, sizeof(premoteAddr));
+ premoteAddr.sin_family = AF_INET;
+ premoteAddr.sin_port = htons(LISTEN_PORT);
+ premoteAddr.sin_addr.s_addr = htonl(pmid);
+
+ /* for backup machine */
+ bzero(&bremoteAddr, sizeof(bremoteAddr));
+ bremoteAddr.sin_family = AF_INET;
+ bremoteAddr.sin_port = htons(LISTEN_PORT);
+ bremoteAddr.sin_addr.s_addr = htonl(bmid);
+
+ /* send message to both the primary and the backup */
+ if((connect(psock, (struct sockaddr *)&premoteAddr, sizeof(premoteAddr)) < 0) ||
+ (connect(bsock, (struct sockaddr *)&bremoteAddr, sizeof(bremoteAddr)) < 0)) {
+ printf("%s -> error in connecting\n",__func__);
+ return;
+ }
+ else {
+ printf("%s -> Pmid = %s\n",__func__,midtoIPString(pmid));
+ printf("%s -> Bmid = %s\n",__func__,midtoIPString(bmid));
+
+ msg[0] = CLEAR_NOTIFY_LIST;
+ *((unsigned int *)(&msg[1])) = oid;
+
+ send_data(psock, &msg, sizeof(char) + sizeof(unsigned int));
+ send_data(bsock, &msg, sizeof(char) + sizeof(unsigned int));
+ }
+
+ close(psock);
+ close(bsock);
+
+}
+
+
+int checkiftheMachineDead(unsigned int mid) {
+ int mIndex = findHost(mid);
+ return getStatus(mIndex);
+}
+
+#endif