Moving pending signals to task group; Logic to recover some MQ resources on pthread_cacancel or task_delete; Now obeys rules for delivering signals to a process with threads
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5613 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
a6e6cb3daa
commit
9acfb81b34
@ -91,6 +91,8 @@
|
||||
* Private Variables
|
||||
**************************************************************************/
|
||||
|
||||
static mqd_t g_send_mqfd;
|
||||
|
||||
/**************************************************************************
|
||||
* Private Functions
|
||||
**************************************************************************/
|
||||
@ -101,7 +103,6 @@
|
||||
|
||||
static void *sender_thread(void *arg)
|
||||
{
|
||||
mqd_t mqfd;
|
||||
char msg_buffer[TEST_MSGLEN];
|
||||
struct mq_attr attr;
|
||||
int status = 0;
|
||||
@ -127,11 +128,11 @@ static void *sender_thread(void *arg)
|
||||
* already created it.
|
||||
*/
|
||||
|
||||
mqfd = mq_open("testmq", O_WRONLY|O_CREAT, 0666, &attr);
|
||||
if (mqfd < 0)
|
||||
g_send_mqfd = mq_open("testmq", O_WRONLY|O_CREAT, 0666, &attr);
|
||||
if (g_send_mqfd < 0)
|
||||
{
|
||||
printf("sender_thread: ERROR mq_open failed\n");
|
||||
pthread_exit((pthread_addr_t)1);
|
||||
printf("sender_thread: ERROR mq_open failed\n");
|
||||
pthread_exit((pthread_addr_t)1);
|
||||
}
|
||||
|
||||
/* Fill in a test message buffer to send */
|
||||
@ -142,7 +143,7 @@ static void *sender_thread(void *arg)
|
||||
|
||||
for (i = 0; i < TEST_SEND_NMSGS; i++)
|
||||
{
|
||||
status = mq_send(mqfd, msg_buffer, TEST_MSGLEN, 42);
|
||||
status = mq_send(g_send_mqfd, msg_buffer, TEST_MSGLEN, 42);
|
||||
if (status < 0)
|
||||
{
|
||||
printf("sender_thread: ERROR mq_send failure=%d on msg %d\n", status, i);
|
||||
@ -156,7 +157,7 @@ static void *sender_thread(void *arg)
|
||||
|
||||
/* Close the queue and return success */
|
||||
|
||||
if (mq_close(mqfd) < 0)
|
||||
if (mq_close(g_send_mqfd) < 0)
|
||||
{
|
||||
printf("sender_thread: ERROR mq_close failed\n");
|
||||
}
|
||||
@ -247,6 +248,7 @@ static void *receiver_thread(void *arg)
|
||||
j, TEST_MESSAGE[j], TEST_MESSAGE[j], msg_buffer[j]);
|
||||
}
|
||||
}
|
||||
|
||||
printf("receiver_thread: %2d 00 %02x\n",
|
||||
j, msg_buffer[j]);
|
||||
}
|
||||
@ -284,6 +286,7 @@ void mqueue_test(void)
|
||||
void *result;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param sparam;
|
||||
FAR void *expected;
|
||||
int prio_min;
|
||||
int prio_max;
|
||||
int prio_mid;
|
||||
@ -378,16 +381,38 @@ void mqueue_test(void)
|
||||
/* Then cancel the thread and see if it did */
|
||||
|
||||
printf("mqueue_test: Canceling receiver\n");
|
||||
|
||||
expected = PTHREAD_CANCELED;
|
||||
status = pthread_cancel(receiver);
|
||||
if (status == ESRCH)
|
||||
{
|
||||
printf("mqueue_test: receiver has already terminated\n");
|
||||
expected = (FAR void *)0;
|
||||
}
|
||||
|
||||
/* Check the result. If the pthread was canceled, PTHREAD_CANCELED is the
|
||||
* correct result. Zero might be returned if the thread ran to completion
|
||||
* before it was canceled.
|
||||
*/
|
||||
|
||||
pthread_join(receiver, &result);
|
||||
if (result != (void*)0)
|
||||
if (result != expected)
|
||||
{
|
||||
printf("mqueue_test: ERROR receiver thread exited with %d errors\n", (int)result);
|
||||
printf("mqueue_test: ERROR receiver thread should have exited with %d\n",
|
||||
expected);
|
||||
printf(" ERROR Instead exited with nerrors=%d\n",
|
||||
(int)result);
|
||||
}
|
||||
|
||||
/* Message queues are global resources and persist for the life the the
|
||||
* task group. The message queue opened by the sender_thread must be closed
|
||||
* since the sender pthread may have been canceled and may have left the
|
||||
* message queue open.
|
||||
*/
|
||||
|
||||
if (mq_close(g_send_mqfd) < 0)
|
||||
{
|
||||
printf("sender_thread: ERROR mq_close failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user