Changeset 82d56184 in mainline for uspace/lib/c/generic/adt/prodcons.c


Ignore:
Timestamp:
2011-06-01T21:05:19Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5cac9cd
Parents:
682cfceb (diff), 5d1b3aa (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/adt/prodcons.c

    r682cfceb r82d56184  
    11/*
    2  * Copyright (c) 2009 Martin Decky
     2 * Copyright (c) 2011 Martin Decky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 #include <test.h>
     29/** @addtogroup libc
     30 * @{
     31 */
     32/** @file
     33 */
    3034
    31 const char *test_fpu1(void)
     35#include <adt/prodcons.h>
     36#include <adt/list.h>
     37#include <fibril_synch.h>
     38
     39void prodcons_initialize(prodcons_t *pc)
    3240{
    33         return NULL;
     41        list_initialize(&pc->list);
     42        fibril_mutex_initialize(&pc->mtx);
     43        fibril_condvar_initialize(&pc->cv);
    3444}
     45
     46void prodcons_produce(prodcons_t *pc, link_t *item)
     47{
     48        fibril_mutex_lock(&pc->mtx);
     49       
     50        list_append(item, &pc->list);
     51        fibril_condvar_signal(&pc->cv);
     52       
     53        fibril_mutex_unlock(&pc->mtx);
     54}
     55
     56link_t *prodcons_consume(prodcons_t *pc)
     57{
     58        fibril_mutex_lock(&pc->mtx);
     59       
     60        while (list_empty(&pc->list))
     61                fibril_condvar_wait(&pc->cv, &pc->mtx);
     62       
     63        link_t *head = pc->list.next;
     64        list_remove(head);
     65       
     66        fibril_mutex_unlock(&pc->mtx);
     67       
     68        return head;
     69}
     70
     71/** @}
     72 */
Note: See TracChangeset for help on using the changeset viewer.