SW#
 All Files Functions Variables Typedefs Macros
thread.h
Go to the documentation of this file.
1 /*
2 swsharp - CUDA parallelized Smith Waterman with applying Hirschberg's and
3 Ukkonen's algorithm and dynamic cell pruning.
4 Copyright (C) 2013 Matija Korpar, contributor Mile Šikić
5 
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 Contact the author by mkorpar@gmail.com.
20 */
27 #ifndef __SW_SHARP_THREADH__
28 #define __SW_SHARP_THREADH__
29 
30 #ifdef _WIN32
31 #include <windows.h>
32 #else
33 #include <pthread.h>
34 #include <semaphore.h>
35 #endif
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #ifdef _WIN32
42 
45 typedef CRITICAL_SECTION Mutex;
46 
50 typedef HANDLE Semaphore;
51 
55 typedef HANDLE Thread;
56 #else
57 
60 typedef pthread_mutex_t Mutex;
61 
65 typedef sem_t Semaphore;
66 
70 typedef pthread_t Thread;
71 #endif
72 
78 extern void mutexCreate(Mutex* mutex);
79 
85 extern void mutexDelete(Mutex* mutex);
86 
92 extern void mutexLock(Mutex* mutex);
93 
99 extern void mutexUnlock(Mutex* mutex);
100 
107 extern void semaphoreCreate(Semaphore* semaphore, unsigned int value);
108 
114 extern void semaphoreDelete(Semaphore* semaphore);
115 
121 extern void semaphorePost(Semaphore* semaphore);
122 
130 extern int semaphoreValue(Semaphore* semaphore);
131 
138 extern void semaphoreWait(Semaphore* semaphore);
139 
145 extern void threadCancel(Thread thread);
146 
154 extern void threadCreate(Thread* thread, void* (*routine)(void*), void* args);
155 
161 extern void threadCurrent(Thread* thread);
162 
168 extern void threadJoin(Thread thread);
169 
175 extern void threadSleep(unsigned int ms);
176 #ifdef __cplusplus
177 }
178 #endif
179 #endif // __SW_SHARP_THREADH__
void threadCurrent(Thread *thread)
Thread getter.
void threadJoin(Thread thread)
Waits for thread to finish.
int semaphoreValue(Semaphore *semaphore)
Sempahore value getter.
sem_t Semaphore
Semaphore type.
Definition: thread.h:65
void semaphoreWait(Semaphore *semaphore)
Decreses sempahore value or waits.
void semaphorePost(Semaphore *semaphore)
Increases sempahore value.
void semaphoreDelete(Semaphore *semaphore)
Semaphore destructor.
void mutexDelete(Mutex *mutex)
Mutex destructor.
void threadCancel(Thread thread)
Cancels the current thread.
void threadSleep(unsigned int ms)
Sleeps the current thread.
void semaphoreCreate(Semaphore *semaphore, unsigned int value)
Semaphore constructor.
pthread_mutex_t Mutex
Mutex type.
Definition: thread.h:60
void mutexUnlock(Mutex *mutex)
Unlocks the mutex.
void mutexLock(Mutex *mutex)
Locks the mutex.
void mutexCreate(Mutex *mutex)
Mutex constructor.
pthread_t Thread
Thread type.
Definition: thread.h:70
void threadCreate(Thread *thread, void *(*routine)(void *), void *args)
Thread constructor.