-
Notifications
You must be signed in to change notification settings - Fork 17
/
event.c
74 lines (66 loc) · 1.61 KB
/
event.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/********************************************************************/
/* Copyright (C) SSE-USTC, 2010 */
/* */
/* FILE NAME : event.c */
/* PRINCIPAL AUTHOR : Mengning */
/* SUBSYSTEM NAME : ChatSys */
/* MODULE NAME : ChatSys */
/* LANGUAGE : C */
/* TARGET ENVIRONMENT : ANY */
/* DATE OF FIRST RELEASE : 2010/12/03 */
/* DESCRIPTION : implement of Event ¡¤¡¤ */
/********************************************************************/
/*
* Revision log:
*
* Created by Mengning,2010/12/03
*
*/
#include"event.h"
#include<stdio.h>
#include<semaphore.h>
#define SUCCESS 0
#define FAILURE (-1)
/*
* Initialize an Event
* input : tEvent *pEvent, Memory allocate outside
* input : Value (0)
* return : SUCCESS(0)/FAILURE(-1)
*
*/
int EventInit(tEvent *pEvent,int Value)
{
if(sem_init(pEvent,0,Value) != SUCCESS)
{
printf("sem_init failure!\n");
return FAILURE;
}
return SUCCESS;
}
/*
* Shutdown an Event
* input : ...
*
*/
int EventShut(tEvent *pEvent)
{
sem_destroy(pEvent);
return SUCCESS;
}
/*
* ....
*
*/
int SentEvent(tEvent *pEvent)
{
return sem_post(pEvent);
}
/*
* ...
* return : SUCCESS(0)/FAILURE(-1)
*
*/
int WaitEvent(tEvent *pEvent)
{
return sem_wait(pEvent);
}