/** * @brief Set the callback associated with the execution. * @param _xid [in] The xid we want. * @param _callback [in] The callback we want to associate. */ PUBLIC void PROCESSOR_RegisterCallback(IN XID _xid, IN fProcessorCallback _callback) { if((TO_INDEX(_xid) < MAX_EXECUTIONS) && processor[TO_INDEX(_xid)].used) { processor[TO_INDEX(_xid)].callback = _callback; } }
/** * @brief This method deallocates an used xid. If the execution only used that xid, it is also deleted. * @param _xid [in] The XID of the execution we want to delete. */ PUBLIC void PROCESSOR_DeleteExecution(IN XID _xid) { if(TO_INDEX(_xid) < MAX_EXECUTIONS && processor[TO_INDEX(_xid)].used) { //Free the slot processor[TO_INDEX(_xid)].used = false; //Decrease the number of executions processor_slices_used--; //Let's see if we need to free also the execution dword i = 0; for(; i < MAX_EXECUTIONS; i++) { if(i!=TO_INDEX(_xid) && processor[i].execution == processor[TO_INDEX(_xid)].execution) break; } if(i == MAX_EXECUTIONS) { //It was the only execution... delete DEBUG("CPU: Freeing Execution"); CPU_FreeExecution(processor[TO_INDEX(_xid)].execution); } //Zero fields processor[TO_INDEX(_xid)].execution = 0; processor[TO_INDEX(_xid)].environment = 0; processor[TO_INDEX(_xid)].callback = 0; } }
/* Insert a non-null-terminated string and a value the size of a machine word. Return 0 on success. */ int insert(char *string, int len, int value) { Word_t *pvalue; TO_INDEX(string, len); JSLI(pvalue, trie, Index); if (pvalue == NULL) return -1; *pvalue = (Word_t)value; return 0; }
/** * @brief This method allocates an empty slot and creates an execution that will run on it. * @param _desired_xid [in] The xid we want, or XID_ANY if doesnt mind. * @param _execution [in] The state of the task. * @param _environment [in] The environment associated. * @return The xid (eXecution ID) newly allocated. */ PUBLIC XID PROCESSOR_CreateNewExecution(IN XID _desired_xid, IN EXECUTION* _execution, IN ENVIRONMENT* _environment) { if(_desired_xid == XID_ANY) { //Search in the vector of executions for(dword i = 0; i < MAX_EXECUTIONS; i++) { //If it is empty... if(!processor[i].used) { _desired_xid = i; break; } } if(_desired_xid == XID_ANY) { //No empty room found return 0; } _desired_xid = TO_HANDLE(_desired_xid); } //If it is empty... if(!processor[TO_INDEX(_desired_xid)].used) { //Allocate processor[TO_INDEX(_desired_xid)].used = true; //Assign the slice processor[TO_INDEX(_desired_xid)].execution = _execution; processor[TO_INDEX(_desired_xid)].environment = _environment; processor[TO_INDEX(_desired_xid)].callback = 0; //Increase the number of executions processor_slices_used++; //Return XID return _desired_xid; } //Couldn't succeed return 0; }
/** * @brief This method allocates an empty slot for an existing execution. * @param _desired_xid [in] The xid we would like. * @param _xid [in] The xid of the execution we want to give more cpu. * @return The xid (eXecution ID) newly allocated. */ PUBLIC XID PROCESSOR_AssignNewExecution(IN XID _desired_xid, IN XID _xid) { if(_desired_xid == XID_ANY) { //Search the executions' vector for(dword i = 0; i < MAX_EXECUTIONS; i++) { //If it's empty... if(!processor[i].used) { _desired_xid = i; break; } } if(_desired_xid == XID_ANY) { //No empty room found return 0; } _desired_xid = TO_HANDLE(_desired_xid); } //If it's empty... if(!processor[TO_INDEX(_desired_xid)].used) { //Allocate processor[TO_INDEX(_desired_xid)].used = true; //Copy processor[TO_INDEX(_desired_xid)].execution = processor[TO_INDEX(_xid)].execution; processor[TO_INDEX(_desired_xid)].environment = processor[TO_INDEX(_xid)].environment; processor[TO_INDEX(_desired_xid)].callback = processor[TO_INDEX(_xid)].callback; //Increase the number of executions processor_slices_used++; //Return the XID return _desired_xid; } return 0; }
//---------------------------------------------------------------------- // //---------------------------------------------------------------------- ObjectEntry* Manager::getObjectEntry(LNHandle handle) { return &mObjectEntryArray[TO_INDEX(handle)]; }