Chinaunix首页 | 论坛 | 博客
  • 博客访问: 702224
  • 博文数量: 152
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1793
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-12 12:26
个人简介

相信自己,只有不想做的,没有做不到的。

文章分类

全部博文(152)

文章存档

2021年(1)

2015年(2)

2014年(74)

2013年(75)

分类: Web开发

2013-10-27 10:08:02

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
;
}

阅读(1219) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~