00001 #include "ck.h"
00002 #include "queueing.h"
00003
00004 CkpvDeclare(size_t *, _offsets);
00005
00006 void *CkAllocSysMsg(const CkEntryOptions *opts)
00007 {
00008 if(opts == NULL)
00009 return CkpvAccess(_msgPool)->get();
00010
00011 envelope *env = _allocEnv(ForChareMsg, 0, opts->getPriorityBits(), GroupDepNum{(int)opts->getGroupDepNum()});
00012 setMemoryTypeMessage(env);
00013 env->setMsgIdx(0);
00014
00015 env->setIsVarSysMsg(1);
00016
00017 env->setQueueing((unsigned char)opts->getQueueing());
00018
00019
00020 if (opts->getPriorityPtr() != NULL)
00021 CmiMemcpy(env->getPrioPtr(), opts->getPriorityPtr(), env->getPrioBytes());
00022
00023
00024 if(opts->getGroupDepNum() > 0)
00025 CmiMemcpy(env->getGroupDepPtr(), opts->getGroupDepPtr(), env->getGroupDepSize());
00026
00027 return EnvToUsr(env);
00028 }
00029
00030 void CkFreeSysMsg(void *m)
00031 {
00032 CkpvAccess(_msgPool)->put(m);
00033 }
00034
00035 void* CkAllocMsg(int msgIdx, int msgBytes, int prioBits, GroupDepNum groupDepNum)
00036 {
00037 envelope* env = _allocEnv(ForChareMsg, msgBytes, prioBits, groupDepNum);
00038 setMemoryTypeMessage(env);
00039
00040 env->setQueueing(_defaultQueueing);
00041 env->setMsgIdx(msgIdx);
00042
00043 return EnvToUsr(env);
00044 }
00045
00046 void* CkAllocBuffer(void *msg, int bufsize)
00047 {
00048 bufsize = CkMsgAlignLength(bufsize);
00049 envelope *env = UsrToEnv(msg);
00050 envelope *packbuf = _allocEnv(env->getMsgtype(), bufsize,
00051 env->getPriobits(),
00052 GroupDepNum{(int)env->getGroupDepNum()});
00053
00054 int size = packbuf->getTotalsize();
00055 CmiMemcpy(packbuf, env, sizeof(envelope));
00056 packbuf->setTotalsize(size);
00057 packbuf->setPacked(!env->isPacked());
00058 CmiMemcpy(packbuf->getPrioPtr(), env->getPrioPtr(), packbuf->getPrioBytes());
00059
00060 return EnvToUsr(packbuf);;
00061 }
00062
00063 void CkFreeMsg(void *msg)
00064 {
00065 if (msg!=NULL) {
00066 CmiFree(UsrToEnv(msg));
00067 }
00068 }
00069
00070
00071 void* CkCopyMsg(void **pMsg)
00072 {
00073 void *srcMsg = *pMsg;
00074 envelope *env = UsrToEnv(srcMsg);
00075 unsigned char msgidx = env->getMsgIdx();
00076 if(!env->isPacked() && _msgTable[msgidx]->pack) {
00077 srcMsg = _msgTable[msgidx]->pack(srcMsg);
00078 UsrToEnv(srcMsg)->setPacked(1);
00079 }
00080 int size = UsrToEnv(srcMsg)->getTotalsize();
00081 envelope *newenv = (envelope *) CmiAlloc(size);
00082 CmiMemcpy(newenv, UsrToEnv(srcMsg), size);
00083
00084 if(UsrToEnv(srcMsg)->isPacked() && _msgTable[msgidx]->unpack) {
00085 srcMsg = _msgTable[msgidx]->unpack(srcMsg);
00086 UsrToEnv(srcMsg)->setPacked(0);
00087 }
00088 *pMsg = srcMsg;
00089 if(newenv->isPacked() && _msgTable[msgidx]->unpack) {
00090 srcMsg = _msgTable[msgidx]->unpack(EnvToUsr(newenv));
00091 UsrToEnv(srcMsg)->setPacked(0);
00092 } else srcMsg = EnvToUsr(newenv);
00093
00094 setMemoryTypeMessage(newenv);
00095 return srcMsg;
00096 }
00097
00098 void CkSetQueueing(void *msg, int strategy)
00099 {
00100 UsrToEnv(msg)->setQueueing((unsigned char) strategy);
00101 }
00102
00103
00104 void* CkPriorityPtr(void *msg)
00105 {
00106 #if CMK_ERROR_CHECKING
00107 if (UsrToEnv(msg)->getPriobits() == 0) CkAbort("Trying to access priority bits, but none was allocated");
00108 #endif
00109 return UsrToEnv(msg)->getPrioPtr();
00110 }
00111
00112 CkMarshallMsg *CkAllocateMarshallMsgNoninline(int size,const CkEntryOptions *opts)
00113 {
00114
00115 CkMarshallMsg *m=new (size,opts->getPriorityBits(),GroupDepNum{(int)opts->getGroupDepNum()}) CkMarshallMsg;
00116
00117 envelope *env=UsrToEnv(m);
00118 setMemoryTypeMessage(env);
00119 if (opts->getPriorityPtr() != NULL)
00120 CmiMemcpy(env->getPrioPtr(),opts->getPriorityPtr(),env->getPrioBytes());
00121
00122
00123 if(opts->getGroupDepNum() > 0)
00124 CmiMemcpy(env->getGroupDepPtr(), opts->getGroupDepPtr(), env->getGroupDepSize());
00125
00126
00127 env->setQueueing((unsigned char)opts->getQueueing());
00128 return m;
00129 }
00130