18 #ifndef UTHREADS_CWRAPPER_H_ 19 #define UTHREADS_CWRAPPER_H_ 22 #include <sys/types.h> 23 #include <sys/socket.h> 43 typedef struct WCluster WCluster;
65 typedef struct WkThread WkThread;
89 typedef struct WuThread WuThread;
93 void uThread_start(WuThread* ut, WCluster* cluster,
void *func,
void *arg1 ,
void* arg2,
void* arg3);
119 typedef struct WConnection WConnection;
131 int connection_accept(WConnection* acceptor, WConnection *conn,
struct sockaddr *addr, socklen_t *addrlen);
142 int connection_bind(WConnection* conn,
const struct sockaddr *addr,socklen_t addrlen);
144 int connection_connect(WConnection* conn,
const struct sockaddr *addr,socklen_t addrlen);
149 ssize_t
connection_recv(WConnection* conn,
void *buf,
size_t len,
int flags);
151 ssize_t
connection_recvfrom(WConnection* conn,
void *buf,
size_t len,
int flags,
struct sockaddr *src_addr, socklen_t *addrlen);
153 ssize_t
connection_recvmsg(WConnection* conn,
int sockfd,
struct msghdr *msg,
int flags);
155 int connection_recvmmsg(WConnection* conn,
int sockfd,
struct mmsghdr *msgvec,
unsigned int vlen,
unsigned int flags,
struct timespec *timeout);
158 ssize_t
connection_send(WConnection* conn,
const void *buf,
size_t len,
int flags);
160 ssize_t
connection_sendto(WConnection* conn,
int sockfd,
const void *buf,
size_t len,
int flags,
const struct sockaddr *dest_addr, socklen_t addrlen);
164 int connection_sendmmsg(WConnection* conn,
int sockfd,
struct mmsghdr *msgvec,
unsigned int vlen,
unsigned int flags);
190 typedef struct WMutex WMutex;
208 typedef struct WOwnerLock WOwnerLock;
225 struct WConditionVariable;
226 typedef struct WConditionVariable WConditionVariable;
248 typedef struct WSemaphore WSemaphore;
266 typedef struct WuThreadPool WuThreadPool;
267 WuThreadPool* uthreadpool_create();
268 void uthreadpool_destory(WuThreadPool* utp);
269 void uthreadpool_execute(WuThreadPool* utp, WCluster* cluster,
void *(*start_routine) (
void *),
void *arg);
WkThread * kThread_create(WCluster *cluster)
Definition: cwrapper.cpp:38
WuThread * uThread_create(bool joinable)
Create a uThread with a given stack size.
Definition: cwrapper.cpp:50
WConditionVariable * condition_variable_create()
Definition: cwrapper.cpp:141
void condition_variable_wait(WConditionVariable *cv, WMutex *mutex)
Block uThread on the condition variable using the provided mutex.
Definition: cwrapper.cpp:143
ssize_t connection_send(WConnection *conn, const void *buf, size_t len, int flags)
Call the underlying system call on Connection's file descriptor.
Definition: cwrapper.cpp:101
WCluster * cluster_get_current()
Definition: cwrapper.cpp:32
WMutex * mutex_create()
Definition: cwrapper.cpp:127
int connection_get_fd(WConnection *conn)
Definition: cwrapper.cpp:120
ssize_t connection_recvfrom(WConnection *conn, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
Call the underlying system call on Connection's file descriptor.
Definition: cwrapper.cpp:90
void ownerlock_destroy(WOwnerLock *olock)
Definition: cwrapper.cpp:135
int connection_connect(WConnection *conn, const struct sockaddr *addr, socklen_t addrlen)
Same as connect syscall.
Definition: cwrapper.cpp:84
ssize_t connection_write(WConnection *conn, const void *buf, size_t count)
Call the underlying system call on Connection's file descriptor.
Definition: cwrapper.cpp:115
void condition_variable_signal(WConditionVariable *cv, WMutex *mutex)
Unblock one uThread waiting on the condition variable.
Definition: cwrapper.cpp:144
ssize_t connection_read(WConnection *conn, void *buf, size_t count)
Call the underlying system call on Connection's file descriptor.
Definition: cwrapper.cpp:114
pthread_t kThread_get_current_pthread_id()
return the native hanlde for the kernel thread
Definition: cwrapper.cpp:43
bool semaphore_p(WSemaphore *sem)
Decrement the value of the Semaphore.
Definition: cwrapper.cpp:152
bool mutex_acquire(WMutex *mutex)
acquire the mutex
Definition: cwrapper.cpp:129
int connection_socket(WConnection *conn, int domain, int type, int protocol)
Same as socket syscall, set the fd for current connection.
Definition: cwrapper.cpp:78
void condition_variable_signall_all(WConditionVariable *cv, WMutex *mutex)
unblock all uThreads waiting on the condition variable
Definition: cwrapper.cpp:145
void ownerlock_release(WOwnerLock *olock)
Definition: cwrapper.cpp:137
uint64_t uThread_get_id(WuThread *ut)
get the ID of this uThread
Definition: cwrapper.cpp:59
void mutex_destroy(WMutex *mutex)
Definition: cwrapper.cpp:128
void semaphore_destroy(WSemaphore *sem)
Definition: cwrapper.cpp:151
uint64_t uThread_get_total_number_of_uThreads()
Definition: cwrapper.cpp:61
void mutex_release(WMutex *mutex)
release the Mutex
Definition: cwrapper.cpp:130
WConnection * connection_create_socket(int domain, int type, int protocol)
Same as socket syscall adds | SOCK_NONBLOCK to type.
Definition: cwrapper.cpp:68
WCluster * cluster_create()
Definition: cwrapper.cpp:29
void uThread_start(WuThread *ut, WCluster *cluster, void *func, void *arg1, void *arg2, void *arg3)
start the uThread by calling the function passed to it
Definition: cwrapper.cpp:51
void semaphore_v(WSemaphore *sem)
increment the value of the Semaphore
Definition: cwrapper.cpp:153
uint64_t cluster_get_id(WCluster *cluster)
Get the ID of Cluster.
Definition: cwrapper.cpp:33
WConnection * connection_accept_connenction(WConnection *acceptor, struct sockaddr *addr, socklen_t *addrlen)
Accepts a connection and returns a connection object.
Definition: cwrapper.cpp:74
void condition_variable_destroy(WConditionVariable *cv)
Definition: cwrapper.cpp:142
bool uThread_join(WuThread *ut)
Wait for uThread to finish execution and exit.
Definition: cwrapper.cpp:57
uint64_t kThread_get_total_number_of_kThreads()
Definition: cwrapper.cpp:40
ssize_t connection_sendto(WConnection *conn, int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
Call the underlying system call on Connection's file descriptor.
Definition: cwrapper.cpp:104
WkThread * kThread_get_current()
Get the pointer to the current kThread.
Definition: cwrapper.cpp:41
int connection_sendmmsg(WConnection *conn, int sockfd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags)
Call the underlying system call on Connection's file descriptor.
Definition: cwrapper.cpp:110
void connection_destroy(WConnection *c)
Definition: cwrapper.cpp:69
void uThread_migrate(WCluster *cluster)
Move the uThread to the provided cluster.
Definition: cwrapper.cpp:54
WCluster * cluster_get_default()
Definition: cwrapper.cpp:31
void uThread_terminate(WuThread *ut)
Terminates the uThread.
Definition: cwrapper.cpp:55
void cluster_destroy(WCluster *cluster)
Definition: cwrapper.cpp:30
bool condition_variable_empty(WConditionVariable *cv)
Whether the waiting list is empty or not.
Definition: cwrapper.cpp:146
int connection_close(WConnection *conn)
closes the socket
Definition: cwrapper.cpp:85
size_t cluster_get_number_of_kThreads(WCluster *cluster)
Total number of kThreads belonging to this cluster.
Definition: cwrapper.cpp:34
int connection_accept(WConnection *acceptor, WConnection *conn, struct sockaddr *addr, socklen_t *addrlen)
nonblocking accept syscall and updating the passed Connection object
Definition: cwrapper.cpp:71
WConnection * connection_create()
Create a Connection that does not have.
Definition: cwrapper.cpp:66
int connection_recvmmsg(WConnection *conn, int sockfd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags, struct timespec *timeout)
Call the underlying system call on Connection's file descriptor.
Definition: cwrapper.cpp:96
WOwnerLock * ownerlock_create()
Definition: cwrapper.cpp:134
WSemaphore * semaphore_create()
Create a new Semaphore.
Definition: cwrapper.cpp:150
uint64_t ownerlock_acquire(WOwnerLock *olock)
Definition: cwrapper.cpp:136
int connection_bind(WConnection *conn, const struct sockaddr *addr, socklen_t addrlen)
Same as bind syscall.
Definition: cwrapper.cpp:83
int connection_listen(WConnection *conn, int backlog)
Same as listen syscall on current fd.
Definition: cwrapper.cpp:82
WuThread * uThread_get_current()
Get a pointer to the current running uThread.
Definition: cwrapper.cpp:60
void uThread_detach(WuThread *ut)
Detach a joinable thread.
Definition: cwrapper.cpp:58
void connection_block_on_write(WConnection *conn)
Block uThread, waiting for fd to become ready for write.
Definition: cwrapper.cpp:118
WConnection * connection_create_with_fd(int fd)
Create a connection object with the provided fd.
Definition: cwrapper.cpp:67
void connection_block_on_read(WConnection *conn)
Block uThread, waiting for fd to become ready for read.
Definition: cwrapper.cpp:117
pthread_t kThread_get_pthread_id(WkThread *kt)
return the native hanlde for the kernel thread
Definition: cwrapper.cpp:44
ssize_t connection_recvmsg(WConnection *conn, int sockfd, struct msghdr *msg, int flags)
Call the underlying system call on Connection's file descriptor.
Definition: cwrapper.cpp:93
ssize_t connection_recv(WConnection *conn, void *buf, size_t len, int flags)
Call the underlying system call on Connection's file descriptor.
Definition: cwrapper.cpp:87
void uThread_yield()
Causes uThread to yield.
Definition: cwrapper.cpp:56
ssize_t connection_sendmsg(WConnection *conn, const struct msghdr *msg, int flags)
Call the underlying system call on Connection's file descriptor.
Definition: cwrapper.cpp:107
void kThread_destroy(WkThread *kt)
Definition: cwrapper.cpp:39