Linux??????????????????????????
???????????? ???????[ 2013/1/30 10:04:08 ] ????????
???????????????????
//??????????????????????????????
//???????????sec??????????
//?????????????????????????ID?????????
bool ManagePthread_TimeReadSignal(PTHREAD_BUF *rbuf?? PTHREAD_ID thread_num?? int sec)
{
bool b_valid = false;
struct timespec to;
int err;
to.tv_sec = time(NULL) + sec;
to.tv_nsec = 0;
//????
pthread_mutex_lock(&managePthread.g_pthread_mutex[thread_num]);
//???sec???????????????select
err = pthread_cond_timedwait(&managePthread.g_pthread_cond[thread_num]?? &managePthread.g_pthread_mutex[thread_num]?? &to);
if(err == ETIMEDOUT)
{
pthread_mutex_unlock(&managePthread.g_pthread_mutex[thread_num]);
return false;
}
//?????????
if(managePthread.g_pthread_info[thread_num] == WRITE_FLAG)
{
managePthread.g_pthread_info[thread_num] = READ_FLAG;
memcpy((PTHREAD_BUF *)rbuf?? (PTHREAD_BUF *)&managePthread.g_pthread_buf[thread_num]?? sizeof(PTHREAD_BUF));
b_valid = true;
}
//????
pthread_mutex_unlock(&managePthread.g_pthread_mutex[thread_num]);
return b_valid;
}
//?????????????
bool ManagePthread_ReadSignal(PTHREAD_BUF *rbuf?? PTHREAD_ID thread_num?? bool wait)
{
bool b_valid = false;
pthread_mutex_lock(&managePthread.g_pthread_mutex[thread_num]);
if(wait == true)
pthread_cond_wait(&managePthread.g_pthread_cond[thread_num]?? &managePthread.g_pthread_mutex[thread_num]);
if(managePthread.g_pthread_info[thread_num] == WRITE_FLAG)
{
managePthread.g_pthread_info[thread_num] = READ_FLAG;
memcpy((PTHREAD_BUF *)rbuf?? (PTHREAD_BUF *)&managePthread.g_pthread_buf[thread_num]?? sizeof(PTHREAD_BUF));
b_valid = true;
}
pthread_mutex_unlock(&managePthread.g_pthread_mutex[thread_num]);
return b_valid;
}
//????/??????????
bool ManagePthread_SendSignal(PTHREAD_BUF *sbuf?? PTHREAD_ID thread_num)
{
bool b_valid = false;
pthread_mutex_lock(&managePthread.g_pthread_mutex[thread_num]);
managePthread.g_pthread_info[thread_num] = WRITE_FLAG;
if(sbuf)
{
memcpy((PTHREAD_BUF *)&managePthread.g_pthread_buf[thread_num]?? (PTHREAD_BUF *)sbuf?? sizeof(PTHREAD_BUF));
}
pthread_mutex_unlock(&managePthread.g_pthread_mutex[thread_num]);
pthread_cond_signal(&managePthread.g_pthread_cond[thread_num]);
b_valid = true;
return b_valid;
}
//??
bool ManagePthread_BroadcastSignal(PTHREAD_BUF *sbuf?? PTHREAD_ID thread_num)
{
bool b_valid = false;
pthread_mutex_lock(&managePthread.g_pthread_mutex[thread_num]);
managePthread.g_pthread_info[thread_num] = WRITE_FLAG;
memcpy((PTHREAD_BUF *)&managePthread.g_pthread_buf[thread_num]?? (PTHREAD_BUF *)sbuf?? sizeof(PTHREAD_BUF));
pthread_mutex_unlock(&managePthread.g_pthread_mutex[thread_num]);
pthread_cond_broadcast(&managePthread.g_pthread_cond[thread_num]);
b_valid = true;
return b_valid;
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11