/*=========================================================================== FUNCTION Q_PUT DESCRIPTION This function enqueues an item onto a specified queue using a specified link. DEPENDENCIES The specified queue should have been previously initialized via a call to q_init. The specified link field of the item should have been prev- iously initialized via a call to q_init_link. RETURN VALUE None. SIDE EFFECTS The specified item is placed at the tail of the specified queue. ===========================================================================*/ void q_put( q_type *q_ptr, /* Ptr to queue. */ q_link_type *link_ptr /* Ptr to item link to use for queueing. */ ) { q_lock( q_ptr ); link_ptr->next_ptr = (q_link_type *)&q_ptr->link; #ifndef FEATURE_Q_NO_SELF_QPTR link_ptr->q_ptr = q_ptr; #endif #ifndef FEATURE_Q_SINGLE_LINK link_ptr->prev_ptr = q_ptr->link.prev_ptr; #endif q_ptr->link.prev_ptr->next_ptr = link_ptr; q_ptr->link.prev_ptr = link_ptr; q_ptr->cnt++; Q_XCEPT_Q_PUT( q_ptr, link_ptr ); q_free( q_ptr ); return; } /* END q_put */
/*=========================================================================== FUNCTION Q_CHECK DESCRIPTION This function returns a pointer to the data block at the head of the queue. The data block is not removed from the queue. DEPENDENCIES The specified queue should have been initialized previously via a call to q_init. RETURN VALUE A pointer to the queue item. If the specified queue is empty, then NULL is returned. SIDE EFFECTS None ===========================================================================*/ void* q_check( q_type *q_ptr ) { q_link_type *link_ptr; #ifdef FEATURE_Q_NO_SELF_QPTR q_link_type *ret_ptr = NULL; #endif q_lock( q_ptr ); link_ptr = q_ptr->link.next_ptr; #ifdef FEATURE_Q_NO_SELF_QPTR if( q_ptr->cnt > 0 ) { ret_ptr = link_ptr; } #endif Q_XCEPT_Q_CHECK( q_ptr ); q_free( q_ptr ); #ifdef FEATURE_Q_NO_SELF_QPTR return (void *)ret_ptr; #else return link_ptr->self_ptr; #endif } /* END q_check */
void takeScreenShot(const QString filename) { q_lock(); QImage image = QImage(( uchar *) q_frameBuffer(), q_screenWidth(), q_screenHeight(), q_screenWidth() * q_screenDepth() / 8, QImage::Format_RGB16); image.save(filename, "PNG"); q_unlock(); }
/*=========================================================================== FUNCTION Q_LAST_GET DESCRIPTION This function returns the item which was most recently enqueued in a queue. Note, this is different from q_get() which returns the oldest item in a queue. DEPENDENCIES None RETURN VALUE None SIDE EFFECTS None ===========================================================================*/ void * q_last_get( q_type* q_ptr ) { q_link_type *link_ptr; #if defined(FEATURE_Q_SINGLE_LINK) || defined(FEATURE_Q_NO_SELF_QPTR) q_link_type *ret_ptr=NULL; #endif /* FEATURE_Q_SINGLE_LINK || FEATURE_Q_NO_SELF_QPTR */ q_lock( q_ptr ); #ifdef FEATURE_Q_SINGLE_LINK for( link_ptr = (q_link_type *)q_ptr; link_ptr->next_ptr != q_ptr->link.prev_ptr; link_ptr = link_ptr->next_ptr ); if( q_ptr->cnt > 0 ) { ret_ptr = link_ptr->next_ptr; q_ptr->link.prev_ptr = link_ptr; link_ptr->next_ptr = (q_link_type *)(&q_ptr->link); q_ptr->cnt--; #ifdef FEATURE_Q_NO_SELF_QPTR ret_ptr->next_ptr = NULL; #else link_ptr = ret_ptr; link_ptr->q_ptr = NULL; #endif } #else link_ptr = q_ptr->link.prev_ptr; if ( q_ptr->cnt > 0 ) { q_ptr->link.prev_ptr = link_ptr->prev_ptr; link_ptr->prev_ptr->next_ptr = &q_ptr->link; q_ptr->cnt--; #ifdef FEATURE_Q_NO_SELF_QPTR link_ptr->next_ptr = NULL; ret_ptr = link_ptr; #else link_ptr->q_ptr = NULL; #endif } #endif Q_XCEPT_Q_LAST_GET( q_ptr ); q_free( q_ptr ); #ifdef FEATURE_Q_NO_SELF_QPTR return (void *)ret_ptr; #else return link_ptr->self_ptr; #endif } /* q_last_get */
/*=========================================================================== FUNCTION Q_GET DESCRIPTION This function removes an item from the head of a specified queue. DEPENDENCIES The specified queue should have been initialized previously via a call to q_init. RETURN VALUE A pointer to the dequeued item. If the specified queue is empty, then NULL is returned. SIDE EFFECTS The head item, if any, is removed from the specified queue. ===========================================================================*/ void* q_get( q_type *q_ptr /* Ptr to queue. */ ) { q_link_type *link_ptr; #ifdef FEATURE_Q_NO_SELF_QPTR q_link_type *ret_ptr = NULL; #endif q_lock( q_ptr ); /* Get ptr to 1st queue item. */ link_ptr = q_ptr->link.next_ptr; /* Can only get an item if the queue is non empty */ if( q_ptr->cnt > 0 ) { q_ptr->link.next_ptr = link_ptr->next_ptr; #ifdef FEATURE_Q_SINGLE_LINK if (link_ptr->next_ptr == (q_link_type *)q_ptr) { q_ptr->link.prev_ptr = (q_link_type *)(&q_ptr->link); } #else link_ptr->next_ptr->prev_ptr = &q_ptr->link; #endif q_ptr->cnt--; /* Mark item as no longer in a queue. */ #ifdef FEATURE_Q_NO_SELF_QPTR link_ptr->next_ptr = NULL; ret_ptr = link_ptr; #else link_ptr->q_ptr = NULL; #endif } Q_XCEPT_Q_GET( q_ptr ); q_free( q_ptr ); #ifdef FEATURE_Q_NO_SELF_QPTR return (void *)ret_ptr; #else return link_ptr->self_ptr; #endif } /* END q_get */
/*=========================================================================== FUNCTION Q_LAST_CHECK DESCRIPTION This function returns the item which was most recently enqueued in a queue. Note, this is different from q_check() which returns the oldest item in a queue. DEPENDENCIES None RETURN VALUE None SIDE EFFECTS None ===========================================================================*/ void * q_last_check ( q_type* q_ptr /* The queue from which the item will be removed */ ) { q_link_type *link_ptr; /* For returning value. */ #if defined(FEATURE_Q_SINGLE_LINK) || defined(FEATURE_Q_NO_SELF_QPTR) q_link_type *ret_ptr=NULL; /* For returning value. */ #endif /* FEATURE_Q_SINGLE_LINK || FEATURE_Q_NO_SELF_QPTR */ /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ q_lock( q_ptr ); #ifdef FEATURE_Q_SINGLE_LINK for( link_ptr = (q_link_type *)q_ptr;link_ptr->next_ptr != q_ptr->link.prev_ptr;link_ptr=link_ptr->next_ptr); if (q_ptr->cnt > 0) { ret_ptr = link_ptr->next_ptr; #ifndef FEATURE_Q_NO_SELF_QPTR link_ptr = ret_ptr; #endif } #else link_ptr = q_ptr->link.prev_ptr; if ( q_ptr->cnt > 0 ) { #ifdef FEATURE_Q_NO_SELF_QPTR ret_ptr = link_ptr; #endif } #endif Q_XCEPT_Q_LAST_CHECK( q_ptr ); q_free( q_ptr ); #ifdef FEATURE_Q_NO_SELF_QPTR return (void *)ret_ptr; #else return ( link_ptr->self_ptr ); #endif } /* q_last_check */
bool my_queue_insert(struct my_queue *q, void *item, unsigned *pspace) { q_lock(q); bool res = false; unsigned head = q->head; unsigned tail = q->tail; unsigned space = q_space(head, tail, q->size); if (space >= 1) { q->elems[head] = item; q->head = (head + 1) & (q->size - 1); res = true; space--; } q_unlock(q); if (pspace) *pspace = space; return (res); }
bool my_queue_remove(struct my_queue *q, void **pitem, unsigned *pcount) { q_lock(q); bool res = false; unsigned head = q->head; unsigned tail = q->tail; unsigned count = q_count(head, tail, q->size); if (count >= 1) { *pitem = q->elems[tail]; q->tail = (tail + 1) & (q->size - 1); res = true; count--; } q_unlock(q); if (pcount) *pcount = count; return (res); }
void q_initDD() { if (initialized) return; DirectDrawCreate(NULL, &g_pDD, NULL); HRESULT h; h = g_pDD->SetCooperativeLevel(0, DDSCL_NORMAL); if (h != DD_OK) qDebug() << "cooperation level failed"; h = g_pDD->TestCooperativeLevel(); if (h != DD_OK) qDebug() << "cooperation level failed test"; DDSURFACEDESC ddsd; memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; h = g_pDD->CreateSurface(&ddsd, &g_pDDSSurface, NULL); if (h != DD_OK) qDebug() << "CreateSurface failed!"; if (g_pDDSSurface->GetCaps(&ddsCaps) != DD_OK) qDebug() << "GetCaps failed"; q_lock(); q_unlock(); initialized = true; }
/*=========================================================================== FUNCTION Q_LINEAR_DELETE DESCRIPTION Given a comparison function, this function traverses the elements in a queue, calls the compare function, and returns a pointer to the current element being compared if the user passed compare function returns non zero. In addition, the item will be removed from the queue. The user compare function should return 0 if the current element is not the element in which the compare function is interested. DEPENDENCIES The specified queue should have been initialized previously via a call to q_init. The user's queue elements must have q_link_type as the first element of the queued structure. The user's compare function will be passed NULL for the compare value. RETURN VALUE None SIDE EFFECTS None. ===========================================================================*/ void q_linear_delete( q_type *q_ptr, q_compare_func_type compare_func, void *param, q_action_func_type action_func ) { q_generic_item_type *item_ptr = NULL; /* Used in the traversal to point to the current item */ q_generic_item_type *prev_ptr = NULL; /* Used in the traversal to point to the item previous to ** the current item. This makes removing the current item ** a constant time operation */ /* User must provide a compare function, otherwise, this is ** meaningless. */ if( compare_func == NULL ) { return; } q_lock( q_ptr ); /* item_ptr points to the first item on the list */ item_ptr = (q_generic_item_type*)q_check( q_ptr ); prev_ptr = NULL; while( item_ptr != NULL ) { if( compare_func( item_ptr, NULL ) != 0 ) { /* Remove the item */ if( prev_ptr != NULL ) { /* Remove from the middle or tail */ prev_ptr->link.next_ptr = item_ptr->link.next_ptr; item_ptr->link.next_ptr = NULL; } else { /* Remove from the head */ q_get( q_ptr ); } /* Call the action function if there is one */ if( action_func ) { action_func( item_ptr, param ); } break; } /* Move on to the next item */ prev_ptr = item_ptr; item_ptr = (q_generic_item_type*)q_next( q_ptr, &item_ptr->link ); } /* END while traversing the queue */ q_free( q_ptr ); return; } /* END q_linear_delete */
/*=========================================================================== FUNCTION Q_DELETE_EXT DESCRIPTION This function removes an item from a specified queue. DEPENDENCIES The specified queue should have been initialized previously via a call to q_init. RETURN VALUE FALSE : if the item is not found in the queue. TRUE : if the item is found and removed from the queue. SIDE EFFECTS Input item is deleted from the queue. ===========================================================================*/ boolean q_delete_ext( #ifdef FEATURE_Q_NO_SELF_QPTR q_type *q_ptr, /* Ptr to the Queue */ #endif q_link_type *q_delete_ptr /* Ptr to link of item to delete */ ) { #ifdef FEATURE_Q_SINGLE_LINK q_link_type *link_ptr; q_type *real_q_ptr; #endif int qcount; boolean item_in_q = FALSE; #ifdef FEATURE_Q_NO_SELF_QPTR q_lock( q_ptr ); #else q_lock( q_delete_ptr->q_ptr ); #endif #ifdef FEATURE_Q_SINGLE_LINK #ifdef FEATURE_Q_NO_SELF_QPTR real_q_ptr = q_ptr; #else real_q_ptr = q_delete_ptr->q_ptr; #endif for( qcount = q_ptr->cnt, link_ptr = (q_link_type *) real_q_ptr; link_ptr->next_ptr != q_delete_ptr && qcount > 0; link_ptr = link_ptr->next_ptr, qcount--); if(qcount > 0) { link_ptr->next_ptr = q_delete_ptr->next_ptr; if(link_ptr->next_ptr == (q_link_type *) real_q_ptr) { real_q_ptr->link.prev_ptr = link_ptr; } #else q_delete_ptr->prev_ptr->next_ptr = q_delete_ptr->next_ptr; q_delete_ptr->next_ptr->prev_ptr = q_delete_ptr->prev_ptr; #endif #ifdef FEATURE_Q_NO_SELF_QPTR q_ptr->cnt--; q_delete_ptr->next_ptr = NULL; #else q_delete_ptr->q_ptr->cnt--; q_delete_ptr->q_ptr = NULL; #endif #ifdef FEATURE_Q_NO_SELF_QPTR Q_XCEPT_Q_DELETE( q_ptr, q_delete_ptr ); #else Q_XCEPT_Q_DELETE( q_delete_ptr ); #endif item_in_q = TRUE; #ifdef FEATURE_Q_SINGLE_LINK } #endif #ifdef FEATURE_Q_NO_SELF_QPTR q_free( q_ptr ); #else q_free( q_delete_ptr->q_ptr ); #endif return item_in_q; } /* END q_delete_ext */
/*=========================================================================== FUNCTION Q_INSERT DESCRIPTION This function inserts an item before a specified item on a queue. DEPENDENCIES The specified queue should have been initialized previously via a call to q_init. RETURN VALUE None. SIDE EFFECTS Input item is inserted before input item. ===========================================================================*/ void q_insert( #ifdef FEATURE_Q_NO_SELF_QPTR q_type *q_ptr, /* Ptr to the queue */ #endif q_link_type *q_insert_ptr, /* Ptr to link of item to insert */ q_link_type *q_item_ptr /* Ptr to link item to insert before */ ) { #ifdef FEATURE_Q_SINGLE_LINK q_link_type *link_ptr; #endif #ifdef FEATURE_Q_NO_SELF_QPTR q_lock( q_ptr ); #else q_lock( q_item_ptr->q_ptr ); #endif q_insert_ptr->next_ptr = q_item_ptr; #ifdef FEATURE_Q_SINGLE_LINK /* Start at beginning of queue and find the item that will be before the ** new item */ #ifdef FEATURE_Q_NO_SELF_QPTR link_ptr = (q_link_type *) q_ptr; #else link_ptr = (q_link_type *) q_item_ptr->q_ptr; #endif while (link_ptr->next_ptr != q_item_ptr) { link_ptr = link_ptr->next_ptr; } link_ptr->next_ptr = q_insert_ptr; #else q_insert_ptr->prev_ptr = q_item_ptr->prev_ptr; q_item_ptr->prev_ptr->next_ptr = q_insert_ptr; q_item_ptr->prev_ptr = q_insert_ptr; #endif #ifdef FEATURE_Q_NO_SELF_QPTR q_ptr->cnt++; #else q_insert_ptr->q_ptr = q_item_ptr->q_ptr; q_item_ptr->q_ptr->cnt++; #endif #ifdef FEATURE_Q_NO_SELF_QPTR Q_XCEPT_Q_INSERT( q_ptr, q_insert_ptr, q_item_ptr ); #else Q_XCEPT_Q_INSERT( q_insert_ptr, q_item_ptr ); #endif #ifdef FEATURE_Q_NO_SELF_QPTR q_free( q_ptr ); #else q_free( q_item_ptr->q_ptr ); #endif return; } /* END q_insert */
GNC::GCS::TipoListaEspera::size_type GNC::GCS::WaitQueue::Pending() { ILocker q_lock(this); const TipoListaEspera::size_type npending = m_Size - m_ListaEspera.size(); return npending; }