00001
00002 #if CMK_SMP && CMK_LEVERAGE_COMMTHREAD
00003
00020
00021 CsvDeclare(CMIQueue, 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(void){
00031 CpvInitialize(int, notifyCommThdHdlr);
00032 CpvAccess(notifyCommThdHdlr) = CmiRegisterHandler((CmiHandler)commThdHandleNotification);;
00033
00034 if(CmiMyRank() == CmiMyNodeSize()){
00035 int i;
00036 CsvAccess(notifyCommThdMsgBuffer) = CMIQueueCreate();
00037 CMIQueue 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 CMIQueuePush(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 *)CMIQueuePop(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 CMIQueuePush(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 extern "C" void CmiPushImmediateMsg(void *);
00079
00080 void CmiNotifyCommThd(CmiNotifyCommThdMsg *msg){
00081 CmiPushImmediateMsg(msg);
00082 }
00083
00084 #endif