Revision b4797b9a

View differences:

chunker_player/tcp_chunk_puller.c
24 24
#include <unistd.h>
25 25
#include <pthread.h>
26 26

  
27
//handle threads through SDL
28
#include <SDL.h>
29
#include <SDL_thread.h>
30

  
27 31
#define TCP_BUF_SIZE 65536*16
28 32

  
29 33
static int accept_fd = -1;
30 34
static int socket_fd = -1;
31 35
static int isRunning = 0;
32 36
static int isReceving = 0;
33
static pthread_t AcceptThread;
34
static pthread_t RecvThread;
37
static SDL_Thread *AcceptThread;
38
static SDL_Thread *RecvThread;
35 39

  
36
static void* RecvThreadProc(void* params);
37
static void* AcceptThreadProc(void* params);
40
static int RecvThreadProc(void* params);
41
static int AcceptThreadProc(void* params);
38 42

  
39 43
int initChunkPuller(const int port)
40 44
{
......
68 72
	
69 73
	fprintf(stderr,"listening on port %d\n", port);
70 74
	
71
	if(pthread_create( &AcceptThread, NULL, &AcceptThreadProc, NULL) != 0)
75
	if((AcceptThread = SDL_CreateThread(&AcceptThreadProc, NULL)) == 0)
72 76
	{
73 77
		fprintf(stderr,"TCP-INPUT-MODULE: could not start accepting thread!!\n");
74 78
		return -1;
......
77 81
	return accept_fd;
78 82
}
79 83

  
80
static void* AcceptThreadProc(void* params)
84
static int AcceptThreadProc(void* params)
81 85
{
82 86
    int fd = -1;
83 87
    
......
103 107
		{
104 108
			isReceving = 0;
105 109
			printf("TCP-INPUT-MODULE: waiting for receive thread to terminate...\n");
106
			pthread_join(RecvThread, NULL);
107
			pthread_detach(RecvThread);
110
			SDL_WaitThread(RecvThread, NULL);
108 111
			printf("TCP-INPUT-MODULE: receive thread terminated\n");
109 112
			socket_fd = fd;
110 113
		}
111
		if(pthread_create( &RecvThread, NULL, &RecvThreadProc, NULL) != 0)
114
		if((RecvThread = SDL_CreateThread(&RecvThreadProc, NULL)) == 0)
112 115
		{
113 116
			fprintf(stderr,"TCP-INPUT-MODULE: could not start receveing thread!!\n");
114 117
			return NULL;
......
118 121
	return NULL;
119 122
}
120 123

  
121
static void* RecvThreadProc(void* params)
124
static int RecvThreadProc(void* params)
122 125
{
123 126
	int ret = -1;
124 127
	uint32_t fragment_size = 0;
......
173 176
void finalizeChunkPuller()
174 177
{
175 178
	isRunning = 0;
176
	pthread_join(AcceptThread, NULL);
177
	pthread_detach(AcceptThread);
179
	SDL_WaitThread(AcceptThread, NULL);
178 180
	
179 181
	if(socket_fd > 0)
180 182
		close(socket_fd);

Also available in: Unified diff