Example #1
0
void	Prot_set_down_queue( int queue_type )
{
        switch(queue_type) {
        case NORMAL_DOWNQUEUE:
                Down_queue_ptr = &Protocol_down_queue[NORMAL_DOWNQUEUE];
                break;
        case GROUPS_DOWNQUEUE:
                Down_queue_ptr = &Protocol_down_queue[GROUPS_DOWNQUEUE];
                break;
        default:
                Alarm(EXIT, "Prot_set_down_queue: Illegal queue_type (%d)\n", queue_type);
        }
}
Example #2
0
//vrider borren 1 steg
int step(void){
	if(ML4IN &(2)){
		//är i toppläge
		Outone(1);
		Outone(0);
		hold((time_type)250);
		Outzero(0);
		hold((time_type)500);
		return 1; 
	}
	Alarm(2);
	return 0;
}
Example #3
0
int CMFPI::N_Close()
{
    int ret = m_apiCtrl.LFSAsyncClose(&m_CurrRequestID);

    if(LFS_SUCCESS!=ret)
	{
		LOGERROR("%s,关闭失败!错误码:ret = %d",__FUNCTION__,ret);
        Alarm("07000000");
        emit CloseFailed();
	}

	return ret;
}
Example #4
0
//执行LFS_CMD_IDC_Get_RAW_DATA
int CMFPI::N_ReadRawData(WORD readData,LONG timeout)
{
	m_FingerData = "";

	timeout = (-1==timeout) ? 0 : timeout;//

	if(timeout<0)
	{
        if ( readData == LFS_IDC_TRACK1)
		{
            emit IdentifyFailed();
		}
		else
		{
            emit DataAcquireFailed();
		}
		LOGERROR("%s,时间参数错误。设置了-1之外的负数,timeout = %d",__FUNCTION__,timeout);
        Alarm("07000001");
		return HM_PARAM_ERROR;
	}

    int ret=m_apiCtrl.LFSAsyncExecute(LFS_CMD_IDC_READ_RAW_DATA,&readData,timeout,&m_CurrRequestID);
    if(LFS_SUCCESS!=ret)
	{
        if ( readData == LFS_IDC_TRACK1)
		{
            emit IdentifyFailed();
		}
		else
		{
            emit DataAcquireFailed();
		}
		LOGERROR("%s,执行错误,错误码:ret = %d",__FUNCTION__,ret);
        Alarm("07000001");
	}

	return ret;
}
Example #5
0
sp_time	E_sub_time( sp_time t, sp_time delta_t )
{
	sp_time	res;

	res.sec  = t.sec  - delta_t.sec;
	res.usec = t.usec - delta_t.usec;
	if ( res.usec < 0 )
	{
		res.usec = res.usec + 1000000;
		res.sec--;
	} 
	if ( res.sec < 0 ) Alarm( EVENTS, "E_sub_time: negative time result.\n");
	return ( res );
}
Example #6
0
void ErrorHandler::CreateErrorMsg(const char *ArcName,const wchar *ArcNameW,const char *FileName,const wchar *FileNameW)
{
#ifndef SILENT
  if (FileName!=NULL)
    Log(ArcName,St(MCannotCreate),FileName);
  Alarm();

#if defined(_WIN_ALL) && !defined(_WIN_CE) && defined(MAX_PATH)
  CheckLongPathErrMsg(FileName,FileNameW);
#endif

  SysErrMsg();
#endif
}
Example #7
0
static sp_time E_get_time_monotonic(void)
#ifdef HAVE_CLOCK_GETTIME_CLOCK_MONOTONIC
{
  struct timespec t;

  if (clock_gettime(CLOCK_MONOTONIC, &t) != 0) {
    Alarm( EXIT, "E_get_time_monotonic: clock_gettime problems: %d '%s'\n", errno, strerror(errno) );
  }

  Now.sec  = t.tv_sec;
  Now.usec = (t.tv_nsec + 500) / 1000;

  return Now;
}
Example #8
0
// 收到打开完成消息后调用该函数
void  CMFPI::WR_OpenComplete(DWORD dwCommand, HRESULT hResult, LPVOID lpBuffer)
{
	//异步打开成功
    if(LFS_SUCCESS == hResult)
	{
		DWORD dwEvent = SERVICE_EVENTS | USER_EVENTS | SYSTEM_EVENTS | EXECUTE_EVENTS;
        int ret = m_apiCtrl.LFSAsyncRegister(dwEvent,&m_CurrRequestID);

        if(LFS_SUCCESS != ret)
		{
			N_Close();
            emit OpenFailed();
			LOGERROR("%s,注册事件失败,错误码:ret = %d",__FUNCTION__,ret);
            Alarm("07000000");
		}
	}
	else
	{
        emit OpenFailed();
		LOGERROR("%s,打开失败,错误码:hResult = %d",__FUNCTION__,hResult);
        Alarm("07000000");
	}
}
Example #9
0
int CMFPI::N_Open()
{
    int ret = m_apiCtrl.LFSAsyncOpen(m_szLogicalName,HM_MIDDLE_TIMEOUT,&m_CurrRequestID);

    if(LFS_SUCCESS!=ret)
	{
		LOGERROR("%s,打开失败!错误码:ret = %d",__FUNCTION__,ret);
        Alarm("07000000");
        emit OpenFailed();
	}
	/////获取产商
    m_Fpiprovider=help.GetPrivateProfileInt("MFPI","Fpiprovider",2,m_strConfigPath);

	return ret;
}
Example #10
0
void bhvm::execute_program (void)
{
    try{


        while (program_counter < int(program.size()))
        {
	    //std::cout << program[program_counter] << std::endl;    // debug... traza todo
            exec_instruction(program[program_counter]);
            ++program_counter;
        }
        signal_debug(Alarm(MTK_HERE, "bhvm",  MTK_SS("end of program." << std::endl << get_status()), alPriorDebug));


    } catch(const mtk::Alarm& error) {
        Alarm al(MTK_HERE, "bhvm",  get_status(), alPriorCritic);
        al.Add(error);
        signal_error(al);
    } catch (std::exception& e) {
        signal_error(Alarm(MTK_HERE, "bhvm",  MTK_SS("c++ exception " << e.what()  << get_status()), alPriorCritic));
    } catch(...) {
        signal_error(Alarm(MTK_HERE, "bhvm",  MTK_SS("unknown error  " << get_status()), alPriorCritic));
    }
}
Example #11
0
void handler(int sig)
{
	static int beeps = 0;

	if( beeps++ <5)
	{
		printf("beef\n");	
		Alarm(1);
	}
	else
	{
		printf("boom!\n");
		exit(0);
	}
}
Example #12
0
// 收到关闭完成消息后调用该函数
void CMFPI::WR_CloseComplete(DWORD dwCommand, HRESULT hResult, LPVOID lpBuffer)
{
    if(LFS_SUCCESS == hResult)
	{
		m_bOpened = false;
        emit ConnectionClosed();
		LOGINFO("%s,事件:ConnectionClosed()",__FUNCTION__);
	}
	else
	{
        emit CloseFailed();
		LOGERROR("%s,关闭设备失败,错误码:hResult = %d",__FUNCTION__,hResult);
        Alarm("07000000");
	}
}
Example #13
0
Property& Property::operator=(const Property& value) {
    if (type==value.type  ||  type==propTypeNone) {
        name = value.name;
        number=value.number;
        text = value.text;
        type = value.type;
        date = value.date;
        return *this;
    }
    else
        throw Alarm (
                    MTK_HERE, "property",
                    "Tipos no compatibles",
                    alPriorError, alTypeNoPermisions
                );
}
Example #14
0
void  CMFPI::WR_RegisterComplete(DWORD dwCommand, HRESULT hResult, LPVOID lpBuffer)
{
    if(LFS_SUCCESS != hResult)
	{
		N_Close();		
        emit OpenFailed();
		LOGERROR("%s,注册事件失败,错误码:hResult = %d",__FUNCTION__,hResult);
        Alarm("07000000");
	}
	else
	{
		m_bOpened = true;
        emit ConnectionOpened();
		LOGINFO("%s,事件:ConnectionOpened()",__FUNCTION__);
	}
}
Example #15
0
CountPtr< Signal<bhvm*> >
bhvm::register_external_command (const std::string& command)
{
    CountPtr< Signal<bhvm*> > new_signal = make_cptr(new Signal<bhvm*>());

    std::map    <std::string, CountPtr < Signal<bhvm*> > >::iterator it = map_signal_external_commands.find(command);
    if (it == map_signal_external_commands.end())
    {
        map_signal_external_commands.insert(std::make_pair(command, new_signal));
        map_signal_external_commands[command].DANGEROUS_ThisInstance_NOT_Delete();
    }
    else
        throw Alarm(MTK_HERE, "bhvm",  MTK_SS("command already registered "), alPriorCritic);

    return new_signal;
}
Example #16
0
File: drill.c Project: sumsarj/xcc
int Nstep(int a){   //a == antal steg att steppa
	int i;
	for(i = 0; i<a; i++){	//steppa a gånger
		if(0 == (BORR_STATUS & 0x2)){	//borren uppe?
			Alarm(2);
			return 0;
		}
		OutOne(1);
		hold((time_type)250);    //250 ms delay
		OutOne(0);
		hold((time_type)500);
		OutZero(0);
		
	}
	return 1;
}
Example #17
0
int Ask(const wchar *AskStr)
{
  Alarm();

  const int MaxItems=10;
  wchar Item[MaxItems][40];
  int ItemKeyPos[MaxItems],NumItems=0;

  for (const wchar *NextItem=AskStr;NextItem!=NULL;NextItem=wcschr(NextItem+1,'_'))
  {
    wchar *CurItem=Item[NumItems];
    wcsncpyz(CurItem,NextItem+1,ASIZE(Item[0]));
    wchar *EndItem=wcschr(CurItem,'_');
    if (EndItem!=NULL)
      *EndItem=0;
    int KeyPos=0,CurKey;
    while ((CurKey=CurItem[KeyPos])!=0)
    {
      bool Found=false;
      for (int I=0;I<NumItems && !Found;I++)
        if (toupperw(Item[I][ItemKeyPos[I]])==toupperw(CurKey))
          Found=true;
      if (!Found && CurKey!=' ')
        break;
      KeyPos++;
    }
    ItemKeyPos[NumItems]=KeyPos;
    NumItems++;
  }

  for (int I=0;I<NumItems;I++)
  {
    eprintf(I==0 ? (NumItems>4 ? L"\n":L" "):L", ");
    int KeyPos=ItemKeyPos[I];
    for (int J=0;J<KeyPos;J++)
      eprintf(L"%c",Item[I][J]);
    eprintf(L"[%c]%ls",Item[I][KeyPos],&Item[I][KeyPos+1]);
  }
  eprintf(L" ");
  wchar Str[50];
  getwstr(Str,ASIZE(Str));
  wchar Ch=toupperw(Str[0]);
  for (int I=0;I<NumItems;I++)
    if (Ch==Item[I][ItemKeyPos[I]])
      return I+1;
  return 0;
}
Example #18
0
void	E_delay( sp_time t )
{
	struct timeval 	tmp_t;

	tmp_t.tv_sec = t.sec;
	tmp_t.tv_usec = t.usec;

#ifndef ARCH_PC_WIN95
        if (select(0, NULL, NULL, NULL, &tmp_t ) < 0)
        {
                Alarm( EVENTS, "E_delay: select delay returned error: %s\n", strerror(errno));
        }
#else  /* ARCH_PC_WIN95 */
        SleepEx( tmp_t.tv_sec*1000+tmp_t.tv_usec/1000, 0 );
#endif /* ARCH_PC_WIN95 */   

}
Example #19
0
bool GetPassword(PASSWORD_TYPE Type,const char *FileName,char *Password,int MaxLength)
{
  Alarm();
  while (true)
  {
    char PromptStr[256];
#if defined(_EMX) || defined(_BEOS)
    strcpy(PromptStr,St(MAskPswEcho));
#else
    strcpy(PromptStr,St(MAskPsw));
#endif
    if (Type!=PASSWORD_GLOBAL)
    {
      strcat(PromptStr,St(MFor));
      strcat(PromptStr,PointToName(FileName));
    }
    eprintf("\n%s: ",PromptStr);
    GetPasswordText(Password,MaxLength);
    if (*Password==0 && Type==PASSWORD_GLOBAL)
      return(false);
    if (Type==PASSWORD_GLOBAL)
    {
      strcpy(PromptStr,St(MReAskPsw));
      eprintf(PromptStr);
      char CmpStr[256];
      GetPasswordText(CmpStr,sizeof(CmpStr));
      if (*CmpStr==0 || strcmp(Password,CmpStr)!=0)
      {
        strcpy(PromptStr,St(MNotMatchPsw));
/*
#ifdef _WIN_32
        CharToOem(PromptStr,PromptStr);
#endif
*/
        eprintf(PromptStr);
        memset(Password,0,MaxLength);
        memset(CmpStr,0,sizeof(CmpStr));
        continue;
      }
      memset(CmpStr,0,sizeof(CmpStr));
    }
    break;
  }
  return(true);
}
Example #20
0
void ErrorHandler::ErrMsg(const char *ArcName,const char *fmt,...)
{
  safebuf char Msg[NM+1024];
  va_list argptr;
  va_start(argptr,fmt);
  vsprintf(Msg,fmt,argptr);
  va_end(argptr);
#ifdef _WIN_ALL
  if (UserBreak)
    Sleep(5000);
#endif
  Alarm();
  if (*Msg)
  {
    Log(ArcName,"\n%s",Msg);
    mprintf("\n%s\n",St(MProgAborted));
  }
}
Example #21
0
void main()
{
	/*time_t currentTime = time(NULL);
	printf("현재시간 = %u\n", currentTime);
	printf("현재시간 = %s\n", asctime(localtime(&currentTime)));*/
	
	//1. 기준 시간 ( 프로그램 시작 시간 )
	const time_t timeBegin = time(NULL);

	while (true)
	{
		if (Alarm( timeBegin, 4) )
		{
			printf("%d 초가 경과 .. !\n", 4);
			break;
		}
	}//while()

}
Example #22
0
void Log(const wchar *ArcName,const wchar *fmt,...)
{
  // Preserve the error code for possible following system error message.
  int Code=ErrHandler.GetSystemErrorCode();

  Alarm();

  // This buffer is for format string only, not for entire output,
  // so it can be short enough.
  wchar fmtw[1024];
  PrintfPrepareFmt(fmt,fmtw,ASIZE(fmtw));

  safebuf wchar Msg[2*NM+1024];
  va_list arglist;
  va_start(arglist,fmt);
  vswprintf(Msg,ASIZE(Msg),fmtw,arglist);
  va_end(arglist);
  eprintf(L"%ls",Msg);
  ErrHandler.SetSystemErrorCode(Code);
}
bool GetPassword(PASSWORD_TYPE Type,const char *FileName,char *Password,int MaxLength)
{
  Alarm();
  while (true)
  {
    char PromptStr[NM+256];
#if defined(_EMX) || defined(_BEOS)
    strcpy(PromptStr,St(MAskPswEcho));
#else
    strcpy(PromptStr,St(MAskPsw));
#endif
    if (Type!=PASSWORD_GLOBAL)
    {
      strcat(PromptStr,St(MFor));
      char *NameOnly=PointToName(FileName);
      if (strlen(PromptStr)+strlen(NameOnly)<ASIZE(PromptStr))
        strcat(PromptStr,NameOnly);
    }
    eprintf("\n%s: ",PromptStr);
    GetPasswordText(Password,MaxLength);
    if (*Password==0 && Type==PASSWORD_GLOBAL)
      return(false);
    if (Type==PASSWORD_GLOBAL)
    {
      eprintf(St(MReAskPsw));
      char CmpStr[MAXPASSWORD];
      GetPasswordText(CmpStr,ASIZE(CmpStr));
      if (*CmpStr==0 || strcmp(Password,CmpStr)!=0)
      {
        eprintf(St(MNotMatchPsw));
        memset(Password,0,MaxLength);
        memset(CmpStr,0,sizeof(CmpStr));
        continue;
      }
      memset(CmpStr,0,sizeof(CmpStr));
    }
    break;
  }
  return(true);
}
	void Scheduler::Passenger()
    {
	  
	  Serial.print("----- Passenger Command ");
	     switch(opCode){
	    
	     case 0:   break;
	     case 1:   ScheduleCalls(floor,"UP");
	 	           Serial.print(" op: Hall Call Up");
	 			   Serial.print("\tFloor : "+String(floor)+"-----\n");
	 			   break;
	     case 2:   ScheduleCalls(floor,"DOWN");
	 	           Serial.print(" op: Hall Call Down");
	 			   Serial.print("\tFloor : "+String(floor)+"-----\n");
	 			   break;
	     case 3:   InsertDestination(floor,elevatorID);
	 	           Serial.print(" op:Insert Destination for Elevator "+String(elevatorID+1));
	 	           Serial.print("\tFloor : "+String(floor)+"-----\n");
	 	           break;
	     case 4:   OpenDoor(elevatorID);
	 	           Serial.print(" op: Open Door for Elevator "+String(elevatorID+1));
	 	           Serial.print("-----\n");
	 	           break;
	     case 5:   CloseDoor(elevatorID);
	 	           Serial.print(" op: Close Door for Elevator "+String(elevatorID+1));
	 	           Serial.print("-----\n");
	 	           break;
	     case 6:   CancelCalls(floor,elevatorID);
	 			   Serial.print(" op: Cancel floor for Elevator "+String(elevatorID+1));
	 			   Serial.print("\tFloor : "+String(floor)+"-----\n");
	 			   break;
	     case 7:   Serial.print(" op: Alarm status:");
	 			   Alarm(elevatorID);
	 			   Serial.print(" for Elevator "+String(elevatorID+1));
	 			   Serial.print("-----\n");
	 			   break;
	     default : break;
	 }
    }	
Example #25
0
void	Prot_token_hurry()
{
	/* asked to send token again (almost lost) */
			
	sys_scatter	retrans_token;
	int32		val;

	retrans_token.num_elements = 1;
	retrans_token.elements[0].len = sizeof(token_header);
	retrans_token.elements[0].buf = (char *)Last_token;
	Last_token->rtr_len=0;
	if( Conf_leader( Memb_active_ptr() ) == My.id ) 
	{
		val = Get_retrans(Last_token->type);
		val++;
		Last_token->type = Set_retrans( Last_token->type, val );
		E_queue( Prot_token_hurry, 0, NULL, Hurry_timeout );
		GlobalStatus.token_hurry++;
	}
	/* sending token */
	Net_send_token( &retrans_token );
	if( Wide_network && 
	    Conf_seg_last(Memb_active_ptr(), My.seg_index) == My.id )
	{
		/* sending again to another segment */
		Net_send_token( &retrans_token );
	}
	if( Get_retrans( Last_token->type ) > 1 )
	{
		/* problems */ 
		Net_send_token( &retrans_token );
		Net_send_token( &retrans_token );
	}

	Alarm( PROTOCOL, "Prot_token_hurry: retransmiting token %d %d\n",
		Get_arq(Last_token->type), Get_retrans(Last_token->type) );
}
Example #26
0
void ErrorHandler::CreateErrorMsg(const char *ArcName,const char *FileName)
{
#ifndef SILENT
  Log(ArcName && *ArcName ? ArcName:NULL,St(MCannotCreate),FileName);
  Alarm();
/*#if defined(_WIN_32) && !defined(_WIN_CE) && !defined(SFX_MODULE) && defined(MAXPATH)
  if (GetLastError()==ERROR_PATH_NOT_FOUND)
  {
    int NameLength=strlen(FileName);
    if (!IsFullPath(FileName))
    {
      char CurDir[NM];
      GetCurrentDirectory(sizeof(CurDir),CurDir);
      NameLength+=strlen(CurDir)+1;
    }
    if (NameLength>MAXPATH)
    {
      Log(ArcName && *ArcName ? ArcName:NULL,St(MMaxPathLimit),MAXPATH);
    }
  }
#endif*/
  SysErrMsg();
#endif
}
Example #27
0
static	void	Deliver_reliable_packets( int32 start_seq, int num_packets )
{
	int		pack_entry;
	int		end_seq;
	int		i;

	if( Memb_state() == EVS ) return;
	end_seq = start_seq+num_packets-1;
	if( start_seq <= Last_delivered ) start_seq = Last_delivered + 1;
	for( i = start_seq; i <= end_seq  ; i++ )
	{
		pack_entry = i & PACKET_MASK;

		if( Packets[pack_entry].exist == 1 )
		{
			if( Is_reliable( Packets[pack_entry].head->type ) &&
			    Packets[pack_entry].head->packet_index == -1 )
			{
				Deliver_packet( pack_entry, 1 );
				Alarm( PROTOCOL, "Deliver_reliable_packets: packet %d was delivered\n", i );
			}
		}
	}
}
Example #28
0
/* Input: valid object type, threshold/watermark value for this object, initial objects to create
 * Output: none
 * Effects: sets watermark for type,creates initial memory buffers and updates global vars
 * Should ONLY be called once per execution of the program
 */
int            Mem_init_object(int32u obj_type, int32u size, unsigned int threshold, unsigned int initial)
{
    int mem_error = 0;
#ifdef  SPREAD_STATUS
    char memobj_name[32];
    char memobj_desc[200];
    struct StatGroup *sgroup;
#endif
    assert((obj_type > 0) && (obj_type < MAX_MEM_OBJECTS));
    assert(size > 0 );

#ifndef NDEBUG
    if (!Initialized) {
        /* do any initialization needed just once here */
        Mem_Bytes_Allocated = 0;
        Mem_Obj_Allocated = 0;
        Mem_Obj_Inuse = 0;
        Mem_Max_Bytes = 0;
        Mem_Max_Objects = 0;
        Mem_Max_Obj_Inuse = 0;

        Initialized = TRUE;
    }
#endif
    assert(!(Mem[obj_type].exist));

    if( obj_type == BLOCK_OBJECT )
    {
        assert(threshold == 0);
        assert(initial == 0);
    }

    Mem[obj_type].exist = TRUE;
    Mem[obj_type].size = size;
    Mem[obj_type].threshold = threshold;
    /* Only enabled when MEM_DISABLE_CACHE set. Disable threshold so all memory is dellocated at dispose() */
#ifdef  MEM_DISABLE_CACHE
    Mem[obj_type].threshold = 0;
#endif
#ifndef NDEBUG
    Mem[obj_type].num_obj = 0;
    Mem[obj_type].bytes_allocated = 0;
    Mem[obj_type].num_obj_inuse = 0;
    Mem[obj_type].max_bytes = 0;
    Mem[obj_type].max_obj = 0;
    Mem[obj_type].max_obj_inuse = 0;
#endif
    Mem[obj_type].num_obj_inpool = 0;
    if (initial > 0)
    {
        /* Create 'initial' objects */
        int i;
        mem_header *head_ptr;
        void  ** body_ptr;
        for(i = initial; i > 0; i--)
        {
            head_ptr = (mem_header *) calloc(1, sizeof(mem_header) + sizeobj(obj_type) );
            if (head_ptr == NULL)
            {
                Alarm(MEMORY, "mem_init_object: Failure to calloc an initial object. Returning with existant buffers\n");
                mem_error = 1;
                break;
            }


            head_ptr->obj_type = obj_type;
            head_ptr->block_len = sizeobj(obj_type);
            /* We add 1 because pointer arithm. states a pointer + 1 equals a pointer
             * to the next element in an array where each element is of a particular size.
             * in this case that size is 8 (or 12)
             * (since it is a pointer to a struct of a 32bit int and a size_t)
             * so adding one actually moves the pointer 8 (or 12) bytes forward!
             */
            body_ptr = (void **) (head_ptr + 1);

#ifdef TESTING
            printf("alignment objtype = %u\n", __alignof__(head_ptr->obj_type));
            printf("alignment blocklen = %u\n", __alignof__(head_ptr->block_len));
            printf("initial  head = 0x%x\n", head_ptr);
            printf("initial body = 0x%x\n", body_ptr);
            printf("alignment head = %u\n", __alignof__(head_ptr));
            printf("alignment body = %u\n", __alignof__(body_ptr));
            printf("sizeof body pointer = %u\n", sizeof(body_ptr));
            printf("size head = %u\t size body = %u\n", sizeof(mem_header), sizeobj(obj_type));
#endif

            *body_ptr = (void *) Mem[obj_type].list_head;
            Mem[obj_type].list_head = body_ptr;
            Mem[obj_type].num_obj_inpool++;
#ifndef NDEBUG
            Mem[obj_type].num_obj++;
            Mem[obj_type].bytes_allocated += (sizeobj(obj_type) + sizeof(mem_header));
#endif
        }
#ifndef NDEBUG
        Mem[obj_type].max_bytes = Mem[obj_type].bytes_allocated;
        Mem[obj_type].max_obj = Mem[obj_type].num_obj;

        Mem_Bytes_Allocated += Mem[obj_type].bytes_allocated;
        Mem_Obj_Allocated += Mem[obj_type].num_obj;
        if (Mem_Bytes_Allocated > Mem_Max_Bytes)
        {
            Mem_Max_Bytes = Mem_Bytes_Allocated;
        }
        if (Mem_Obj_Allocated > Mem_Max_Objects)
        {
            Mem_Max_Objects = Mem_Obj_Allocated;
        }
#endif
    }

#ifndef NDEBUG
#ifdef SPREAD_STATUS
    if (MemStatus_initialized) {
        sprintf(memobj_name, "Memory_%d", obj_type);
        sprintf(memobj_desc, "Memory statistics for object: %s", Objnum_to_String(obj_type) );
        sgroup = Stat_Group_Create(memobj_name, memobj_desc);
        if (!sgroup)
            Alarm(PRINT, "Mem_init_object:Failed to create stat group for object: %s\n", Objnum_to_String(obj_type) );
        else {
            Stat_Insert_Record(memobj_name, "Current Bytes Used", "bytes", STAT_INT, &(Mem[obj_type].bytes_allocated) );
            Stat_Group_Add_Member(sgroup, &(Mem[obj_type].bytes_allocated) );
            Stat_Insert_Record(memobj_name, "Maximum Bytes Used", "max_bytes", STAT_INT, &(Mem[obj_type].max_bytes) );
            Stat_Group_Add_Member(sgroup, &(Mem[obj_type].max_bytes) );
            Stat_Insert_Record(memobj_name, "Current Objects Used", "objs", STAT_INT, &(Mem[obj_type].num_obj) );
            Stat_Group_Add_Member(sgroup, &(Mem[obj_type].num_obj) );
            Stat_Insert_Record(memobj_name, "Maximum Objects Used", "max_objs", STAT_INT, &(Mem[obj_type].max_obj) );
            Stat_Group_Add_Member(sgroup, &(Mem[obj_type].max_obj) );
            Stat_Insert_Record(memobj_name, "Current Objects Inuse", "obj_inuse", STAT_INT, &(Mem[obj_type].num_obj_inuse) );
            Stat_Group_Add_Member(sgroup, &(Mem[obj_type].num_obj_inuse) );
            Stat_Insert_Record(memobj_name, "Maximum Objects Inuse", "max_inuse", STAT_INT, &(Mem[obj_type].max_obj_inuse) );
            Stat_Group_Add_Member(sgroup, &(Mem[obj_type].max_obj_inuse) );
            Stat_Insert_Record(memobj_name, "Current Objects In Pool", "obj_inpool", STAT_INT, &(Mem[obj_type].num_obj_inpool) );
            Stat_Group_Add_Member(sgroup, &(Mem[obj_type].num_obj_inpool) );
        }
    } /* if memstatus_init */
#endif
#endif

    if (mem_error) {
        return(MEM_ERR);
    }
    return(0);
}
Example #29
0
void    Mem_init_status()
{
#ifdef SPREAD_STATUS
    struct StatGroup *sgroup;
    int obj_type;
    char memobj_name[32];
    char memobj_desc[200];
    if (!MemStatus_initialized)
    {
        sgroup = Stat_Group_Create("Memory_Summary_0", "Statistics for memory useage summarized over all memory objects");
        if (!sgroup)
        {
            Alarm(PRINT, "Mem_init_object: Failed to create Memory Status group\n");
        } else {
            Stat_Insert_Record("Memory_Summary_0", "Current Bytes Used", "bytes", STAT_INT, &Mem_Bytes_Allocated );
            Stat_Group_Add_Member(sgroup, &Mem_Bytes_Allocated);
            Stat_Insert_Record("Memory_Summary_0", "Maximum Bytes Used", "max_bytes", STAT_INT, &Mem_Max_Bytes );
            Stat_Group_Add_Member(sgroup, &Mem_Max_Bytes);
            Stat_Insert_Record("Memory_Summary_0", "Current Objects Used", "objs", STAT_INT, &Mem_Obj_Allocated );
            Stat_Group_Add_Member(sgroup, &Mem_Obj_Allocated);
            Stat_Insert_Record("Memory_Summary_0", "Maximum Objects Used", "max_objs", STAT_INT, &Mem_Max_Objects);
            Stat_Group_Add_Member(sgroup, &Mem_Max_Objects);
            Stat_Insert_Record("Memory_Summary_0", "Current Objects Inuse", "objs_inuse", STAT_INT, &Mem_Obj_Inuse);
            Stat_Group_Add_Member(sgroup, &Mem_Obj_Inuse);
            Stat_Insert_Record("Memory_Summary_0", "Maximum Objects Inuse", "max_obj_inuse", STAT_INT, &Mem_Max_Obj_Inuse);
            Stat_Group_Add_Member(sgroup, &Mem_Max_Obj_Inuse);
        }
        MemStatus_initialized = TRUE;
    }

    for (obj_type = 1; obj_type < MAX_MEM_OBJECTS; obj_type++)
    {
        if (Mem[obj_type].exist) {
            sprintf(memobj_name, "Memory_%d", obj_type);
            sprintf(memobj_desc, "Memory statistics for object: %s", Objnum_to_String(obj_type) );
            sgroup = Stat_Group_Create(memobj_name, memobj_desc);
            if (!sgroup)
                Alarm(PRINT, "Mem_init_object:Failed to create stat group for object: %s\n", Objnum_to_String(obj_type) );
            else {
#ifndef NDEBUG
                Stat_Insert_Record(memobj_name, "Current Bytes Used", "bytes", STAT_INT, &(Mem[obj_type].bytes_allocated) );
                Stat_Group_Add_Member(sgroup, &(Mem[obj_type].bytes_allocated) );
                Stat_Insert_Record(memobj_name, "Maximum Bytes Used", "max_bytes", STAT_INT, &(Mem[obj_type].max_bytes) );
                Stat_Group_Add_Member(sgroup, &(Mem[obj_type].max_bytes) );
                Stat_Insert_Record(memobj_name, "Current Objects Used", "objs", STAT_INT, &(Mem[obj_type].num_obj) );
                Stat_Group_Add_Member(sgroup, &(Mem[obj_type].num_obj) );
                Stat_Insert_Record(memobj_name, "Maximum Objects Used", "max_objs", STAT_INT, &(Mem[obj_type].max_obj) );
                Stat_Group_Add_Member(sgroup, &(Mem[obj_type].max_obj) );
                Stat_Insert_Record(memobj_name, "Current Objects Inuse", "obj_inuse", STAT_INT, &(Mem[obj_type].num_obj_inuse) );
                Stat_Group_Add_Member(sgroup, &(Mem[obj_type].num_obj_inuse) );
                Stat_Insert_Record(memobj_name, "Maximum Objects Inuse", "max_inuse", STAT_INT, &(Mem[obj_type].max_obj_inuse) );
                Stat_Group_Add_Member(sgroup, &(Mem[obj_type].max_obj_inuse) );
#endif
                Stat_Insert_Record(memobj_name, "Current Objects In Pool", "obj_inpool", STAT_INT, &(Mem[obj_type].num_obj_inpool) );
                Stat_Group_Add_Member(sgroup, &(Mem[obj_type].num_obj_inpool) );
            }
        } /* if exists */
    } /* for loop */
    return;
#else
    return;
#endif
}
Example #30
0
struct skiplistnode *sl_insert_compare(Skiplist *sl,
				       void *data,
				       SkiplistComparator comp) {
  struct skiplistnode *m, *p, *tmp, *ret, **stack;
  int nh=1, ch, stacki;
  ret = NULL;
/*sl_print_struct(sl, "BI: ");*/
  if(!sl->top) {
    sl->height = 1;
    sl->topend = sl->bottomend = sl->top = sl->bottom = 
      (struct skiplistnode *)malloc(sizeof(struct skiplistnode));
    assert(sl->top);
    sl->top->next = sl->top->data = sl->top->prev =
	sl->top->up = sl->top->down = 
	sl->top->nextindex = sl->top->previndex = NULL;
    sl->top->sl = sl;
  }
  if(sl->preheight) {
    while(nh < sl->preheight && get_b_rand()) nh++;
  } else {
    while(nh <= sl->height && get_b_rand()) nh++;
  }
  /* Now we have the new height at which we wish to insert our new node */
  /* Let us make sure that our tree is a least that tall (grow if necessary)*/
  for(;sl->height<nh;sl->height++) {
    sl->top->up =
      (struct skiplistnode *)malloc(sizeof(struct skiplistnode));
    assert(sl->top->up);
    sl->top->up->down = sl->top;
    sl->top = sl->topend = sl->top->up;
    sl->top->prev = sl->top->next = sl->top->nextindex =
      sl->top->previndex = sl->top->up = NULL;
    sl->top->data = NULL;
    sl->top->sl = sl;
  }
  ch = sl->height;
  /* Find the node (or node after which we would insert) */
  /* Keep a stack to pop back through for insertion */
  m = sl->top;
  stack = (struct skiplistnode **)malloc(sizeof(struct skiplistnode *)*(nh));
  stacki=0;
  while(m) {
    int compared=-1;
    if(m->next) compared=comp(data, m->next->data);
    if(compared == 0) {
      free(stack);
      return 0;
    }
    if((m->next == NULL) || (compared<0)) {
            /* FIXME: This if ch<=nh test looks unnecessary. ch==nh at beginning of while(m)
             */
      if(ch<=nh) {
	/* push on stack */
	stack[stacki++] = m;
      }
      m = m->down;
      ch--;
    } else {
      m = m->next;
    }
  }
  /* Pop the stack and insert nodes */
  p = tmp = NULL;
  for(;stacki>0;stacki--) {
    m = stack[stacki-1];
    tmp = (struct skiplistnode *)malloc(sizeof(struct skiplistnode));
    tmp->next = m->next;
    if(m->next) m->next->prev=tmp;
    tmp->prev = m;
    tmp->up = NULL;
    tmp->nextindex = tmp->previndex = NULL;
    tmp->down = p;
    if(p) p->up=tmp;
    tmp->data = data;
    tmp->sl = sl;
    m->next = tmp;
    /* This sets ret to the bottom-most node we are inserting */
    if(!p) 
    {
            ret=tmp;
            sl->size++;
    }
    p = tmp;
  }
  free(stack);
  if(tmp && (tmp->prev == sl->topend)) {
    /* The last element on the top row is the new inserted one */
    sl->topend = tmp;
  }
  if(ret && (ret->prev == sl->bottomend)) {
    /* The last element on the bottom row is the new inserted one */
    sl->bottomend = ret;
  }
  if(sl->index != NULL) {
    /* this is a external insertion, we must insert into each index as well */
    struct skiplistnode *p, *ni, *li;
    li=ret;
    for(p = sl_getlist(sl->index); p; sl_next(sl->index, &p)) {
      ni = sl_insert((Skiplist *)p->data, ret->data);
      assert(ni);
      Alarm(SKIPLIST, "Adding %p to index %p\n", ret->data, p->data);
      li->nextindex = ni;
      ni->previndex = li;
      li = ni;
    }
  } 
  /* JRS: move size increment above to where node is inserted
    else {
    sl->size++;
  }
  */
/*sl_print_struct(sl, "AI: ");*/
  return ret;
}