main.c------------------->//创建多线程
int main(int argc, char **argv)
{
#if 1
Create_table (); //创建环境表
#endif
setLimit (1, 50, 5, 50, 10, 500, 10);
setLimit (2, 50, 5, 50, 10, 500, 10);
pthread_mutex_init (&mutex_slinklist, NULL);
pthread_mutex_init (&mutex_sqlite, NULL);
pthread_mutex_init (&mutex_analysis, NULL);
pthread_mutex_init (&mutex_uart_cmd, NULL);
pthread_mutex_init (&mutex_client_request, NULL);
pthread_mutex_init (&mutex_infrared, NULL);
pthread_mutex_init (&mutex_buzzer, NULL);
pthread_mutex_init (&mutex_led, NULL);
pthread_mutex_init (&mutex_camera, NULL);
pthread_mutex_init (&mutex_sms, NULL);
pthread_mutex_init (&mutex_refresh, NULL);
pthread_mutex_init (&mutex_refresh_updata, NULL);
pthread_mutex_init (&mutex_global, NULL);
pthread_mutex_init (&mutex_linklist, NULL);
pthread_cond_init (&cond_sqlite, NULL);
pthread_cond_init (&cond_analysis, NULL);
pthread_cond_init (&cond_uart_cmd, NULL);
pthread_cond_init (&cond_client_request, NULL);
pthread_cond_init (&cond_infrared, NULL);
pthread_cond_init (&cond_buzzer, NULL);
pthread_cond_init (&cond_led, NULL);
pthread_cond_init (&cond_camera, NULL);
pthread_cond_init (&cond_sms, NULL);
pthread_cond_init (&cond_refresh, NULL);
pthread_cond_init (&cond_refresh_updata, NULL);
signal (SIGINT, ReleaseResource);
pthread_create (&id_sqlite, 0, pthread_sqlite, NULL);
sleep (1);
pthread_create (&id_analysis, 0, pthread_analysis, NULL);
pthread_create (&id_transfer, 0, pthread_transfer, NULL);
sleep (1);
pthread_create (&id_uart_cmd, 0, pthread_uart_cmd, NULL);
pthread_create (&id_client_request, 0, pthread_client_request, NULL);
pthread_create (&id_infrared, 0, pthread_infrared, NULL);
pthread_create (&id_buzzer, 0, pthread_buzzer, NULL);
pthread_create (&id_led, 0, pthread_led, NULL);
pthread_create (&id_camera, 0, pthread_camera, NULL);
pthread_create (&id_sms, 0, pthread_sms, NULL);
pthread_create (&id_refresh, 0, pthread_refresh, NULL);
pthread_join (id_sqlite, NULL);
printf ("g1\n");
pthread_join (id_analysis, NULL);
printf ("g2\n");
pthread_join (id_transfer, NULL);
printf ("g3\n");
pthread_join (id_uart_cmd, NULL);
printf ("g4\n");
pthread_join (id_client_request, NULL);
printf ("g5\n");
pthread_join (id_infrared, NULL);
printf ("g6\n");
pthread_join (id_buzzer, NULL);
printf ("g7\n");
pthread_join (id_led, NULL);
printf ("g8\n");
pthread_join (id_camera, NULL);
printf ("g9\n");
pthread_join (id_sms, NULL);
printf ("g10\n");
pthread_join (id_refresh, NULL);
printf ("g11\n");
return 0;
}
//pthread_client_request.c ----------------->接受cgi的消息来处理相应的线程
void *pthread_client_request (void *arg)
{
key_t key;
ssize_t msgsize;
struct msg msgbuf;
struct setEnv new;
int sto_no;
if ((key = ftok ("/app", 'g')) < 0)
{
perror ("ftok msgqueue");
exit (-1);
}
if ((msgid = msgget (key, IPC_CREAT | IPC_EXCL | 0666)) < 0)
{
perror ("msgget msgid");
exit (-1);
}
printf ("pthread_client_request is ok\n");
while (1)
{
bzero (&msgbuf, sizeof (msgbuf));
// printf ("wait for the msg\n");
msgsize = msgrcv (msgid, &msgbuf, sizeof (msgbuf) - sizeof (long), 1L, 0);
// printf ("Get %ldL msg\n", msgbuf.msgtype);
// printf ("text[0] = %#x\n", msgbuf.text[0]);
switch (msgbuf.msgtype)
{
case 1L:
{
pthread_mutex_lock (&mutex_led);
dev_led_mask = msgbuf.text[0];
pthread_cond_signal (&cond_led);
pthread_mutex_unlock (&mutex_led);
break;
}
case 2L:
break;
case 3L:
break;
case 4L:
break;
case 5L:
break;
case 6L:
break;
case 7L:
break;
default:
break;
}