1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // clib/cfathread.h -- |
---|
8 | // |
---|
9 | // Author : Thierry Delisle |
---|
10 | // Created On : Tue Sep 22 15:31:20 2020 |
---|
11 | // Last Modified By : |
---|
12 | // Last Modified On : |
---|
13 | // Update Count : |
---|
14 | // |
---|
15 | |
---|
16 | #include "stddef.h" |
---|
17 | #include "invoke.h" |
---|
18 | |
---|
19 | #if defined(__cforall) || defined(__cplusplus) |
---|
20 | extern "C" { |
---|
21 | #endif |
---|
22 | #include <asm/types.h> |
---|
23 | #include <errno.h> |
---|
24 | #include <unistd.h> |
---|
25 | |
---|
26 | |
---|
27 | //-------------------- |
---|
28 | // Basic types |
---|
29 | |
---|
30 | typedef struct cluster * cfathread_cluster_t; |
---|
31 | |
---|
32 | int cfathread_cluster_create(cfathread_cluster_t * cluster); |
---|
33 | cfathread_cluster_t cfathread_cluster_self(void); |
---|
34 | int cfathread_cluster_add_worker(cfathread_cluster_t cluster, pthread_t* tid, void (*init_routine) (void *), void * arg); |
---|
35 | int cfathread_cluster_pause (cfathread_cluster_t cluster); |
---|
36 | int cfathread_cluster_resume(cfathread_cluster_t cluster); |
---|
37 | |
---|
38 | //-------------------- |
---|
39 | // thread attribute |
---|
40 | typedef struct cfathread_attr { |
---|
41 | cfathread_cluster_t cl; |
---|
42 | } cfathread_attr_t; |
---|
43 | |
---|
44 | int cfathread_attr_init(cfathread_attr_t * attr) __attribute__((nonnull (1))); |
---|
45 | static inline int cfathread_attr_destroy(cfathread_attr_t * attr) __attribute__((nonnull (1))); |
---|
46 | static inline int cfathread_attr_destroy(cfathread_attr_t * attr) { return 0; } |
---|
47 | static inline int cfathread_attr_setbackground(cfathread_attr_t * attr, int background) __attribute__((nonnull (1))); |
---|
48 | static inline int cfathread_attr_setbackground(cfathread_attr_t * attr, int background) { return 0; } |
---|
49 | static inline int cfathread_attr_setcluster(cfathread_attr_t * attr, cfathread_cluster_t cl) __attribute__((nonnull (1))); |
---|
50 | static inline int cfathread_attr_setcluster(cfathread_attr_t * attr, cfathread_cluster_t cl) { attr->cl = cl; return 0; } |
---|
51 | |
---|
52 | //-------------------- |
---|
53 | // thread type |
---|
54 | struct cfathread_object; |
---|
55 | typedef struct cfathread_object * cfathread_t; |
---|
56 | |
---|
57 | int cfathread_create( cfathread_t * h, const cfathread_attr_t * a, void *(*main)( void * ), void * arg ) __attribute__((nonnull (1))); |
---|
58 | int cfathread_join( cfathread_t, void ** retval ); |
---|
59 | |
---|
60 | int cfathread_get_errno(void); |
---|
61 | cfathread_t cfathread_self(void); |
---|
62 | |
---|
63 | int cfathread_usleep(useconds_t usecs); |
---|
64 | int cfathread_sleep(unsigned int secs); |
---|
65 | |
---|
66 | void cfathread_park( void ); |
---|
67 | void cfathread_unpark( cfathread_t ); |
---|
68 | void cfathread_yield( void ); |
---|
69 | |
---|
70 | //-------------------- |
---|
71 | // mutex and condition |
---|
72 | struct timespec; |
---|
73 | |
---|
74 | typedef struct cfathread_mutex_attr { |
---|
75 | } cfathread_mutexattr_t; |
---|
76 | typedef struct cfathread_mutex * cfathread_mutex_t; |
---|
77 | int cfathread_mutex_init(cfathread_mutex_t *restrict mut, const cfathread_mutexattr_t *restrict attr) __attribute__((nonnull (1))); |
---|
78 | int cfathread_mutex_destroy(cfathread_mutex_t *mut) __attribute__((nonnull (1))); |
---|
79 | int cfathread_mutex_lock(cfathread_mutex_t *mut) __attribute__((nonnull (1))); |
---|
80 | int cfathread_mutex_trylock(cfathread_mutex_t *mut) __attribute__((nonnull (1))); |
---|
81 | int cfathread_mutex_unlock(cfathread_mutex_t *mut) __attribute__((nonnull (1))); |
---|
82 | |
---|
83 | typedef struct cfathread_cond_attr { |
---|
84 | } cfathread_condattr_t; |
---|
85 | typedef struct cfathread_condition * cfathread_cond_t; |
---|
86 | int cfathread_cond_init(cfathread_cond_t *restrict cond, const cfathread_condattr_t *restrict attr) __attribute__((nonnull (1))); |
---|
87 | int cfathread_cond_wait(cfathread_cond_t *restrict cond, cfathread_mutex_t *restrict mut) __attribute__((nonnull (1,2))); |
---|
88 | int cfathread_cond_timedwait(cfathread_cond_t *restrict cond, cfathread_mutex_t *restrict mut, const struct timespec *restrict abstime) __attribute__((nonnull (1,2,3))); |
---|
89 | int cfathread_cond_signal(cfathread_cond_t *cond) __attribute__((nonnull (1))); |
---|
90 | |
---|
91 | //-------------------- |
---|
92 | // IO operations |
---|
93 | struct sockaddr; |
---|
94 | struct msghdr; |
---|
95 | int cfathread_socket(int domain, int type, int protocol); |
---|
96 | int cfathread_bind(int socket, const struct sockaddr *address, socklen_t address_len); |
---|
97 | int cfathread_listen(int socket, int backlog); |
---|
98 | int cfathread_accept(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len); |
---|
99 | int cfathread_connect(int socket, const struct sockaddr *address, socklen_t address_len); |
---|
100 | int cfathread_dup(int fildes); |
---|
101 | int cfathread_close(int fildes); |
---|
102 | ssize_t cfathread_sendmsg(int socket, const struct msghdr *message, int flags); |
---|
103 | ssize_t cfathread_write(int fildes, const void *buf, size_t nbyte); |
---|
104 | ssize_t cfathread_recvfrom(int socket, void *restrict buffer, size_t length, int flags, struct sockaddr *restrict address, socklen_t *restrict address_len); |
---|
105 | ssize_t cfathread_read(int fildes, void *buf, size_t nbyte); |
---|
106 | |
---|
107 | #if defined(__cforall) || defined(__cplusplus) |
---|
108 | } |
---|
109 | #endif |
---|