summaryrefslogtreecommitdiffstats
path: root/mpeglib/lib/util/abstract/abs_thread.h
blob: f65445d8d069eea06609d41840f3bb3f75b006e3 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
  abstraction for threads
  Copyright (C) 2000 Martin Vogt

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Library General Public License as published by
  the Free Software Foundation.

  For more information look at the file COPYRIGHT in this package

 */


#ifndef __ABS_THREAD_H
#define __ABS_THREAD_H


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

/**
   This passed alle pthread_xxx calls to this interface, thus
   it can be easier replaced with other thread "layers"

   All posix pthread calls are conveterd to abs_thread.
*/

extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
}

#define _ABS_BUSY EBUSY

#ifndef SDL_WRAPPER
// definitions for direct pthread support
#include <pthread.h>

typedef pthread_mutex_t abs_thread_mutex_t;
typedef pthread_cond_t abs_thread_cond_t;
typedef pthread_t abs_thread_t;



#define abs_thread_cond_init(cond) pthread_cond_init(cond,NULL)
#define abs_thread_cond_destroy(cond) pthread_cond_destroy(cond)
#define abs_thread_cond_signal(cond) pthread_cond_signal(cond)
#define abs_thread_cond_wait(cond,mutex) pthread_cond_wait(cond,mutex)

// CREATE / JOIN THREAD

#define abs_thread_create(thread,func,arg) pthread_create(thread,NULL,func,arg)
#define abs_thread_join(th,thread_return) pthread_join(th,thread_return)

// MUTEX FUNCTIONS

#define abs_thread_mutex_lock(mutex) pthread_mutex_lock(mutex)
#define abs_thread_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
#define abs_thread_mutex_init(mutex) pthread_mutex_init(mutex,NULL)
#define abs_thread_mutex_destroy(mutex) pthread_mutex_destroy(mutex)

#endif
// not SDL_WRAPPER

#ifdef SDL_WRAPPER


// SDL SUPPORT DISABLED 

#if defined WIN32
  #include <SDL_thread.h>
  #include <SDL_mutex.h>
#else
  #include <SDL/SDL_thread.h>
  #include <SDL/SDL_mutex.h>
#endif


typedef SDL_mutex* abs_thread_mutex_t;
typedef SDL_cond*  abs_thread_cond_t;
typedef SDL_Thread* abs_thread_t;

// SIGNAL FUNCTIONS
// note we have _no_ cond attribut (not needed)
int abs_thread_cond_init(abs_thread_cond_t* cond);
int abs_thread_cond_destroy(abs_thread_cond_t *cond);

int abs_thread_cond_signal(abs_thread_cond_t* cond);

int abs_thread_cond_wait(abs_thread_cond_t* cond,
			 abs_thread_mutex_t *mutex);
// CREATE / JOIN THREAD
// Note: we have thread attribute
int abs_thread_create(abs_thread_t* thread,
		      void * (*start_routine)(void *), void * arg);

int abs_thread_join(abs_thread_t th, 
		    void **thread_return);


// MUTEX FUNCTIONS

int abs_thread_mutex_lock(abs_thread_mutex_t *mutex);
int abs_thread_mutex_trylock(abs_thread_mutex_t *mutex);
int abs_thread_mutex_unlock(abs_thread_mutex_t *mutex);
// not attribute!
int abs_thread_mutex_init(abs_thread_mutex_t   *mutex);

int abs_thread_mutex_destroy(abs_thread_mutex_t *mutex);



#endif
//SDL_WRAPPER



#endif