コード例 #1
0
ファイル: mempool.c プロジェクト: Balipeace/SMysqLogger
void TMemPool_Init(TMemPool * me, 
                   int mincount, 
                   int maxcount, 
                   int elementsize, 
                   BOOL threading)
{
   int i;
   
   //all elements must be aligned to 4 bytes boundary to be save...
   //the smalest size is now 4 bytes...
   if ((elementsize & 0x3))
   {
      elementsize = (elementsize & 0x03)+4;
   }
   
   me->mincount = mincount;    
   me->maxcount = maxcount;
   me->elementsize = elementsize;
   me->threading  = threading;
   me->currcount = 0;
   INITLIST(&me->poolList);
   
   //allocate the minimum selements whiche were only freed when destructing
   //...as one block....
   me->preAllocElems = NULL;
   if (mincount)
   {
      me->preAllocElems = os_malloc(mincount * elementsize);
      assert(me->preAllocElems);
   
      //add it as some small pieces to the list of unused elements...
      for(i=0;i < mincount; i++)
      {
         ADDHEAD(&me->poolList, (TMinNode*)(me->preAllocElems + (i * elementsize) ));
      }
   } 
}
コード例 #2
0
ファイル: prot_layer.c プロジェクト: Balipeace/SMysqLogger
/**************************************************************************
   Description   : Erzeugt zu einem Device das benoetigte Protokoll-
                   Implementierungs-Object
   Parameter     : Pointer to device
   Return-Value  : Pointer to new created protocol object
   Changes       : Author, Date, Version, Reason
                   ********************************************************
                   PRUESSING, 20.04.2001, 1.0, Created
**************************************************************************/
void TProtLayer_CreateProtocol(TDevice * device)
{
   int i;
   char cProtName[30];
   char ConfigPath[50];
   struct TProtocol * prot = NULL;
   TProtocolMapEntry * newentry;

   /* count of prots... */
   int iProtCount = sizeof(ProtocolTable) / sizeof(struct TProtocolTable);

   assert(device);

   /*
   ** get the right protocol name from config file
   */
   sprintf(ConfigPath,"%s.Protocol",device->cName);
   TRepository_GetElementStr(ConfigPath, "SMANet", cProtName, sizeof(cProtName));

   /* Rufe den richtigen Konstruktor zum Erzeugen des Protokolls auf...*/
   for(i = 0; i < iProtCount; i++)
   {
      if (strstr(cProtName, ProtocolTable[i].ProtName ) != NULL )
      {
         assert(ProtocolTable[i].Constructor);
         prot = (ProtocolTable[i].Constructor)();
         YASDI_DEBUG((VERBOSE_MESSAGE,"Configured protocol for device '%5s' is: '%s'...\n", device->cName, ProtocolTable[i].ProtName  ));

         //Eintragen...
         newentry = os_malloc(sizeof(TProtocolMapEntry));
         assert(newentry);
         newentry->device   = device;
         newentry->protocol = prot;
         ADDHEAD( &ProtocolMap, &newentry->node );
      }
   }
}
コード例 #3
0
ファイル: slaballoc.c プロジェクト: locosoft1986/nucleos
/*===========================================================================*
 *				void *slaballoc				     *
 *===========================================================================*/
void *slaballoc(int bytes)
{
	int i;
	int count = 0;
	struct slabheader *s;
	struct slabdata *firstused;

	SLABSANITYCHECK(SCL_FUNCTIONS);

	/* Retrieve entry in slabs[]. */
	GETSLAB(bytes, s);
	vm_assert(s);

	/* To make the common case more common, make space in the 'used'
	 * queue first.
	 */
	if(!LH(s, LIST_USED)) {
		/* Make sure there is something on the freelist. */
	SLABSANITYCHECK(SCL_DETAIL);
		if(!LH(s, LIST_FREE)) {
			struct slabdata *nd = newslabdata(LIST_FREE);
	SLABSANITYCHECK(SCL_DETAIL);
			if(!nd) return NULL;
			ADDHEAD(nd, s, LIST_FREE);
	SLABSANITYCHECK(SCL_DETAIL);
		}


	SLABSANITYCHECK(SCL_DETAIL);
		MOVEHEAD(s, LIST_FREE, LIST_USED);
	SLABSANITYCHECK(SCL_DETAIL);

	}
	SLABSANITYCHECK(SCL_DETAIL);

	vm_assert(s);
	firstused = LH(s, LIST_USED);
	vm_assert(firstused);
	vm_assert(firstused->sdh.magic1 == MAGIC1);
	vm_assert(firstused->sdh.magic2 == MAGIC2);
	vm_assert(firstused->sdh.nused < ITEMSPERPAGE(bytes));

	for(i = firstused->sdh.freeguess;
		count < ITEMSPERPAGE(bytes); count++, i++) {
	SLABSANITYCHECK(SCL_DETAIL);
		i = i % ITEMSPERPAGE(bytes);

		if(!GETBIT(firstused, i)) {
			struct slabdata *f;
			char *ret;
			SETBIT(firstused, i);
	SLABSANITYCHECK(SCL_DETAIL);
			if(firstused->sdh.nused == ITEMSPERPAGE(bytes)) {
	SLABSANITYCHECK(SCL_DETAIL);
				MOVEHEAD(s, LIST_USED, LIST_FULL);
	SLABSANITYCHECK(SCL_DETAIL);
			}
	SLABSANITYCHECK(SCL_DETAIL);
			ret = ((char *) firstused->data) + i*bytes;

#if SANITYCHECKS
			nojunkwarning++;
			slabunlock(ret, bytes);
			nojunkwarning--;
			vm_assert(!nojunkwarning);
			*(u32_t *) ret = NOJUNK;
			slablock(ret, bytes);
#endif
			SLABSANITYCHECK(SCL_FUNCTIONS);
			SLABDATAUSE(firstused, firstused->sdh.freeguess = i+1;);

#if SANITYCHECKS
	if(bytes >= SLABSIZES+MINSIZE) {
		printk("slaballoc: odd, bytes %d?\n", bytes);
	}
			if(!slabsane_f(__FILE__, __LINE__, ret, bytes))
				vm_panic("slaballoc: slabsane failed", NO_NUM);
#endif

			return ret;
		}

	SLABSANITYCHECK(SCL_DETAIL);

	}
コード例 #4
0
ファイル: smfPrint.c プロジェクト: ibm-messaging/mq-smf-csv
FILE *smfPrintStart(FILE *fp, char *name, void *p, size_t l, BOOL *f, BOOL *newFile,columnHeader_t **h)
{
  FILE *fpNew = fp;
  BOOL first = *f;
  int i;

  offsetH=0;
  offsetD=0;
  columnCount=0;
  tableName = name;
  columnHeadersTmp = h;
  localFirst = first;
  /* Dump the entire record in hex */
  if (debugLevel >=1 )
  {
    printDEBUG(name,p,(l));
  }

  if (first) {
    switch (outputFormat)
    {
    case OF_CSV:
    case OF_SQL:
      fpNew = fopencsv(name,newFile);
      if (outputFormat == OF_SQL)
        openDDL(name);

      if (!fpNew)
      {
        exit(1);
      }
      break;
    case OF_JSON:
      if (!fpNew)
      {
        fpNew = fopenext("MQSMF","json",newFile);
        if (!fpNew)
        {
          exit(1);
        }
      }
      break;
    }
    for(i=0;i<HEADINGS_COUNT;i++) {
      h[i] = 0;
    }
  }
  if (outputFormat == OF_JSON)
    jsonNew(fpNew,name);

  ADDSTR ("Date",commonF.recordDate,8);
  ADDSTR ("Time",commonF.recordTime,16);
  ADDSTRN("LPAR",commonF.systemId,4,4);
  ADDSTRN("QMgr",commonF.qMgr,4,4);
  ADDSTRN("MQ_Version",commonF.mqVer,3,3);

  if (recordType == 115 && commonF.intstart != 0)
  {
    char *dt[2];
    unsigned long long du = conv64(commonF.intduration)/1000000L;
    ADDTIME("Interval_Start",commonF.intstart);
    ADDHEAD("Interval_Duration",DDL_I,0);
    /* Not documented, but this subtype uses a different scale for */
    /* measuring the duration.                                     */
    if (recordSubType == 231)
    {
      ADDDATA(ODT_I64,"%llu,",du/4096L);
    } else {
      ADDDATA(ODT_I64,"%llu,",du);
    }
  }
  *f = first;

  return fpNew;
}
コード例 #5
0
ファイル: test.c プロジェクト: michalsc/AROS
int
main ()
{
    int a;
    short b;
    APTR ptr;
    WORD c;
    struct List l;
    ListPtr lptr;
    struct Node n;

    /* Store an int in a BE 16bit data type */
    c = 15;
    a = c;  // Check if all conversions work
    b = c;

    // Try to print the data
    printf ("Must be 15 15 15: %d %d %d\n", a, b, (int)c);
    putchar ('\n');

    // Same with a pointer
    ptr = &lptr;

    // Note that the pointer must be casted but the compiler will print
    // a warning if the cast is missing:
    //	warning: cannot pass objects of type `APTR' through `...'
    // These three lines must print the same values.
    printf ("APTR %p %p\n", &lptr, (void *)ptr);
    hexdump (&ptr, sizeof (ptr));
    ptr.print (); putchar ('\n');
    putchar ('\n');

    // Same with a pointer
    char * p1;
    STRPTR p2;

    p1 = "hello";
    p2 = p1;

    // Note that the pointer must be casted but the compiler will print
    // a warning if the cast is missing:
    //	warning: cannot pass objects of type `STRPTR' through `...'
    // The first line must print two equal pointers and the second line
    // must print two times "hello".
    printf ("string %p %p\n", p1, (void *)p2);
    printf ("%s %s\n", p1, (UBYTE *)p2);
    putchar ('\n');

    // Show the contents of the memory (to prove that the actual data is BE)
    printf ("Contents of p1 (host endianess) and p2 (big endian):\n");
    hexdump (&p1, sizeof (p1));
    hexdump (&p2, sizeof (p2));
    putchar ('\n');

    // Same with a structure
    lptr = &l;
    // Print address of list header
    printf ("&lptr %p\n", &lptr);
    // Print list pointers (host and BE) which must be equal (otherwise the
    // BE pointer is not converted correctly).
    printf ("List %p %p\n", &l, (void *)lptr);
    // Show that it's really a BE pointer
    hexdump (&lptr, sizeof (lptr));
    // Print the real contents of the variable in host endianess
    lptr.print ();
    putchar ('\n');
    putchar ('\n');

    // Try some functions on the list
    NEWLIST(lptr);
    printf ("NewList %p %p %p\n", (void *)(l.lh_Head), (void *)l.lh_Tail, (void *)l.lh_TailPred);
    printf ("NewList %p %p %p\n", (void *)(lptr->lh_Head), (void *)lptr->lh_Tail, (void *)lptr->lh_TailPred);
    hexdump (&l, sizeof (struct List));
    putchar ('\n');

    ADDHEAD(lptr, &n);
    printf ("&Node %p\n", &n);
    printf ("AddHead %p %p %p\n", (void *)l.lh_Head, (void *)l.lh_Tail, (void *)l.lh_TailPred);
    putchar ('\n');

    return 0;
}
コード例 #6
0
ファイル: mempool.c プロジェクト: Balipeace/SMysqLogger
void TMemPool_FreeElem(TMemPool * me, void * elem )
{
   //lay it back to list...
   ADDHEAD(&me->poolList, ((TMinNode*)elem));
   me->currcount--;
}