File: Events.h

package info (click to toggle)
procdump 3.4.1-1~exp4
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 15,276 kB
  • sloc: ansic: 202,443; cpp: 51,275; sh: 1,618; cs: 76; makefile: 12
file content (50 lines) | stat: -rw-r--r-- 1,365 bytes parent folder | download | duplicates (4)
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License

//--------------------------------------------------------------------
//
// Quick events implementation
//
//--------------------------------------------------------------------

#ifndef EVENTS_H
#define EVENTS_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <stdbool.h>
#include <errno.h>
#include <time.h>

#define MAX_EVENT_NAME 64

#define MANUAL_RESET_EVENT_INITIALIZER(NAME) \
    {\
    .mutex          = PTHREAD_MUTEX_INITIALIZER,\
    .cond           = PTHREAD_COND_INITIALIZER,\
    .bManualReset   = true,\
    .bTriggered     = false,\
    .nWaiters       = 0,\
    .Name           = NAME\
    }

struct Event {
    pthread_mutex_t mutex;
    pthread_cond_t cond;
    bool bTriggered;
    bool bManualReset;
    char Name[MAX_EVENT_NAME];
    int nWaiters;
};

struct Event *CreateEvent(bool IsManualReset, bool InitialState);
struct Event *CreateNamedEvent(bool IsManualReset, bool InitialState, char *Name);
void InitEvent(struct Event *Event, bool IsManualReset, bool InitialState);
void InitNamedEvent(struct Event *Event, bool IsManualReset, bool InitialState, char *Name);
void DestroyEvent(struct Event *Event);
bool SetEvent(struct Event *Event);
bool ResetEvent(struct Event *Event);

#endif // EVENTS_H