static void stringref_free(GaimStringref *stringref)
{
#ifdef DEBUG
	if (REFCOUNT(stringref->ref) != 0) {
		gaim_debug(GAIM_DEBUG_ERROR, "stringref", "Free of nonzero (%d) ref stringref!\n", REFCOUNT(stringref->ref));
		return;
	}
#endif /* DEBUG */
	g_free(stringref);
}
Exemple #2
0
 int
 process(const tendrils& /*inputs*/, const tendrils& outputs)
 {
   SHOW()
   boost::this_thread::sleep(boost::posix_time::milliseconds(std::rand() % 1000));
   REFCOUNT(in);
   REFCOUNT(out);
   in->copyTo(*out);
   return ecto::OK;
 }
Exemple #3
0
void
OFVALUE::decrementRefCount()
{
    if ( DYNTYPE( type ) && value.valmem.buffer && REFCOUNT(value) != -1 && REFCOUNT(value) > 0 )
    {
        ofuint32 i;
        for (;;)
        {
            i = REFCOUNT(value);
            if ( compare_and_swap_int( REFCOUNTADDR(value), i, i-1 ) )
                break;
        }
    }
}
Exemple #4
0
void OFVALUE::listAllocate( ofuint32 listSize )
{
    value.valmem.size = 0;
    value.valmem.capacity = REFCOUNTSIZE + listSize * sizeof(OFVALUE);
    value.valmem.buffer = new char[value.valmem.capacity];
    memset( (char *)value.valmem.buffer, 0, value.valmem.capacity );
    REFCOUNT(value) = 1;
}
Exemple #5
0
void purple_stringref_unref(PurpleStringref *stringref)
{
	if (stringref == NULL)
		return;
	if (REFCOUNT(--(stringref->ref)) == 0) {
		if (stringref->ref & 0x80000000)
			gclist = g_list_remove(gclist, stringref);
		stringref_free(stringref);
	}
}
Exemple #6
0
static void stringref_free(PurpleStringref *stringref)
{
#ifdef DEBUG
	if (REFCOUNT(stringref->ref) != 0) {
		purple_debug(PURPLE_DEBUG_ERROR, "stringref", "Free of nonzero (%d) ref stringref!\n", REFCOUNT(stringref->ref));
		return;
	}
#endif /* DEBUG */
	g_free(stringref);
}
Exemple #7
0
void
OFVALUE::listIncrease( ofuint32 inc )
{
    if (inc<16)
        inc = 16;
//     cout << "listIncrease:in: buffer:" << hex << (void*)value.valmem.buffer << dec << endl;
    ofuint32 newSize = LISTSIZE(value) + inc;
    value.valmem.capacity = REFCOUNTSIZE + newSize * sizeof(OFVALUE);
    char *newbuf = new char[value.valmem.capacity];
    //memset(newbuf,0,value.valmem.capacity);
    char *newpos = newbuf + REFCOUNTSIZE + LISTSIZE(value)*sizeof(OFVALUE);
    memset(newpos,0, inc * sizeof(OFVALUE) );
    if ( DYNTYPE(type) && value.valmem.buffer )
    {
        if ( LISTSIZE(value) )
        {
//             cout << "Copying " << value.valmem.size << " bytes" << endl;
            memcpy( newbuf, (char *)value.valmem.buffer, value.valmem.size );
        }
        // Decrement the original reference count, if one exists
        if ( REFCOUNT(value) != -1 )
        {
            ofuint32 i;
            for (;;)
            {
                i = REFCOUNT(value);
                // if (std::atomic_compare_exchange_weak(REFCOUNTADDR(value), &i, i-1)
                //     break;
                if (compare_and_swap_int(REFCOUNTADDR(value), i, i-1))
                    break;
            }
            if ( i == 1 )
                delete [] (char *)value.valmem.buffer;
        }
    }
//     else
//     {
//         cout << "List inc. no copy" << endl;
//     }
    value.valmem.buffer = newbuf;
    REFCOUNT(value) = 1;
//     cout << "listIncrease:out: buffer:" << hex << (void*)value.valmem.buffer << dec << endl;
}
Exemple #8
0
    int
    process(const tendrils& /*inputs*/, const tendrils& outputs)
    {
      SHOW()

//      *image = cv::Mat();
      REFCOUNT(image);
      cv::Mat out(cv::Size(640, 480), CV_8UC3, cv::Scalar(std::rand() % 255, std::rand() % 255, std::rand() % 255));
      out.copyTo(*image);
      return ecto::OK;
    }
Exemple #9
0
void
OFVALUE::set( const char *str )
{
    ofuint32 newlen = OFOS::strlen( str ) + 1 + REFCOUNTSIZE;
    //    if ( DYNTYPE( type ) )
    destroy( );
    type = typeString;
    value.valmem.capacity = value.valmem.size = newlen;
    value.valmem.buffer = new char[newlen];
    OFOS::strcpy( ((char *)value.valmem.buffer)+REFCOUNTSIZE, str );
    REFCOUNT(value) = 1;
//     cout << hex << (void*)(value.valmem.buffer) << dec << " set(char*): " << REFCOUNT( value ) << endl;
}
Exemple #10
0
void
OFVALUE::destroy( )
{
    if ( DYNTYPE( type ) && value.valmem.buffer )
    {
#if !defined(NDEBUG)
        //cout << hex << (void*)(value.valmem.buffer) << dec << " destroy ref count: 0x" << hex << REFCOUNT(value) << dec << endl;
        assert( REFCOUNT(value) != 0xdead );
        assert( REFCOUNT(value) );
        //if (REFCOUNT(value) > 3500)
        //        cout << hex << (void*)(value.valmem.buffer) << dec << " destroy ref count: 0x" << hex << REFCOUNT(value) << dec << endl;
        //assert( REFCOUNT(value) < 4000 );
#endif
        if ( REFCOUNT(value) != -1 )
        {
            // If we're a dynamic list, decrement the reference count of each 
            // element in the list
            ofuint32 i;
            for (;;)
            {
                i = REFCOUNT(value);
                if ( compare_and_swap_int( REFCOUNTADDR(value), i, i-1 ) )
                    break;
            }

            if ( i == 1 )
            {
#if !defined(NDEBUG)
                REFCOUNT(value) = 0xdead;
#endif
                delete [] (char *)value.valmem.buffer;
                value.valmem.size = value.valmem.capacity = 0;
                value.valmem.buffer = 0;
            }
        }
    }
    type = 0;
}
Exemple #11
0
void
OFVALUE::noRefCounting()
{
    if ( DYNTYPE( type ) && value.valmem.buffer )
    {
        ofuint32 i;
        for (;;)
        {
            i = REFCOUNT(value);
            if ( compare_and_swap_int( REFCOUNTADDR(value), i, (ofuint32)-1 ) )
                break;
        }
    }
}
Exemple #12
0
static gboolean gs_idle_cb(gpointer data)
{
	PurpleStringref *ref;
	GList *del;

	while (gclist != NULL) {
		ref = gclist->data;
		if (REFCOUNT(ref->ref) == 0) {
			stringref_free(ref);
		}
		del = gclist;
		gclist = gclist->next;
		g_list_free_1(del);
	}

	return FALSE;
}
Exemple #13
0
void
OFVALUE::set( const char *data, ofuint32 dataLength )
{
    ofuint32 newlen = dataLength + REFCOUNTSIZE;
    if ( DYNTYPE( type ) )
        destroy( );
    type = typeBinary;
    if ( dataLength == 0 )
    {
         value.valmem.capacity = value.valmem.size = 0;
         value.valmem.buffer = NULL;
         return;
    }
    value.valmem.capacity = value.valmem.size = newlen;
    value.valmem.buffer = new char[newlen];
    memcpy( ((char *)value.valmem.buffer)+REFCOUNTSIZE, data, dataLength );
    REFCOUNT(value) = 1;
//     cout << hex << (void*)(value.valmem.buffer) << dec << " set(char*, ofuint32): " << REFCOUNT( value ) << endl;
}
Exemple #14
0
void
OFVALUE::populate( OFVariant *variant )
{
//     cout << hex << "THIS:" << (void*)this << dec << endl;
    destroy( );
    OFIDENTITY id;
    signed char newtype = translateVariantType(variant);
    switch (newtype)
    {
    case 0: // special case because the variant had no type.
        if ( variant->isList() && variant->listSize() )
        {
//             cout << "Special case for type 0" << endl;
            OFVariant *elem = variant->listRetrieve( 1 );
            variant->convert( elem->type() );
            populate( variant );
            return;
        }
        else
        {
//             cout << "Its a list, but its empty" << endl;
            type = typeListInteger;
            return;
        }
        break;
    case typeInteger:
        set( variant->cv_ofint64() );
        break;
    case typeBoolean:
        set( variant->cv_bool() );
        break;
    case typeString:
        set( variant->cv_pcstr() );
        break;
    case typeFloat:
        set( variant->cv_double() );
        break;
    case typeOFDateTime:
        set( variant->cv_OFDateTime() );
        break;
    case typeBinary:
        set( variant->buffer(), variant->bufferSize() );
        break;
    case typeIdentity:
        id = variant->cv_identity();
        set( &id );
        break;
    case typeListInteger:
    case typeListBoolean:
    case typeListString:
    case typeListFloat:
    case typeListOFDateTime:
    case typeListIdentity:
    case typeListBinary:
        ofuint32 listSize = variant->listSize();
        listAllocate( listSize );
        value.valmem.size = REFCOUNTSIZE + (listSize) * sizeof( OFVALUE );
        for ( ofuint32 cur = 0; cur < listSize; cur++ )
        {
            LISTELEM( value, cur ).populate( variant->listRetrieve( cur+1 ) );
        }
        break;

    }
    type = newtype;
    if ( DYNTYPE( type ) && value.valmem.buffer )
    {
        REFCOUNT(value) = 1;
    }
}
Exemple #15
0
void
OFVALUE::read( StorageBlob *blob, signed char *ocaltype )
{
    type = blob->readInt32();
    if ( DYNTYPE( type ) )
    {
         // If it's a list of dynamic type, read in each element.
         // If not, read in the entire binary chunk
         if ( !LISTTYPE( type ) )
         {
              value.valmem.size = value.valmem.capacity = blob->readInt32();
              if ( value.valmem.size )
              {
                   value.valmem.size += REFCOUNTSIZE;
                   value.valmem.capacity += REFCOUNTSIZE;
                   value.valmem.buffer = new char[value.valmem.size];
                   blob->readBinary( (char *)value.valmem.buffer + REFCOUNTSIZE,
                                     value.valmem.size - REFCOUNTSIZE );
                   REFCOUNT( value ) = 1;
              }
         }
         else
         {
              ofuint32 i = blob->readInt32( );
              listAllocate( i );
              value.valmem.size = REFCOUNTSIZE + (i) * sizeof( OFVALUE );
              for ( ofuint32 cur = 0; cur < LISTSIZE(value); cur++ )
              {
                   LISTELEM(value,cur).read( blob, 0 );
              }
         }
    }
    else
    {
        OFIDENTITY x;
        switch( type )
        {
        case typeInteger:
            value.valint = blob->readInt64( );
            break;
        case typeBoolean:
            value.valbool = ( blob->readInt08( ) != 0 );
            break;
        case typeFloat:
            value.valdbl = blob->readDouble( );
            break;
        case typeOFDateTime:
            blob->readDateTime( &value.valdate );
            break;
        case typeIdentity:
            blob->readIdentity( &x );
            value.valid.id[0] = x.m_id0;
            value.valid.id[1] = x.m_id1;
            value.valid.flags = x.m_flags;
            break;
        default:
            assert(0);
            break;
        }
    }
    if ( ocaltype )
        *ocaltype = type;
}
/*
 * Test 6: es_free_err_info_list
 */
boolean_t
test6(void)
{
	boolean_t	retval = B_FALSE;
	err_info_t	*rv1 = NULL;
	err_info_t	*rv2 = NULL;
	int		start_refcnt_1;
	err_info_list_t *list;
	err_info_list_t *item;
	int		count;

	printf("\nTest 6: es_free_err_info_list\n");
	rv1 = es_create_err_info("TD", ES_ERR);
	if (rv1 == NULL) {
		printf("test FAILED\n");
	} else {
		rv2 = es_create_err_info("TI", ES_CLEANUP_ERR);
		if (rv2 == NULL) {
			printf("test FAILED\n");
		}
	}

	if (rv2 != NULL) {
		/*
		 * The reference count returned is typically 1 higher than
		 * expected, due to iternal Python issues.
		 * For testing purposes, we will just confirm that the
		 * ref. count is correctly adjusted relative to the
		 * starting value.
		 */
		start_refcnt_1 = REFCOUNT(rv1);

		count = 0;

		list = es_get_all_errors();

		/*
		 * Confirm that calling es_get_all_errors increments by 1 the
		 * reference count of an ErrorInfo object in the returned list.
		 */
		if (REFCOUNT(rv1) != (start_refcnt_1 + 1)) {
			printf("test FAILED\n");
			printf("ref count = [%d], should be [%d]\n",
			    REFCOUNT(rv1), (start_refcnt_1 + 1));
			es_free_err_info_list(list);
		} else {
			es_free_err_info_list(list);

			/*
			 * Confirm that calling es_free_err_info_list
			 * decrements by 1 the ref count for an ErrorInfo
			 * object in the freed list.
			 */
			if (REFCOUNT(rv1) != start_refcnt_1) {
				printf("test FAILED\n");
				printf("ref count = [%d], should be [%d]\n",
				    REFCOUNT(rv1), start_refcnt_1);
			} else {
				printf("test PASSED\n");
				retval = B_TRUE;
			}
		}
	}

	es_free_errors();

	return (retval);
}
Exemple #17
0
int release_object(struct objc_object ** obj)
{
	return ATOMIC_DECREMENT(REFCOUNT(*obj));
}
Exemple #18
0
int retain_object(struct objc_object ** obj)
{	
	return ATOMIC_INCREMENT(REFCOUNT(*obj));
}