forked from gozfree/gear-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibthread.h
53 lines (43 loc) · 1.28 KB
/
libthread.h
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
/*****************************************************************************
* Copyright (C) 2014-2015
* file: libthread.h
* author: gozfree <[email protected]>
* created: 2015-08-15 22:57
* updated: 2016-01-03 15:38
*****************************************************************************/
#ifndef LIBTHREAD_H
#define LIBTHREAD_H
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <liblock.h>
#ifdef __cplusplus
extern "C" {
#endif
#define PTHREAD_NAME_LEN 16
typedef struct thread {
pthread_t tid;
spin_lock_t *spin;
mutex_lock_t *mutex;
mutex_cond_t *cond;
sem_lock_t *sem;
char name[PTHREAD_NAME_LEN];
void *(*func)(struct thread *, void *);
char *fmt;
void *arg;
} thread_t;
struct thread *thread_create(void *(*func)(struct thread *, void *), void *arg);
void thread_destroy(struct thread *t);
int thread_spin_lock(struct thread *t);
int thread_spin_unlock(struct thread *t);
int thread_sem_wait(struct thread *t, int64_t ms);
int thread_sem_signal(struct thread *t);
int thread_mutex_lock(struct thread *t);
int thread_mutex_unlock(struct thread *t);
int thread_cond_wait(struct thread *t, int64_t ms);
int thread_cond_signal(struct thread *t);
int thread_cond_signal_all(struct thread *t);
#ifdef __cplusplus
}
#endif
#endif