File: Handle.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 (58 lines) | stat: -rw-r--r-- 1,330 bytes parent folder | download
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License

//--------------------------------------------------------------------
//
// Generalization of Events and Semaphores (Critical Sections)
//
//--------------------------------------------------------------------

#ifndef HANDLE_H
#define HANDLE_H

#include <pthread.h>
#include <semaphore.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

#include "Events.h"
#include "Logging.h"

#define INFINITE_WAIT -1
#define WAIT_OBJECT_0 0
#define WAIT_TIMEOUT ETIMEDOUT
#define WAIT_ABANDONED 0x80

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

enum EHandleType {
    EVENT,
    SEMAPHORE
};

struct Handle {
    union {
        struct Event event;
        sem_t* semaphore;
    };
    enum EHandleType type;
};

int WaitForSingleObject(struct Handle *Handle, int Milliseconds);
int WaitForMultipleObjects(int Count, struct Handle **Handles, bool WaitAll, int Milliseconds);

#endif // HANDLE_H