| 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 |
#ifdef WIN32 |
| 32 |
# include <winsock2.h> |
| 33 |
# include <ws2tcpip.h> |
| 34 |
# include <iostream> |
| 35 |
|
| 36 |
typedef HANDLE pthread_t; |
| 37 |
extern char nameProgram[]; |
| 38 |
|
| 39 |
#endif |
| 40 |
|
| 41 |
#ifdef UNIX |
| 42 |
# include <pthread.h> |
| 43 |
# include <iostream> |
| 44 |
# include <unistd.h> |
| 45 |
#endif |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
#ifdef WIN32 |
| 50 |
|
| 51 |
# define MUTEX_THREAD_LOCK(a) \ |
| 52 |
mutexThreadLock(a) |
| 53 |
|
| 54 |
|
| 55 |
# define MUTEX_THREAD_UNLOCK(a) \ |
| 56 |
mutexThreadUnlock(a) |
| 57 |
|
| 58 |
|
| 59 |
# define MUTEX_THREAD_RELEASE(a) \ |
| 60 |
mutexThreadRelease(a) |
| 61 |
|
| 62 |
|
| 63 |
# define CREATE_THREAD(a,b,c,d,e) \ |
| 64 |
createThread(a,b,c,d,e) |
| 65 |
|
| 66 |
|
| 67 |
# define MUTEX_THREAD_INIT(a) \ |
| 68 |
mutexThreadInit(a) |
| 69 |
|
| 70 |
|
| 71 |
# define pthread_cleanup_push(a,b) |
| 72 |
# define pthread_cleanup_pop(a) |
| 73 |
#endif |
| 74 |
|
| 75 |
#ifdef UNIX |
| 76 |
|
| 77 |
# define MUTEX_THREAD_LOCK(a) \ |
| 78 |
mutexThreadLock(&a) |
| 79 |
|
| 80 |
|
| 81 |
# define MUTEX_THREAD_UNLOCK(a) \ |
| 82 |
mutexThreadUnlock(&a) |
| 83 |
|
| 84 |
|
| 85 |
# define MUTEX_THREAD_RELEASE(a) \ |
| 86 |
mutexThreadRelease(&a) |
| 87 |
|
| 88 |
|
| 89 |
# define CREATE_THREAD(a,b,c,d,e) \ |
| 90 |
createThread(a,b,c,d,e) |
| 91 |
|
| 92 |
|
| 93 |
# define MUTEX_THREAD_INIT(a) \ |
| 94 |
mutexThreadInit(&a) |
| 95 |
#endif |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
int createThread(void *argument, void *(nameFunction) (void *), void *attrib, pthread_t& idThread, bool detach); |
| 102 |
|
| 103 |
|
| 104 |
int joinThread(int numFlow, pthread_t hThr[]); |
| 105 |
|
| 106 |
|
| 107 |
int terminateThread(pthread_t idThread); |
| 108 |
|
| 109 |
|
| 110 |
void exitThread(); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
#ifdef WIN32 |
| 115 |
|
| 116 |
int mutexThreadInit(HANDLE &mutex); |
| 117 |
#endif |
| 118 |
|
| 119 |
#ifdef UNIX |
| 120 |
|
| 121 |
int mutexThreadInit(void* mutex); |
| 122 |
#endif |
| 123 |
|
| 124 |
|
| 125 |
int mutexThreadRelease(void* mutex); |
| 126 |
|
| 127 |
|
| 128 |
int mutexThreadLock(void* mutex); |
| 129 |
|
| 130 |
|
| 131 |
int mutexThreadUnlock(void* mutex); |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
int closeSock(int socket); |