00001
00002 #if CMK_SMP && CMK_LEVERAGE_COMMTHREAD
00003
00020
00021 CsvDeclare(PCQueue, notifyCommThdMsgBuffer);
00022 CpvDeclare(int, notifyCommThdHdlr);
00023
00024 static void commThdHandleNotification(CmiNotifyCommThdMsg *msg){
00025 msg->fn(msg->numParams, msg->params);
00026 if(!msg->toKeep) CmiFreeNotifyCommThdMsg(msg);
00027 }
00028
00029
00030 void CmiInitNotifyCommThdScheme(){
00031 CpvInitialize(int, notifyCommThdHdlr);
00032 CpvAccess(notifyCommThdHdlr) = CmiRegisterHandler((CmiHandler)commThdHandleNotification);;
00033
00034 if(CmiMyRank() == CmiMyNodeSize()){
00035 int i;
00036 CsvAccess(notifyCommThdMsgBuffer) = PCQueueCreate();
00037 PCQueue q = CsvAccess(notifyCommThdMsgBuffer);
00038
00039 for(i=0; i<16; i++) {
00040 CmiNotifyCommThdMsg *one = (CmiNotifyCommThdMsg *)malloc(sizeof(CmiNotifyCommThdMsg));
00041 CmiSetHandler(one, CpvAccess(notifyCommThdHdlr));
00042 CmiBecomeImmediate(one);
00043 PCQueuePush(q, (char *)one);
00044 }
00045 }
00046 CmiNodeAllBarrier();
00047 }
00048
00049
00050 CmiNotifyCommThdMsg *CmiCreateNotifyCommThdMsg(CmiCommThdFnPtr fn, int numParams, void *params, int toKeep){
00051 CmiNotifyCommThdMsg *one = (CmiNotifyCommThdMsg *)PCQueuePop(CsvAccess(notifyCommThdMsgBuffer));
00052 if(one == NULL) {
00053 one = (CmiNotifyCommThdMsg *)malloc(sizeof(CmiNotifyCommThdMsg));
00054 CmiSetHandler(one, CpvAccess(notifyCommThdHdlr));
00055 CmiBecomeImmediate(one);
00056 }
00057 one->fn = fn;
00058 one->numParams = numParams;
00059 one->params = params;
00060 one->toKeep = toKeep;
00061 return one;
00062 }
00063
00064 void CmiFreeNotifyCommThdMsg(CmiNotifyCommThdMsg *msg){
00065 free(msg->params);
00066
00067 PCQueuePush(CsvAccess(notifyCommThdMsgBuffer), (char *)msg);
00068 }
00069
00070
00071 void CmiResetNotifyCommThdMsg(CmiNotifyCommThdMsg *msg, CmiCommThdFnPtr fn, int numParams, void *params, int toKeep){
00072 msg->fn = fn;
00073 msg->numParams = numParams;
00074 msg->params = params;
00075 msg->toKeep = toKeep;
00076 }
00077
00078 void CmiNotifyCommThd(CmiNotifyCommThdMsg *msg){
00079 CmiPushImmediateMsg(msg);
00080 }
00081
00082 #endif