semaphore.c
资源名称:gateway-1.2.1 [点击查看]
上传用户:gzpyjq
上传日期:2013-01-31
资源大小:1852k
文件大小:1k
源码类别:
手机WAP编程
开发平台:
WINDOWS
- /*
- * semaphore.c - implementation of semaphores
- *
- * Lars Wirzenius
- */
- #include "gwlib/gwlib.h"
- struct Semaphore {
- List *list;
- };
- Semaphore *semaphore_create(long n)
- {
- Semaphore *semaphore;
- static char item;
- semaphore = gw_malloc(sizeof(*semaphore));
- semaphore->list = list_create();
- list_add_producer(semaphore->list);
- while (n-- > 0)
- list_produce(semaphore->list, &item);
- return semaphore;
- }
- void semaphore_destroy(Semaphore *semaphore)
- {
- if (semaphore != NULL) {
- list_destroy(semaphore->list, NULL);
- gw_free(semaphore);
- }
- }
- void semaphore_up(Semaphore *semaphore)
- {
- static char item;
- list_produce(semaphore->list, &item);
- }
- void semaphore_down(Semaphore *semaphore)
- {
- list_consume(semaphore->list);
- }