Use cookies for thread identification instead of pointers directly which gives a buffer against wrongly identifying a thread when the slot is recycled (which has been nagging me for awhile). A slot gets 255 uses before it repeats. Everything gets incompatible so a full update is required.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19377 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Sevakis 2008-12-10 08:57:10 +00:00
parent 40ff47c7ee
commit 8cfbd3604f
32 changed files with 329 additions and 234 deletions

View file

@ -206,7 +206,7 @@ struct
{
bool foreground; /* set as long as we're owning the UI */
bool exiting; /* signal to the thread that we want to exit */
struct thread_entry *thread; /* worker thread id */
unsigned int thread; /* worker thread id */
} gTread;
static const struct plugin_api* rb; /* here is the global API struct pointer */

View file

@ -216,7 +216,7 @@ struct batt_info
#define BUF_ELEMENTS (sizeof(bat)/sizeof(struct batt_info))
static struct thread_entry *thread_id;
static unsigned int thread_id;
static struct event_queue thread_q;
static bool in_usb_mode;
static unsigned int buf_idx;
@ -537,7 +537,7 @@ int main(void)
if ((thread_id = rb->create_thread(thread, thread_stack,
sizeof(thread_stack), 0, "Battery Benchmark"
IF_PRIO(, PRIORITY_BACKGROUND)
IF_COP(, CPU))) == NULL)
IF_COP(, CPU))) == 0)
{
rb->splash(HZ, "Cannot create thread!");
return PLUGIN_ERROR;

View file

@ -732,7 +732,7 @@ bool audio_thread_init(void)
rb->queue_enable_queue_send(audio_str.hdr.q, &audio_str_queue_send,
audio_str.thread);
if (audio_str.thread == NULL)
if (audio_str.thread == 0)
return false;
/* Wait for thread to initialize */
@ -744,11 +744,11 @@ bool audio_thread_init(void)
/* Stops the audio thread */
void audio_thread_exit(void)
{
if (audio_str.thread != NULL)
if (audio_str.thread != 0)
{
str_post_msg(&audio_str, STREAM_QUIT, 0);
rb->thread_wait(audio_str.thread);
audio_str.thread = NULL;
audio_str.thread = 0;
}
#ifndef SIMULATOR

View file

@ -835,7 +835,7 @@ void disk_buf_reply_msg(intptr_t retval)
bool disk_buf_init(void)
{
disk_buf.thread = NULL;
disk_buf.thread = 0;
list_initialize(&nf_list);
rb->mutex_init(&disk_buf_mtx);
@ -893,7 +893,7 @@ bool disk_buf_init(void)
rb->queue_enable_queue_send(disk_buf.q, &disk_buf_queue_send,
disk_buf.thread);
if (disk_buf.thread == NULL)
if (disk_buf.thread == 0)
return false;
/* Wait for thread to initialize */
@ -904,10 +904,10 @@ bool disk_buf_init(void)
void disk_buf_exit(void)
{
if (disk_buf.thread != NULL)
if (disk_buf.thread != 0)
{
rb->queue_post(disk_buf.q, STREAM_QUIT, 0);
rb->thread_wait(disk_buf.thread);
disk_buf.thread = NULL;
disk_buf.thread = 0;
}
}

View file

@ -62,7 +62,7 @@ struct dbuf_range
* playback events as well as buffering */
struct disk_buf
{
struct thread_entry *thread;
unsigned int thread;
struct event_queue *q;
uint8_t *start; /* Start pointer */
uint8_t *end; /* End of buffer pointer less MPEG_GUARDBUF_SIZE. The

View file

@ -1027,7 +1027,7 @@ intptr_t parser_send_video_msg(long id, intptr_t data)
{
intptr_t retval = 0;
if (video_str.thread != NULL && disk_buf.in_file >= 0)
if (video_str.thread != 0 && disk_buf.in_file >= 0)
{
/* Hook certain messages since they involve multiple operations
* behind the scenes */

View file

@ -908,7 +908,7 @@ static void stream_mgr_thread(void)
/* Opens a new file */
int stream_open(const char *filename)
{
if (stream_mgr.thread != NULL)
if (stream_mgr.thread != 0)
return stream_mgr_send_msg(STREAM_OPEN, (intptr_t)filename);
return STREAM_ERROR;
}
@ -916,7 +916,7 @@ int stream_open(const char *filename)
/* Plays the current file starting at time 'start' */
int stream_play(void)
{
if (stream_mgr.thread != NULL)
if (stream_mgr.thread != 0)
return stream_mgr_send_msg(STREAM_PLAY, 0);
return STREAM_ERROR;
}
@ -924,7 +924,7 @@ int stream_play(void)
/* Pauses playback if playing */
int stream_pause(void)
{
if (stream_mgr.thread != NULL)
if (stream_mgr.thread != 0)
return stream_mgr_send_msg(STREAM_PAUSE, false);
return STREAM_ERROR;
}
@ -932,7 +932,7 @@ int stream_pause(void)
/* Resumes playback if paused */
int stream_resume(void)
{
if (stream_mgr.thread != NULL)
if (stream_mgr.thread != 0)
return stream_mgr_send_msg(STREAM_PAUSE, true);
return STREAM_ERROR;
}
@ -940,7 +940,7 @@ int stream_resume(void)
/* Stops playback if not stopped */
int stream_stop(void)
{
if (stream_mgr.thread != NULL)
if (stream_mgr.thread != 0)
return stream_mgr_send_msg(STREAM_STOP, 0);
return STREAM_ERROR;
}
@ -950,7 +950,7 @@ int stream_seek(uint32_t time, int whence)
{
int ret;
if (stream_mgr.thread == NULL)
if (stream_mgr.thread == 0)
return STREAM_ERROR;
stream_mgr_lock();
@ -968,7 +968,7 @@ int stream_seek(uint32_t time, int whence)
/* Closes the current file */
int stream_close(void)
{
if (stream_mgr.thread != NULL)
if (stream_mgr.thread != 0)
return stream_mgr_send_msg(STREAM_CLOSE, 0);
return STREAM_ERROR;
}
@ -1018,7 +1018,7 @@ int stream_init(void)
rb->queue_enable_queue_send(stream_mgr.q, &stream_mgr_queue_send,
stream_mgr.thread);
if (stream_mgr.thread == NULL)
if (stream_mgr.thread == 0)
{
rb->splash(HZ, "Could not create stream manager thread!");
return STREAM_ERROR;
@ -1073,11 +1073,11 @@ void stream_exit(void)
disk_buf_exit();
pcm_output_exit();
if (stream_mgr.thread != NULL)
if (stream_mgr.thread != 0)
{
stream_mgr_post_msg(STREAM_QUIT, 0);
rb->thread_wait(stream_mgr.thread);
stream_mgr.thread = NULL;
stream_mgr.thread = 0;
}
#ifndef HAVE_LCD_COLOR

View file

@ -27,7 +27,7 @@
* coordination with assistance from the parser */
struct stream_mgr
{
struct thread_entry *thread; /* Playback control thread */
unsigned int thread; /* Playback control thread */
struct event_queue *q; /* event queue for control thread */
const char *filename; /* Current filename */
uint32_t resume_time; /* The stream tick where playback was

View file

@ -45,7 +45,7 @@ struct stream_hdr
struct stream
{
struct stream_hdr hdr; /* Base stream data */
struct thread_entry *thread; /* Stream's thread */
unsigned int thread; /* Stream's thread */
uint8_t* curr_packet; /* Current stream packet beginning */
uint8_t* curr_packet_end; /* Current stream packet end */
struct list_item l; /* List of streams - either reserve pool

View file

@ -1009,7 +1009,7 @@ bool video_thread_init(void)
rb->queue_enable_queue_send(video_str.hdr.q, &video_str_queue_send,
video_str.thread);
if (video_str.thread == NULL)
if (video_str.thread == 0)
return false;
/* Wait for thread to initialize */
@ -1022,11 +1022,11 @@ bool video_thread_init(void)
/* Terminates the video thread */
void video_thread_exit(void)
{
if (video_str.thread != NULL)
if (video_str.thread != 0)
{
str_post_msg(&video_str, STREAM_QUIT, 0);
rb->thread_wait(video_str.thread);
IF_COP(invalidate_icache());
video_str.thread = NULL;
video_str.thread = 0;
}
}

View file

@ -218,7 +218,7 @@ struct mutex slide_cache_stack_lock;
static int empty_slide_hid;
struct thread_entry *thread_id;
unsigned int thread_id;
struct event_queue thread_q;
static char tmp_path_name[MAX_PATH];
@ -831,7 +831,7 @@ bool create_pf_thread(void)
IF_PRIO(, PRIORITY_BACKGROUND)
IF_COP(, CPU)
)
) == NULL) {
) == 0) {
return false;
}
thread_is_running = true;

View file

@ -525,7 +525,7 @@ static enum plugin_status test_track(const char* filename)
long ticks;
unsigned long speed;
unsigned long duration;
struct thread_entry* codecthread_id;
unsigned int codecthread_id;
const char* ch;
/* Display filename (excluding any path)*/
@ -590,7 +590,7 @@ static enum plugin_status test_track(const char* filename)
if ((codecthread_id = rb->create_thread(codec_thread,
codec_stack, codec_stack_size, 0, "testcodec"
IF_PRIO(,PRIORITY_PLAYBACK) IF_COP(, CPU))) == NULL)
IF_PRIO(,PRIORITY_PLAYBACK) IF_COP(, CPU))) == 0)
{
log_text("Cannot create codec thread!",true);
goto exit;

View file

@ -39,7 +39,7 @@ static unsigned long hw_sampr IDATA_ATTR = HW_SAMPR_DEFAULT;
static int gen_thread_stack[DEFAULT_STACK_SIZE/sizeof(int)] IBSS_ATTR;
static bool gen_quit IBSS_ATTR;
static struct thread_entry *gen_thread_p;
static unsigned int gen_thread_id;
#define OUTPUT_CHUNK_COUNT (1 << 1)
#define OUTPUT_CHUNK_MASK (OUTPUT_CHUNK_COUNT-1)
@ -233,11 +233,11 @@ static void play_tone(bool volume_set)
output_clear();
update_gen_step();
gen_thread_p = rb->create_thread(gen_thread_func, gen_thread_stack,
sizeof(gen_thread_stack), 0,
"test_sampr generator"
IF_PRIO(, PRIORITY_PLAYBACK)
IF_COP(, CPU));
gen_thread_id = rb->create_thread(gen_thread_func, gen_thread_stack,
sizeof(gen_thread_stack), 0,
"test_sampr generator"
IF_PRIO(, PRIORITY_PLAYBACK)
IF_COP(, CPU));
rb->pcm_play_data(get_more, NULL, 0);
@ -260,7 +260,7 @@ static void play_tone(bool volume_set)
gen_quit = true;
rb->thread_wait(gen_thread_p);
rb->thread_wait(gen_thread_id);
rb->pcm_play_stop();