source: libcfa/src/concurrency/clib/cfathread.h@ 14f6a3cb

ADT ast-experimental
Last change on this file since 14f6a3cb was f5f2768, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

make _GNU_SOURCE default, change IO to use SOCKADDR_ARG and CONST_SOCKADDR_ARG, move sys/socket.h to first include because of anonymous naming problem

  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[bb662027]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
[f5f2768]11// Last Modified By : Peter A. Buhr
12// Last Modified On : Thu Feb 16 12:00:32 2023
13// Update Count : 5
[bb662027]14//
15
[038110a]16#if defined(__cforall) || defined(__cplusplus)
[f5f2768]17#include <sys/socket.h> // first include because of anonymous types __SOCKADDR_ARG, __CONST_SOCKADDR_ARG
18#include <unistd.h>
19#include <errno.h>
20
[bb662027]21extern "C" {
22#endif
23 //--------------------
24 // Basic types
[a1538cd]25
26 typedef struct cluster * cfathread_cluster_t;
27
[9e27f69]28 int cfathread_cluster_create(cfathread_cluster_t * cluster);
[a1538cd]29 cfathread_cluster_t cfathread_cluster_self(void);
[d971c8d]30 int cfathread_cluster_print_stats(cfathread_cluster_t cluster);
[a1538cd]31 int cfathread_cluster_add_worker(cfathread_cluster_t cluster, pthread_t* tid, void (*init_routine) (void *), void * arg);
32 int cfathread_cluster_pause (cfathread_cluster_t cluster);
33 int cfathread_cluster_resume(cfathread_cluster_t cluster);
34
35 //--------------------
36 // thread attribute
37 typedef struct cfathread_attr {
38 cfathread_cluster_t cl;
39 } cfathread_attr_t;
40
41 int cfathread_attr_init(cfathread_attr_t * attr) __attribute__((nonnull (1)));
[9e27f69]42 static inline int cfathread_attr_destroy(cfathread_attr_t * attr) __attribute__((nonnull (1)));
43 static inline int cfathread_attr_destroy(cfathread_attr_t * attr) { return 0; }
44 static inline int cfathread_attr_setbackground(cfathread_attr_t * attr, int background) __attribute__((nonnull (1)));
45 static inline int cfathread_attr_setbackground(cfathread_attr_t * attr, int background) { return 0; }
46 static inline int cfathread_attr_setcluster(cfathread_attr_t * attr, cfathread_cluster_t cl) __attribute__((nonnull (1)));
47 static inline int cfathread_attr_setcluster(cfathread_attr_t * attr, cfathread_cluster_t cl) { attr->cl = cl; return 0; }
[bb662027]48
49 //--------------------
[a1538cd]50 // thread type
51 struct cfathread_object;
52 typedef struct cfathread_object * cfathread_t;
53
[9e27f69]54 int cfathread_create( cfathread_t * h, const cfathread_attr_t * a, void *(*main)( void * ), void * arg ) __attribute__((nonnull (1)));
[a1538cd]55 int cfathread_join( cfathread_t, void ** retval );
56
57 int cfathread_get_errno(void);
58 cfathread_t cfathread_self(void);
59
60 int cfathread_usleep(useconds_t usecs);
61 int cfathread_sleep(unsigned int secs);
[bb662027]62
63 void cfathread_park( void );
64 void cfathread_unpark( cfathread_t );
65 void cfathread_yield( void );
66
67 //--------------------
[a1538cd]68 // mutex and condition
69 struct timespec;
70
71 typedef struct cfathread_mutex_attr {
72 } cfathread_mutexattr_t;
73 typedef struct cfathread_mutex * cfathread_mutex_t;
[f5f2768]74 int cfathread_mutex_init(cfathread_mutex_t * restrict mut, const cfathread_mutexattr_t * restrict attr) __attribute__((nonnull (1)));
[a1538cd]75 int cfathread_mutex_destroy(cfathread_mutex_t *mut) __attribute__((nonnull (1)));
76 int cfathread_mutex_lock(cfathread_mutex_t *mut) __attribute__((nonnull (1)));
77 int cfathread_mutex_trylock(cfathread_mutex_t *mut) __attribute__((nonnull (1)));
78 int cfathread_mutex_unlock(cfathread_mutex_t *mut) __attribute__((nonnull (1)));
79
80 typedef struct cfathread_cond_attr {
[c457dc41]81 // WARNING: adding support for pthread_condattr_setclock would require keeping track of the clock
82 // and reading it in cond_timedwait
[a1538cd]83 } cfathread_condattr_t;
84 typedef struct cfathread_condition * cfathread_cond_t;
85 int cfathread_cond_init(cfathread_cond_t *restrict cond, const cfathread_condattr_t *restrict attr) __attribute__((nonnull (1)));
86 int cfathread_cond_wait(cfathread_cond_t *restrict cond, cfathread_mutex_t *restrict mut) __attribute__((nonnull (1,2)));
87 int cfathread_cond_timedwait(cfathread_cond_t *restrict cond, cfathread_mutex_t *restrict mut, const struct timespec *restrict abstime) __attribute__((nonnull (1,2,3)));
88 int cfathread_cond_signal(cfathread_cond_t *cond) __attribute__((nonnull (1)));
89
90 //--------------------
91 // IO operations
92 int cfathread_socket(int domain, int type, int protocol);
[f5f2768]93 int cfathread_bind(int socket, __CONST_SOCKADDR_ARG address, socklen_t address_len);
[a1538cd]94 int cfathread_listen(int socket, int backlog);
[f5f2768]95 int cfathread_accept(int socket, __SOCKADDR_ARG address, socklen_t * restrict address_len);
96 int cfathread_connect(int socket, __CONST_SOCKADDR_ARG address, socklen_t address_len);
[a1538cd]97 int cfathread_dup(int fildes);
98 int cfathread_close(int fildes);
99 ssize_t cfathread_sendmsg(int socket, const struct msghdr *message, int flags);
100 ssize_t cfathread_write(int fildes, const void *buf, size_t nbyte);
101 ssize_t cfathread_recvfrom(int socket, void *restrict buffer, size_t length, int flags, struct sockaddr *restrict address, socklen_t *restrict address_len);
102 ssize_t cfathread_read(int fildes, void *buf, size_t nbyte);
[bb662027]103
[038110a]104#if defined(__cforall) || defined(__cplusplus)
[bb662027]105}
106#endif
Note: See TracBrowser for help on using the repository browser.