示例#1
0
void GrResourceCache::purgeAllUnlocked() {
    GrAutoResourceCacheValidate atcv(this);

    // we can have one GrResource holding a lock on another
    // so we don't want to just do a simple loop kicking each
    // entry out. Instead change the budget and purge.

    int savedMaxBytes = fMaxBytes;
    int savedMaxCount = fMaxCount;
    fMaxBytes = (size_t) -1;
    fMaxCount = 0;
    this->purgeAsNeeded();

#if GR_DEBUG
    GrAssert(fExclusiveList.countEntries() == fClientDetachedCount);
    GrAssert(countBytes(fExclusiveList) == fClientDetachedBytes);
    if (!fCache.count()) {
        // Items may have been detached from the cache (such as the backing
        // texture for an SkGpuDevice). The above purge would not have removed
        // them.
        GrAssert(fEntryCount == fClientDetachedCount);
        GrAssert(fEntryBytes == fClientDetachedBytes);
        GrAssert(fList.isEmpty());
    }
#endif

    fMaxBytes = savedMaxBytes;
    fMaxCount = savedMaxCount;
}
示例#2
0
String::String(const char* szBegin)
{
  init();
  if (szBegin != 0) {
    append((char*) szBegin, countBytes(szBegin));
  }
}
示例#3
0
String& String::append(const char* szBegin)
{ 
  if (szBegin != 0) {
    append(szBegin, countBytes(szBegin));
  }
  return *this;
}
示例#4
0
String& String::operator=(const char* szBegin)
{
  if (szBegin != 0) {
    append((char*) szBegin, countBytes(szBegin), 1);
  }
  return *this;
}
示例#5
0
文件: IoNumber.c 项目: Akiyah/io
IO_METHOD(IoNumber, asCharacter)
{
	/*doc Number asCharacter
	Returns a String containing a single character whose
	value is the value of the first byte of the receiver.
	Returns nil if the number has no valid UCS mapping.
	*/
	
	double d =DATA(self);
	long ld = d;
	
	if (d < 0 || d != ld)
	{
		return IONIL(self);
	}
	else
	{	
		uint32_t i = io_uint32InBigEndian((uint32_t)d);
		int bytes = countBytes(ld);
		IoSeq *s;
		
		if (bytes == 0) 
		{ 
			bytes = 1;
		}
		
		if (bytes == 3) 
		{ 
			bytes = 4;
		}
		
		if (bytes > 4) 
		{
			// no valid UCS encoding for this value
			return IONIL(self);
		}
		
		s = IoSeq_newWithData_length_(IOSTATE, (unsigned char *)&i, bytes);
		
		{
			UArray *u = IoSeq_rawUArray(s);
			int e = CENCODING_ASCII;
			
			switch (bytes)
			{
				case 1: e = CENCODING_ASCII; break;
				case 2: e = CENCODING_UCS2; break;
				case 4: e = CENCODING_UCS4; break;
			}
			
			UArray_setEncoding_(u, e);
		}
		
		return s;
	}
}
示例#6
0
void GrResourceCache::validate() const {
    fList.validate();
    fExclusiveList.validate();
    GrAssert(both_zero_or_nonzero(fEntryCount, fEntryBytes));
    GrAssert(both_zero_or_nonzero(fClientDetachedCount, fClientDetachedBytes));
    GrAssert(fClientDetachedBytes <= fEntryBytes);
    GrAssert(fClientDetachedCount <= fEntryCount);
    GrAssert((fEntryCount - fClientDetachedCount) == fCache.count());

    fCache.validate();


    EntryList::Iter iter;

    // check that the exclusively held entries are okay
    const GrResourceEntry* entry = iter.init(const_cast<EntryList&>(fExclusiveList),
                                             EntryList::Iter::kHead_IterStart);

    for ( ; NULL != entry; entry = iter.next()) {
        entry->validate();
    }

    // check that the shareable entries are okay
    entry = iter.init(const_cast<EntryList&>(fList), EntryList::Iter::kHead_IterStart);

    int count = 0;
    for ( ; NULL != entry; entry = iter.next()) {
        entry->validate();
        GrAssert(fCache.find(entry->key()));
        count += 1;
    }
    GrAssert(count == fEntryCount - fClientDetachedCount);

    size_t bytes = countBytes(fList);
    GrAssert(bytes == fEntryBytes  - fClientDetachedBytes);

    bytes = countBytes(fExclusiveList);
    GrAssert(bytes == fClientDetachedBytes);

    GrAssert(fList.countEntries() == fEntryCount - fClientDetachedCount);

    GrAssert(fExclusiveList.countEntries() == fClientDetachedCount);
}
示例#7
0
文件: policz.c 项目: turu/sysopy
int main (int argc, char **argv){
    if (argc < 2) {
        printf("Buka\n");
        return 1;
    }

    char * path = argv[1];
    if(mkfifo(path, 0660) == -1){
        printf("Could not create pajp.\n");
        return 2;
    }

    int fifo = open(path, O_RDONLY | O_NONBLOCK);
    FILE * wyniki = fopen("wyniki.log", "w");
    char buff[128];
    int res;

    while (1) {
        res = read(fifo, buff, sizeof(buff));
        if(!res){
            sleep(1);
        } else {
            char * ptr = strtok(buff, "\n"), * ptr2;
            ptr2 = strtok(NULL, "\n");
            int nonZero;

            while (ptr2 != NULL) {
                nonZero = countBytes(ptr);
                printf("%s: %d\n", ptr, nonZero);
                fprintf(wyniki, "%s: %d\n", ptr, nonZero);
                fflush(wyniki);
                ptr = ptr2;
                ptr2 = strtok(NULL, "\n");
            }
        }
    }

    fclose(wyniki);
    close(fifo);

    return 0;
}
示例#8
0
void testFunctions(){
printf("inside main\n \n ");
printf("\n validFileName tests: \n");
printf("bumba.y should return 0: ");
printf("%d\n", validFileName("bumba.y"));
printf("noDot should return 0: ");
printf("%d\n", validFileName("noDot"));
printf("victory.yo should return 1: ");
printf("%d\n", validFileName("victory.yo"));

printf("\n isAddress tests: \n");
printf("  0x01H: should return 0:");
printf("%d\n",isAddress("  0x01H:"));
printf("  1x014: should return 0:");
printf("%d\n",isAddress("  1x014:"));
printf("  0x014: should return 1:");
printf("%d\n",isAddress("  0x014:"));
printf("  0x6A4: should return 1:");
printf("%d\n",isAddress("  0x064:"));

//need to add testing for 0x014:00 ... spaces ... |
printf("\n isData tests: \n");
printf("  0x014: 0z  should return 0:");
printf("%d\n",isData("  0x014: 0z"));
printf("  0x014: 00ddxx01daq should return 0:");
printf("%d\n",isData("  0x014: 00ddxx01da0q"));
printf("  0x014: 00345dzqa000 should return 0:");
printf("%d\n",isData("  0x014: 000345dzqa000"));
printf("  0x014: 00ddd0000000 should return 1:");
printf("%d\n",isData("  0x014: 00ddd0000000 "));
printf("  0x014: 00000000001 should return 1: ");
printf("%d\n",isData("  0x014: 000000000001"));
printf("  0x014: 01 should return 1: ");
printf("%d\n",isData("  0x014: 01"));

printf("\n isSpaces tests: \n");
printf("should return 0: wxrHtl-jhplzsk");
printf("%d\n",isSpaces("wxrHtl-jhplzsk",0,14));
printf("%d\n",isSpaces("wxrHtl-jhplzsk",0,14));
printf("isSpaces should return 1: ");
printf("%d\n",isSpaces("               ",0,14));
printf("isSpaces should return 1: ");
printf("%d\n",isSpaces("   ",0,2));
printf("isSpaces should return 0: ");
printf("%d\n",isSpaces("d  ",0,2));

printf("checkHex tests: \n");
printf("abcdzf0123456789 should return 0: ");
printf("%d\n",checkHex("abcdzf0123456789",0,15));
printf("abcdef0123456789 should return 1: ");
printf("%d\n",checkHex("abcdef0123456789",0,15));

printf("grabAddress tests: \n");
printf("  0x01a should return 0x01a: ");
printf("%x\n",grabAddress("  0x01a"));
printf("  0x014 should return 0x014: ");
printf("%x\n",grabAddress("  0x014"));

printf("grabDataByte tests: \n");
printf("  01a402, 4 should return 02: ");
printf("%x\n", grabDataByte("01a402",4));
printf("  01a402, 2 should return a4: ");
printf("%x\n", grabDataByte("01a402",2));
printf("  01, 0 should return 01: ");
printf("%x\n", grabDataByte("01",0));


printf("countBytes tests: \n");
printf("  0x014: 00000000001 should return 5: ");
printf("%x\n", countBytes("  0x014: 0000000001 "));
printf("  0x014: 0201 should return 2: ");
printf("%x\n", countBytes("  0x014: 0201"));
printf("  0x014: 020100 should return 3: ");
printf("%x\n", countBytes("  0x014: 020100"));
printf("  0x014:  should return 0: ");
printf("%x\n", countBytes("  0x014: "));

printf("checkLine tests: \n");
printf("  0x014 000000000001 |comments should return 0: ");
printf("%d\n", checkLine("  0x014 000000000001 |comments\n"));
printf("0x014: 000000000001 |comments should return 0: ");
printf("%d\n", checkLine("0x014: 000000000001 |comments\n"));
printf("  0x014: 000000000001 |comments should return 1: ");
printf("%d\n", checkLine("  0x014: 000000000001 |comments\n"));
//printf("  01a402, 2 should return a4: ");
//printf("%x\n", grabDataByte("01a402",2));

//printf("  01, 0 should return 01: ");
/*
printf("discardRest should return 0: \n");
printf("%d\n",discardRest("",0,15));
printf("discardRest should return 1: \n");
printf("%d\n",discardRest("",0,15));
*/
}
示例#9
0
void String::operator+=(const char* szBegin)
{
  if (szBegin != 0) {
    append(szBegin, countBytes(szBegin), 0);
  }
}