Exemple #1
0
static void x_ipc_listIncFreeList(void)
#endif
{
  int32 i;
  LIST_PTR newList;
  
  LOCK_LIST_MUTEX;
  for(i=1;i < LIST_INC_AMOUNT;i++) {
#if defined(DBMALLOC)
    newList = NEW_DB(file,line,LIST_TYPE);
#else
    newList = NEW(LIST_TYPE);
#endif
    
    if (!newList) {
      X_IPC_MOD_ERROR("Error: Can not increment list top level free list.");
      UNLOCK_LIST_MUTEX;
      return;
    }
    
    newList->length = 0;
    newList->first = NULL;
    newList->last = NULL;
    newList->next = NULL;
    
    /* No need to lock M_MUTEX, since list.c is only place this is accessed */
    newList->freeList = GET_M_GLOBAL(listFreeListGlobal);
    GET_M_GLOBAL(listFreeListGlobal) = newList;
  }
  UNLOCK_LIST_MUTEX;
}
Exemple #2
0
void x_ipc_listInsertItemLast(const void *item, LIST_PTR list)
{
  LIST_ELEM_PTR element;
  
  if (!item || !list)
    return;
  
  LOCK_LIST_MUTEX;
  /* No need to lock M_MUTEX, since list.c is only place this is accessed */
  if (!GET_M_GLOBAL(listCellFreeListGlobal))
    x_ipc_listIncCellFreeList();
  
  element = GET_M_GLOBAL(listCellFreeListGlobal);
  GET_M_GLOBAL(listCellFreeListGlobal) = 
    GET_M_GLOBAL(listCellFreeListGlobal)->next;

  element->item = (const char *)item;
  element->next = NULL;
  element->previous = list->last;
  
  if (!list->first) {
    list->first = element;
  }
  
  if (list->last) {
    list->last->next = element;
  }
  
  list->length++;
  list->last = element;
  UNLOCK_LIST_MUTEX;
}
Exemple #3
0
void x_ipc_listCleanup(void)
{
  LOCK_M_MUTEX;
  x_ipc_listFreeElement(GET_M_GLOBAL(listCellFreeListGlobal));
  GET_M_GLOBAL(listCellFreeListGlobal) = NULL;
  /* Now need to really free the master list of lists */
  x_ipc_listFreeMaster(&GET_M_GLOBAL(listFreeListGlobal));
  UNLOCK_M_MUTEX;
}
Exemple #4
0
static int32 countDataMessages(int32 allocatedP, DATA_MSG_BUF_PTR dataMsgBuf)
{
  if (dataMsgBuf->allocated == allocatedP) {
    LOCK_M_MUTEX;
    GET_M_GLOBAL(numAllocatedDM)++;
    GET_M_GLOBAL(sizeDM) += dataMsgBuf->size;
    UNLOCK_M_MUTEX;
  }
  return TRUE;
}
Exemple #5
0
static void x_ipc_listFreeCell(LIST_ELEM_PTR listCell)
{
  listCell->item = NULL;
  listCell->previous = NULL;
  
  LOCK_LIST_MUTEX;
  /* No need to lock M_MUTEX, since list.c is only place this is accessed */
  listCell->next = GET_M_GLOBAL(listCellFreeListGlobal);
  GET_M_GLOBAL(listCellFreeListGlobal) = listCell;
  UNLOCK_LIST_MUTEX;
}
Exemple #6
0
void x_ipc_dataMsgInitialize(void)
{
  LOCK_M_MUTEX;
  GET_M_GLOBAL(DMFree) = 0;
  GET_M_GLOBAL(DMTotal) = 0;
  GET_M_GLOBAL(DMmin) = 2000000000;
  GET_M_GLOBAL(DMmax) = -1;
  
  GET_M_GLOBAL(dataMsgBufferList) = x_ipc_listCreate();
  UNLOCK_M_MUTEX;
}
Exemple #7
0
void x_ipcRegisterFreeMemHnd(void (*func)(u_int32), int retry)
{
  LOCK_M_MUTEX;
  GET_M_GLOBAL(freeMemRetryAmount) = retry;
  
  if (GET_M_GLOBAL(freeMemRetryAmount) < 1)
    GET_M_GLOBAL(freeMemRetryAmount) = 1;
  
  GET_M_GLOBAL(x_ipcFreeMemoryHnd) = func;
  UNLOCK_M_MUTEX;
}
Exemple #8
0
void x_ipcStats(FILE *stream)
{
  if (!mGlobalp())
    return;
  
  LOCK_M_MUTEX;
  fprintf(stream,"Cumulative Memory Usage:\n  Requests: %ld (%ld bytes)\n", 
	  GET_M_GLOBAL(totalMemRequest), GET_M_GLOBAL(totalMemBytes));
  UNLOCK_M_MUTEX;
  x_ipc_dataMsgDisplayStats(stream);
  fflush(stream);
}
Exemple #9
0
static void x_ipc_terminalLogVarHnd(X_IPC_REF_PTR Ref, LOG_PTR log)
{
#ifdef UNUSED_PRAGMA
#pragma unused(Ref)
#endif
  LOCK_M_MUTEX;
  if (GET_M_GLOBAL(logList)[1] != NULL)
    x_ipcFree((void *)GET_M_GLOBAL(logList)[1]);
  GET_M_GLOBAL(logList)[1] = log;
  GET_M_GLOBAL(logList)[2] = NULL;
  UNLOCK_M_MUTEX;
}
Exemple #10
0
void x_ipc_hndDelete(HND_PTR hnd)
{
  HND_KEY_TYPE hndKey;
  LIST_PTR msgList;
  LIST_ELEM_PTR listTmp;
  MODULE_PTR module;
  MSG_PTR msg;
  
  if (hnd) {
    if (hnd->hndLanguage == UNKNOWN_LANGUAGE) return;
    
    hnd->hndLanguage = UNKNOWN_LANGUAGE;
    
    hnd->msg = NULL;
    msgList = hnd->msgList;
    hnd->msgList = NULL; /* to revent recursion of free's */
    x_ipc_listTestDeleteItemAll((LIST_ITER_FN) x_ipc_removeHndFromMsg, 
			  (char *)hnd, msgList);
    
    x_ipc_listFree(&msgList);
    
    LOCK_CM_MUTEX;
    (void)x_ipc_idTableRemove(hnd->localId, GET_C_GLOBAL(hndIdTable));
    /* Need to remove from the module list.   */
    if (GET_M_GLOBAL(moduleList) != NULL) {
      for (listTmp = GET_M_GLOBAL(moduleList)->first; 
	   (listTmp != NULL);
	   listTmp = listTmp->next
	   ) {
	module = (MODULE_PTR)(listTmp->item);
	x_ipc_listDeleteItemAll(hnd,module->hndList);
      }
    }
    if (hnd->hndData) {
      hndKey.num = hnd->sd;
      hndKey.str = hnd->hndData->hndName;
      x_ipc_hashTableRemove((char *)&hndKey, GET_C_GLOBAL(handlerTable));
      msg = GET_MESSAGE(hnd->hndData->msgName);
      if (msg) x_ipc_removeHndFromMsg(hnd, msg);
      x_ipcFree((char *)hnd->hndData->msgName);
      hnd->hndData->msgName = NULL;
      x_ipcFree((char *)hnd->hndData->hndName);
      hnd->hndData->hndName = NULL;
      x_ipcFree((char *)hnd->hndData);
      hnd->hndData = NULL;
    }
    UNLOCK_CM_MUTEX;
    hnd->hndData = NULL;
    
    x_ipcFree((char *)hnd);
  }
}
Exemple #11
0
static void x_ipc_listFreeTop(LIST_PTR list)
{
  list->length = 0;
  list->first = NULL;
  list->last = NULL;
  list->next = NULL;
  
  LOCK_LIST_MUTEX;
  /* No need to lock M_MUTEX, since list.c is only place this is accessed */
  list->freeList = GET_M_GLOBAL(listFreeListGlobal);
  GET_M_GLOBAL(listFreeListGlobal) = list;
  UNLOCK_LIST_MUTEX;
}
Exemple #12
0
void x_ipcRegisterMallocHnd(void *(*func)(size_t size), int retry)
#endif
{
  LOCK_M_MUTEX;
  GET_M_GLOBAL(mallocMemRetryAmount) = retry;
  
  if (GET_M_GLOBAL(mallocMemRetryAmount) < 1)
    GET_M_GLOBAL(mallocMemRetryAmount) = 1;
  
  if (func)
    GET_M_GLOBAL(x_ipcMallocMemHnd) = func;
  UNLOCK_M_MUTEX;
}
Exemple #13
0
IPC_RETURN_TYPE IPC_addTimerGetRef(unsigned long tdelay, long count,
				   TIMER_HANDLER_TYPE handler,
				   void *clientData,
				   TIMER_REF *timerRef)
{
  TIMER_PTR timer;

  if (!handler) {
    RETURN_ERROR(IPC_Null_Argument);
  } else if (tdelay == 0) {
    RETURN_ERROR(IPC_Argument_Out_Of_Range);
  } else if (count <= 0 && count != TRIGGER_FOREVER) {
    RETURN_ERROR(IPC_Argument_Out_Of_Range);
  } else {
    if (0 == timerRef) {
      /* if IPC_addTimerGetRef() is being called from IPC_addTimer(),
         we will clobber any old timers with the same handler
         for backwards compatibility */  
      timer = ipcGetTimer(handler);
      if (timer && timer->status != Timer_Deleted) {
	X_IPC_MOD_WARNING1("Replacing existing timer for handler (%#lx)\n",
			   (long)handler);
      } else {
	timer = NEW(TIMER_TYPE);
	LOCK_M_MUTEX;
	x_ipc_listInsertItemLast((const void *)timer, GET_M_GLOBAL(timerList));
	UNLOCK_M_MUTEX;
      }
    } else {
      /* if IPC_addTimerGetRef() is being called directly with a non-zero
	 timerRef argument, we don't clobber */
      timer = NEW(TIMER_TYPE);
      LOCK_M_MUTEX;
      x_ipc_listInsertItemLast((const void *)timer, GET_M_GLOBAL(timerList));
      UNLOCK_M_MUTEX;
    }

    timer->timerFn = handler;
    timer->period = tdelay;
    timer->clientData = clientData;
    timer->maxTrigger = count;
    timer->triggerTime = x_ipc_timeInMsecs() + tdelay;
    timer->status = Timer_Waiting;

    if (0 != timerRef) *timerRef = (TIMER_REF) timer;

    return IPC_OK;
  }
}
Exemple #14
0
static DATA_MSG_PTR x_ipc_dataMsgAlloc(int32 size)
{
  DATA_MSG_PTR dataMsg;
  
  dataMsg = (DATA_MSG_PTR)x_ipcMalloc((unsigned)size);
  
  LOCK_M_MUTEX;
  (GET_M_GLOBAL(DMTotal))++;
  
  if (size > (GET_M_GLOBAL(DMmax))) (GET_M_GLOBAL(DMmax)) = size;
  if (size < (GET_M_GLOBAL(DMmin))) (GET_M_GLOBAL(DMmin)) = size;
  UNLOCK_M_MUTEX;
  
  return (dataMsg);
}
Exemple #15
0
/* no longer used */
static X_IPC_RETURN_VALUE_TYPE x_ipcAllocateDataBuffer(int32 size)
{
  DATA_MSG_BUF_PTR dataMsgBuf;
  
  /* Creates an unallocated data message buffer */
  dataMsgBuf = dataMsgBufferCreate(size);
  LOCK_M_MUTEX;
  x_ipc_listInsertItem((char *)dataMsgBuf, (GET_M_GLOBAL(dataMsgBufferList)));
  
  if (size > (GET_M_GLOBAL(DMmax))) (GET_M_GLOBAL(DMmax)) = size;
  if (size < (GET_M_GLOBAL(DMmin))) (GET_M_GLOBAL(DMmin)) = size;
  UNLOCK_M_MUTEX;
  
  return Success;
}
Exemple #16
0
unsigned int formatGetUShort(BUFFER_PTR buffer)
{
  unsigned short us;
  int byteOrder;
  ALIGNMENT_TYPE alignment;

  LOCK_M_MUTEX;
  byteOrder = GET_M_GLOBAL(byteOrder);
  alignment = GET_M_GLOBAL(alignment);
  UNLOCK_M_MUTEX;

  buffer->bstart += x_ipc_SHORT_Trans_Decode((GENERIC_DATA_PTR)&us,
					     0, buffer->buffer, buffer->bstart,
					     byteOrder, alignment);
  return (int32)us;
}
Exemple #17
0
int32 formatGetUByte(BUFFER_PTR buffer)
{
  unsigned char byte;
  int byteOrder;
  ALIGNMENT_TYPE alignment;

  LOCK_M_MUTEX;
  byteOrder = GET_M_GLOBAL(byteOrder);
  alignment = GET_M_GLOBAL(alignment);
  UNLOCK_M_MUTEX;
  
  buffer->bstart += x_ipc_BYTE_Trans_Decode((GENERIC_DATA_PTR)&byte,
					    0, buffer->buffer, buffer->bstart,
					    byteOrder, alignment);
  return (int32)byte;
}
Exemple #18
0
double formatGetDouble(BUFFER_PTR buffer)
{
  double d;
  int byteOrder;
  ALIGNMENT_TYPE alignment;

  LOCK_M_MUTEX;
  byteOrder = GET_M_GLOBAL(byteOrder);
  alignment = GET_M_GLOBAL(alignment);
  UNLOCK_M_MUTEX;
  
  buffer->bstart += x_ipc_DOUBLE_Trans_Decode((GENERIC_DATA_PTR)&d, 0,
					      buffer->buffer, buffer->bstart,
					      byteOrder, alignment);
  return d;
}
Exemple #19
0
static void ipcDeleteTimer (TIMER_PTR timer)
{
  LOCK_M_MUTEX;
  x_ipc_listDeleteItem((const void *)timer, GET_M_GLOBAL(timerList));
  UNLOCK_M_MUTEX;
  x_ipcFree((char *)timer);
}
Exemple #20
0
unsigned long ipcNextTime (void)
{
  unsigned long nextTime = WAITFOREVER;
  TIMER_PTR timer;

  LOCK_M_MUTEX;
  timer = (TIMER_PTR)x_ipc_listFirst(GET_M_GLOBAL(timerList));
  while (timer) {
    if (timer->triggerTime < nextTime && timer->status == Timer_Waiting) {
      nextTime = timer->triggerTime;
    }
    timer = (TIMER_PTR)x_ipc_listNext(GET_M_GLOBAL(timerList));
  }
  UNLOCK_M_MUTEX;
  return nextTime;
}
Exemple #21
0
static void startPrint(FILE *stream, Print_Data_Ptr printer)
{
  printer->cursorPosGlobal = 0;
  printer->lineNumGlobal = 0;
  printer->truncatedGlobal = 0;
  printTab(stream, printer, GET_M_GLOBAL(indentGlobal));
}
Exemple #22
0
double formatGetFloat(BUFFER_PTR buffer)
{
  float f;
  int byteOrder;
  ALIGNMENT_TYPE alignment;

  LOCK_M_MUTEX;
  byteOrder = GET_M_GLOBAL(byteOrder);
  alignment = GET_M_GLOBAL(alignment);
  UNLOCK_M_MUTEX;
  
  buffer->bstart += x_ipc_FLOAT_Trans_Decode((GENERIC_DATA_PTR)&f, 
					     0, buffer->buffer, buffer->bstart,
					     byteOrder, alignment);
  return (double)f;
}
Exemple #23
0
unsigned int formatGetUInt(BUFFER_PTR buffer)
{
  unsigned int ui;
  int byteOrder;
  ALIGNMENT_TYPE alignment;

  LOCK_M_MUTEX;
  byteOrder = GET_M_GLOBAL(byteOrder);
  alignment = GET_M_GLOBAL(alignment);
  UNLOCK_M_MUTEX;
  
  buffer->bstart += x_ipc_INT_Trans_Decode((GENERIC_DATA_PTR)&ui,
					   0, buffer->buffer, buffer->bstart,
					   byteOrder, alignment);
  return (unsigned int)ui;
}
Exemple #24
0
DATA_MSG_PTR x_ipc_dataMsgFree(DATA_MSG_PTR dataMsg)
{
  if (dataMsg) {
    (dataMsg->refCount)--;
    if (dataMsg->refCount < 1) {
      if (dataMsg->dataRefCountPtr != NULL) {
	(*(dataMsg->dataRefCountPtr))--;
	if (*(dataMsg->dataRefCountPtr) < 1) {
	  /* Can now free the data. */
	  x_ipcFree((char *)dataMsg->dataRefCountPtr);
	  dataMsg->dataRefCountPtr = NULL;
 	  if ((dataMsg->msgData != NULL) &&
 	      (dataMsg->msgData != dataMsg->dataStruct)) {
	    x_ipcFree((char *)dataMsg->msgData);
	  }
	}
      }
      if (dataMsg->vec != NULL)
	x_ipcFree((char *)dataMsg->vec);
      dataMsg->vec = NULL;
      
      x_ipcFree((char *)dataMsg);
      LOCK_M_MUTEX;
      (GET_M_GLOBAL(DMFree))++;
      UNLOCK_M_MUTEX;
      dataMsg = NULL;
    }
  }
  return dataMsg;
}
Exemple #25
0
void printString(FILE *stream, Print_Data_Ptr printer,
		 const char *pString, int32 keepWithNext)
{ 
  int32 length;
  
  if (!printer->truncatedGlobal) {
    if (pString)
      length = strlen(pString);
    else
      length = 0;
    
    if ((printer->cursorPosGlobal + length + keepWithNext) > LINE_LENGTH) 
      {
	newLine(stream, printer);
	printTab(stream, printer, GET_M_GLOBAL(indentGlobal)+1);
      }
    if (printer->lineNumGlobal < PRINT_LENGTH) {
      if (pString) {
	(void)fprintf(stream, "%s", pString);
	printer->cursorPosGlobal += length;
      }
      else {
	(void)fprintf(stream, "NULL");
	printer->cursorPosGlobal += 4;
      }
    }
    else {
      printer->truncatedGlobal = 1;
      (void)fprintf(stream, "...");
    }
  }
}
Exemple #26
0
void ipcTriggerTimers (void)
{
  unsigned long triggerTime, now;
  TIMER_PTR timer;

  now = x_ipc_timeInMsecs();
  LOCK_M_MUTEX;
  timer = (TIMER_PTR)x_ipc_listFirst(GET_M_GLOBAL(timerList));
  while (timer) {
    triggerTime = timer->triggerTime;
    if (timer->status == Timer_Waiting && triggerTime <= now) {
      timer->status = Timer_In_Use;
      /* Update timer data *before* invoking handler, 
	 just in case triggerTimers is called recursively */
      if (timer->maxTrigger != TRIGGER_FOREVER) {
	timer->maxTrigger--;
	if (timer->maxTrigger == 0)
	  timer->status = Timer_Deleted;
      }
      timer->triggerTime = now + timer->period;
      (timer->timerFn)(timer->clientData, now, triggerTime);
      now = x_ipc_timeInMsecs();

      /* setting status to Timer_Waiting here ensures that the
	 status is only reset after the timer has really finished,
	 and not inside a recursive call. */
      if (timer->status != Timer_Deleted) {
	timer->status = Timer_Done;
      }
    }
    timer = (TIMER_PTR)x_ipc_listNext(GET_M_GLOBAL(timerList));
  }

  /* Clean up any timers that were deleted from within a handler */
  timer = (TIMER_PTR)x_ipc_listFirst(GET_M_GLOBAL(timerList));
  while (timer) {
    if (timer->status == Timer_Deleted) {
      ipcDeleteTimer(timer);
    } else if (timer->status == Timer_Done) {
      timer->status = Timer_Waiting;
    }
    timer = (TIMER_PTR)x_ipc_listNext(GET_M_GLOBAL(timerList));
  }
  UNLOCK_M_MUTEX;
}
Exemple #27
0
void x_ipcModError(const char *description, ...)
{
#ifndef NMP_IPC
  x_ipcStats(stderr);
#endif

#ifdef NMP_IPC
  if (ipcVerbosity >= IPC_Print_Errors)
#endif
  if (description) {
    va_list args;
    va_start(args, description);
    vfprintf(stderr, (char *)description, args);
    fprintf(stderr, "\n");
    va_end(args);
    FLUSH_IF_NEEDED(stderr);
  }
  
#ifdef NMP_IPC
  if (ipcVerbosity >= IPC_Exit_On_Errors)
#endif
  {
    x_ipcClose();
  
    LOCK_M_MUTEX;
    if (mGlobalp()) {
#ifdef LISP
      if (IS_LISP_MODULE()) {
	if (GET_M_GLOBAL(lispExitGlobal) != NULL)
	  (*(GET_M_GLOBAL(lispExitGlobal)))();
      } else
#endif /* LISP */
	{
	  if (GET_M_GLOBAL(x_ipcExitHnd)) {
	    (*(GET_M_GLOBAL(x_ipcExitHnd)))();
	  } else {
	    exit(-1);
	  }
	}
      }
    UNLOCK_M_MUTEX;
  }
}
Exemple #28
0
/*****************************************************************
 * Return to LISP the reference created for a x_ipcQuerySend or x_ipcMultiQuery.
 * There may be a cleaner way to do this, but this seems the easiest
 * and quickest to implement (reids 11/13/92)
 ****************************************************************/
X_IPC_REF_PTR x_ipcQuerySendRefLISPC (void)
{
  X_IPC_REF_PTR result;

  LOCK_M_MUTEX;
  result = GET_M_GLOBAL(lispRefSaveGlobal);
  UNLOCK_M_MUTEX;

  return result;
}
Exemple #29
0
void x_ipcSetSizeEncodeDecode(int (* x_ipc_bufferSize)(int32 *, CONST_FORMAT_PTR),
			    long (* encode)(CONST_FORMAT_PTR, BUFFER_PTR),
			    long (* decode)(CONST_FORMAT_PTR, BUFFER_PTR), 
			    int (* lispExit)(void)
#ifdef NMP_IPC
			    ,int (* lispQueryResponse)(char *, CONST_FORMAT_PTR)
#endif
			    )
{
  LOCK_M_MUTEX;
  (GET_M_GLOBAL(lispBufferSizeGlobal)) = x_ipc_bufferSize;
  (GET_M_GLOBAL(lispEncodeMsgGlobal)) = encode;
  (GET_M_GLOBAL(lispDecodeMsgGlobal)) = decode;
  (GET_M_GLOBAL(lispExitGlobal)) = lispExit;
#ifdef NMP_IPC
  (GET_M_GLOBAL(lispQueryResponseGlobal)) = lispQueryResponse;
#endif
  UNLOCK_M_MUTEX;
}
Exemple #30
0
int msgByteOrder (void)
{
  int result;

  LOCK_M_MUTEX;
  result = GET_M_GLOBAL(byteOrder);
  UNLOCK_M_MUTEX;

  return result;
}