示例#1
0
DWORD WINAPI _libtcas_create_frame_with_chunks_cached_worker_proc(LPVOID lpParam) {
    TCAS_pDoubleCache pDoubleCache;
    TCAS_pDoubleCacheProcArgs pArgs;
    TCAS_pFrameChunksCache pFcc;
    TCAS_QueuedFrame frame;
    VectorPtr vFrameChunks;
    pDoubleCache = (TCAS_pDoubleCache)lpParam;
    pArgs = &pDoubleCache->dcpArgs;    /* a shortcut */
    pFcc = &pArgs->fcc;     /* a shortcut */
    while (pDoubleCache->active) {
        WaitForSingleObject(pDoubleCache->semQueue, INFINITE);    /* wait for room to store the frame */
        if (pDoubleCache->active) {    /* still active */
            EnterCriticalSection(&pDoubleCache->lock);
            if (queue_get_count(pDoubleCache->qFrames) == 0)
                frame.id = pArgs->n;
            else {
                queue_retrieve_front(pDoubleCache->qFrames, &frame);
                if (frame.id == pArgs->n)
                    frame.id += queue_get_count(pDoubleCache->qFrames);
                else
                    frame.id = pArgs->n;
            }
            LeaveCriticalSection(&pDoubleCache->lock);
            while (!libtcas_frame_chunks_cache_get(pFcc, frame.id, &vFrameChunks))
                continue;
            libtcas_create_frame_with_chunks_cached(pFcc, vFrameChunks, pArgs->width, pArgs->height, &frame.buf);
            EnterCriticalSection(&pDoubleCache->lock);
            queue_push_rear(pDoubleCache->qFrames, &frame);
            LeaveCriticalSection(&pDoubleCache->lock);
            ReleaseSemaphore(pDoubleCache->semFrames, 1, NULL);    /* add an available frame */
        }
    }
    return 0;
}
示例#2
0
int DLL_EXPORT condition(queue_t * queue)
{
    int deq;
    int count = queue_get_count(queue);
    for(int i = 0; i < count; i++)
    {
        deq = queue_dequeue(queue);
        queue_enqueue(queue, deq);
    }
    return deq < 0;
}
示例#3
0
// a sample exported function
int get_sum(queue_t * queue)
{
    int sum = 0;
    for(size_t i = 0; i < queue_get_count(queue); i++)
    {
        int el = queue_dequeue(queue);
        sum+=el;
        queue_enqueue(queue, el);
    }
    return sum;
}
示例#4
0
文件: aio.c 项目: zkincaid/duet
size_t queue_get_count_ts(queue_t *queue ) 
{ 
  size_t size ;
  status_t status ;
  int tmp ;

  {
#line 449
  tmp = pthread_mutex_lock(& queue->mutex);
#line 449
  status = (status_t )tmp;
#line 450
  if (status != 0U) {
#line 451
    return ((size_t )0);
  }
#line 454
  size = queue_get_count(queue);
#line 456
  pthread_mutex_unlock(& queue->mutex);
#line 458
  return (size);
}
}
示例#5
0
文件: aio.c 项目: zkincaid/duet
static void aio_init(void) 
{ 
  aio_thread_t *aio_thread ;
  aio_req_queue_t *req_q ;
  int tstatus ;
  queue_t *queue ;
  status_t status ;
  int i ;
  size_t qcount ;
  void *tmp ;
  void *tmp___0 ;
  void *tmp___1 ;
  size_t tmp___2 ;

  {
#line 116
  pthread_attr_init(& globattr);
#line 121
  aio_thread_q = queue_create(& status, "aio", (size_t )0);
#line 122
  if ((unsigned long )aio_thread_q == (unsigned long )((void *)0)) {
#line 124
    __assert_fail("0", "aio_simple.c", 124U, "aio_init");
  }
#line 130
  i = 0;
#line 130
  while (i < 1) {
#line 132
    tmp = malloc(sizeof(aio_thread_t ));
#line 132
    aio_thread = (aio_thread_t *)tmp;
#line 133
    if ((unsigned long )aio_thread == (unsigned long )((void *)0)) {
#line 135
      __assert_fail("0", "aio_simple.c", 135U, "aio_init");
    }
#line 138
    tmp___0 = malloc(sizeof(aio_req_queue_t ));
#line 138
    req_q = (aio_req_queue_t *)tmp___0;
#line 139
    if ((unsigned long )req_q == (unsigned long )((void *)0)) {
#line 141
      __assert_fail("0", "aio_simple.c", 141U, "aio_init");
    }
#line 143
    aio_thread->req_queue = req_q;
#line 148
    tstatus = pthread_mutex_init(& (aio_thread->req_queue)->mutex, (pthread_mutexattr_t const   *)((void *)0));
#line 149
    if (tstatus != 0) {
#line 151
      __assert_fail("0", "aio_simple.c", 151U, "aio_init");
    }
#line 157
    tstatus = pthread_cond_init((pthread_cond_t * __restrict  )(& (aio_thread->req_queue)->cond),
                                (pthread_condattr_t const   * __restrict  )((void *)0));
#line 158
    if (tstatus != 0) {
#line 160
      __assert_fail("0", "aio_simple.c", 160U, "aio_init");
    }
#line 166
    queue = queue_create(& status, "aio", (size_t )0);
#line 167
    if ((unsigned long )queue == (unsigned long )((void *)0)) {
#line 169
      __assert_fail("0", "aio_simple.c", 169U, "aio_init");
    }
#line 171
    (aio_thread->req_queue)->queue = queue;
#line 177
    status = queue_enqueue(aio_thread_q, & aio_thread->link);
#line 178
    if (status != 0U) {
#line 180
      __assert_fail("0", "aio_simple.c", 180U, "aio_init");
    }
#line 130
    i ++;
  }
#line 187
  qcount = queue_get_count(aio_thread_q);
#line 188
  while (1) {
#line 188
    tmp___2 = qcount;
#line 188
    qcount --;
#line 188
    if (! tmp___2) {
#line 188
      break;
    }
#line 190
    tmp___1 = queue_dequeue(aio_thread_q, & status);
#line 190
    aio_thread = (aio_thread_t *)tmp___1;
#line 191
    if ((unsigned long )aio_thread == (unsigned long )((void *)0)) {
#line 193
      __assert_fail("0", "aio_simple.c", 193U, "aio_init");
    }
#line 195
    tstatus = pthread_create((pthread_t * __restrict  )(& aio_thread->thread), (pthread_attr_t const   * __restrict  )(& globattr),
                             & aio_thread_loop, (void * __restrict  )aio_thread);
#line 197
    if (tstatus != 0) {
#line 199
      __assert_fail("0", "aio_simple.c", 199U, "aio_init");
    }
#line 205
    status = queue_enqueue(aio_thread_q, & aio_thread->link);
#line 206
    if (status != 0U) {
#line 208
      __assert_fail("0", "aio_simple.c", 208U, "aio_init");
    }
  }
#line 211
  return;
}
}