summaryrefslogtreecommitdiff
path: root/src/platform/posix/posix_impl.h
blob: 56cc5937f4cc81b549c5c3b13e19cb12118ee632 (plain)
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
72
73
74
75
76
77
78
79
80
81
//
// Copyright 2017 Garrett D'Amore <garrett@damore.org>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt).  A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//

#ifndef PLATFORM_POSIX_IMPL_H
#define PLATFORM_POSIX_IMPL_H

// Some dependency notes:
//
// PLATFORM_POSIX_THREAD depends on PLATFORM_POSIX_CLOCK.  Furthermore,
// when using PLATFORM_POSIX_CLOCK, your condition variable timeouts need
// to use the same base clock values.  Normally these should be used
// together.  Almost everything depends on PLATFORM_POSIX_DEBUG.
#ifdef  PLATFORM_POSIX
#define PLATFORM_POSIX_ALLOC
#define PLATFORM_POSIX_DEBUG
#define PLATFORM_POSIX_CLOCK
#define PLATFORM_POSIX_IPC
#define PLATFORM_POSIX_NET
#define PLATFORM_POSIX_PIPE
#define PLATFORM_POSIX_RANDOM
#define PLATFORM_POSIX_THREAD

#include "platform/posix/posix_config.h"
#endif

#ifdef PLATFORM_POSIX_DEBUG
extern int nni_plat_errno(int);

#endif


#ifdef PLATFORM_POSIX_NET
struct nni_plat_tcpsock {
	int	fd;
	int	devnull; // used for shutting down blocking accept()
};
#endif

#ifdef PLATFORM_POSIX_IPC
struct nni_plat_ipcsock {
	int	fd;
	int	devnull;        // used for shutting down blocking accept()
	char *	unlink;         // path to unlink at termination
};
#endif

// Define types that this platform uses.
#ifdef PLATFORM_POSIX_THREAD

extern int nni_plat_devnull;    // open descriptor on /dev/null

#include <pthread.h>

// These types are provided for here, to permit them to be directly inlined
// elsewhere.

struct nni_plat_mtx {
	int		init;
	pthread_mutex_t mtx;
};

struct nni_plat_thr {
	pthread_t	tid;
	void		(*func)(void *);
	void *		arg;
};

struct nni_plat_cv {
	pthread_cond_t		cv;
	pthread_mutex_t *	mtx;
};

#endif

#endif // PLATFORM_POSIX_IMPL_H