mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-29 16:31:05 +02:00
A multiple of whitespace / indent fixes.
Move the cache lock up to the allocator of the cache pages. There is
a possible race between tuxtxt_allocate_page and tuxtxt_clear_pages.
One customer reported repeated crashes while zapping. Debugging the core dump
lead me to believe there is a race going on as the variables appeared to have been
erased while it was allocating a page, and in the end crashing on an unallocated
page.
git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@1396 e54a6e83-5905-42d5-8d5c-058d10e6a962
Origin commit data
------------------
Commit: d26267a541
Author: nightshad <nightshad@e54a6e83-5905-42d5-8d5c-058d10e6a962>
Date: 2011-04-12 (Tue, 12 Apr 2011)
This commit is contained in:
@@ -71,7 +71,8 @@ void tuxtxt_compress_page(int p, int sp, unsigned char* buffer)
|
||||
pg->bitmask[i>>3] |= 0x80>>(i&0x07);
|
||||
cbuf[j++]=buffer[i];
|
||||
}
|
||||
if (pg->pData) free(pg->pData);//realloc(pg->pData,j); realloc scheint nicht richtig zu funktionieren?
|
||||
if (pg->pData)
|
||||
free(pg->pData);//realloc(pg->pData,j); realloc scheint nicht richtig zu funktionieren?
|
||||
pg->pData = (unsigned char*)malloc(j);
|
||||
if (pg->pData)
|
||||
{
|
||||
@@ -79,18 +80,18 @@ void tuxtxt_compress_page(int p, int sp, unsigned char* buffer)
|
||||
}
|
||||
else
|
||||
memset(pg->bitmask,0,sizeof(pg->bitmask));
|
||||
|
||||
#else
|
||||
//if (pg->pData)
|
||||
memmove(pg->data,buffer,23*40);
|
||||
#endif
|
||||
pthread_mutex_unlock(&tuxtxt_cache_lock);
|
||||
|
||||
}
|
||||
|
||||
void tuxtxt_decompress_page(int p, int sp, unsigned char* buffer)
|
||||
{
|
||||
pthread_mutex_lock(&tuxtxt_cache_lock);
|
||||
tstCachedPage* pg = tuxtxt_cache.astCachetable[p][sp];
|
||||
|
||||
memset(buffer,' ',23*40);
|
||||
if (!pg)
|
||||
{
|
||||
@@ -347,7 +348,7 @@ int tuxtxt_GetSubPage(int page, int subpage, int offset)
|
||||
* clear_cache *
|
||||
******************************************************************************/
|
||||
|
||||
void tuxtxt_clear_cache()
|
||||
void tuxtxt_clear_cache(void)
|
||||
{
|
||||
pthread_mutex_lock(&tuxtxt_cache_lock);
|
||||
int clear_page, clear_subpage, d26;
|
||||
@@ -501,29 +502,34 @@ void tuxtxt_decode_p2829(unsigned char *vtxt_row, tstExtData **ptExtData)
|
||||
|
||||
void tuxtxt_erase_page(int magazine)
|
||||
{
|
||||
pthread_mutex_lock(&tuxtxt_cache_lock);
|
||||
tstCachedPage* pg = tuxtxt_cache.astCachetable[tuxtxt_cache.current_page[magazine]][tuxtxt_cache.current_subpage[magazine]];
|
||||
if (pg)
|
||||
{
|
||||
memset(&(pg->pageinfo), 0, sizeof(tstPageinfo)); /* struct pageinfo */
|
||||
memset(pg->p0, ' ', 24);
|
||||
#if TUXTXT_COMPRESS == 1
|
||||
if (pg->pData) {free(pg->pData); pg->pData = NULL;}
|
||||
if (pg->pData) {
|
||||
free(pg->pData);
|
||||
pg->pData = NULL;
|
||||
}
|
||||
#elif TUXTXT_COMPRESS == 2
|
||||
memset(pg->bitmask, 0, 23*5);
|
||||
#else
|
||||
memset(pg->data, ' ', 23*40);
|
||||
#endif
|
||||
}
|
||||
pthread_mutex_unlock(&tuxtxt_cache_lock);
|
||||
}
|
||||
|
||||
void tuxtxt_allocate_cache(int magazine)
|
||||
{
|
||||
// Lock here as we have a possible race here with
|
||||
// tuxtxt_clear_cache(). We should not be allocating and
|
||||
// freeing at the same time.
|
||||
pthread_mutex_lock(&tuxtxt_cache_lock);
|
||||
|
||||
/* check cachetable and allocate memory if needed */
|
||||
if (tuxtxt_cache.astCachetable[tuxtxt_cache.current_page[magazine]][tuxtxt_cache.current_subpage[magazine]] == 0)
|
||||
{
|
||||
|
||||
tuxtxt_cache.astCachetable[tuxtxt_cache.current_page[magazine]][tuxtxt_cache.current_subpage[magazine]] = (tstCachedPage*) malloc(sizeof(tstCachedPage));
|
||||
if (tuxtxt_cache.astCachetable[tuxtxt_cache.current_page[magazine]][tuxtxt_cache.current_subpage[magazine]] )
|
||||
{
|
||||
@@ -533,12 +539,17 @@ void tuxtxt_allocate_cache(int magazine)
|
||||
tuxtxt_erase_page(magazine);
|
||||
tuxtxt_cache.cached_pages++;
|
||||
}
|
||||
else // Be a little verbose in case a crash is going to happen.
|
||||
{
|
||||
printf("tuxtxt: memory allocation failed!!! expect a crash\n");
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&tuxtxt_cache_lock);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* CacheThread *
|
||||
******************************************************************************/
|
||||
//#define TUXTXT_DEBUG 1 //FIXME
|
||||
static int stop_cache = 0;
|
||||
void *tuxtxt_CacheThread(void * /*arg*/)
|
||||
{
|
||||
@@ -561,7 +572,7 @@ void *tuxtxt_CacheThread(void * /*arg*/)
|
||||
unsigned char pagedata[9][23*40];
|
||||
tstPageinfo *pageinfo_thread;
|
||||
|
||||
printf("TuxTxt running thread...(%03x)\n",tuxtxt_cache.vtxtpid);
|
||||
printf("TuxTxt running thread...(%04x)\n",tuxtxt_cache.vtxtpid);
|
||||
tuxtxt_cache.receiving = 1;
|
||||
nice(3);
|
||||
while (!stop_cache)
|
||||
@@ -569,7 +580,8 @@ void *tuxtxt_CacheThread(void * /*arg*/)
|
||||
/* check stopsignal */
|
||||
pthread_testcancel();
|
||||
|
||||
if (!tuxtxt_cache.receiving) continue;
|
||||
if (!tuxtxt_cache.receiving)
|
||||
continue;
|
||||
|
||||
/* read packet */
|
||||
ssize_t readcnt;
|
||||
@@ -624,7 +636,7 @@ void *tuxtxt_CacheThread(void * /*arg*/)
|
||||
if (packet_number == 0 && tuxtxt_cache.current_page[magazine] != -1 && tuxtxt_cache.current_subpage[magazine] != -1)
|
||||
tuxtxt_compress_page(tuxtxt_cache.current_page[magazine],tuxtxt_cache.current_subpage[magazine],pagedata[magazine]);
|
||||
|
||||
//printf("********************** receiving packet %d page %03x subpage %02x\n",packet_number, tuxtxt_cache.current_page[magazine],tuxtxt_cache.current_subpage[magazine]);//FIXME
|
||||
//printf("********************** receiving packet %d page %03x subpage %02x\n",packet_number, tuxtxt_cache.current_page[magazine],tuxtxt_cache.current_subpage[magazine]);//FIXME
|
||||
|
||||
/* analyze row */
|
||||
if (packet_number == 0)
|
||||
@@ -1027,7 +1039,8 @@ void *tuxtxt_CacheThread(void * /*arg*/)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
/******************************************************************************
|
||||
* start_thread *
|
||||
@@ -1035,8 +1048,8 @@ void *tuxtxt_CacheThread(void * /*arg*/)
|
||||
int tuxtxt_start_thread(int source = 0);
|
||||
int tuxtxt_start_thread(int source)
|
||||
{
|
||||
if (tuxtxt_cache.vtxtpid == -1) return 0;
|
||||
|
||||
if (tuxtxt_cache.vtxtpid == -1)
|
||||
return 0;
|
||||
|
||||
tuxtxt_cache.thread_starting = 1;
|
||||
tuxtxt_init_demuxer(source);
|
||||
|
Reference in New Issue
Block a user