forked from xuos/xiuos
				
			fix timer bug in posix_support for XiZi kernel
This commit is contained in:
		
							parent
							
								
									ca0ef77764
								
							
						
					
					
						commit
						f962cf6919
					
				|  | @ -57,7 +57,6 @@ int timer_create(clockid_t clockid, struct sigevent * evp, timer_t * timerid) | ||||||
| { | { | ||||||
|     int timer_id; |     int timer_id; | ||||||
|     char timer_name[16]; |     char timer_name[16]; | ||||||
|     sem_t sem; |  | ||||||
| 
 | 
 | ||||||
|     if ((NULL == evp) || (NULL == timerid)) { |     if ((NULL == evp) || (NULL == timerid)) { | ||||||
|         errno = EINVAL; |         errno = EINVAL; | ||||||
|  | @ -73,8 +72,7 @@ int timer_create(clockid_t clockid, struct sigevent * evp, timer_t * timerid) | ||||||
|     memset(timer_name, 0, sizeof(timer_name)); |     memset(timer_name, 0, sizeof(timer_name)); | ||||||
|     snprintf(timer_name, sizeof(timer_name), "timer_%ld", clockid); |     snprintf(timer_name, sizeof(timer_name), "timer_%ld", clockid); | ||||||
| 
 | 
 | ||||||
|     sem = timer_sem[clockid]; |     sem_init(&(timer_sem[clockid]), 0, 0); | ||||||
|     sem_init(&sem, 0, 0); |  | ||||||
| 
 | 
 | ||||||
|     g_timer_func[clockid].value = evp->sigev_value; |     g_timer_func[clockid].value = evp->sigev_value; | ||||||
|     g_timer_func[clockid].user_timer_function = evp->sigev_notify_function; |     g_timer_func[clockid].user_timer_function = evp->sigev_notify_function; | ||||||
|  | @ -89,8 +87,8 @@ int timer_create(clockid_t clockid, struct sigevent * evp, timer_t * timerid) | ||||||
|     args.arg = &clockid; |     args.arg = &clockid; | ||||||
| 
 | 
 | ||||||
|     pthread_create(&(timer_task[clockid]), &attr, &timer_callback, (void *)&args); |     pthread_create(&(timer_task[clockid]), &attr, &timer_callback, (void *)&args); | ||||||
|      | 
 | ||||||
|     timer_id = UserTimerCreate(timer_name, NULL, (void *)&(timer_sem[clockid]), 1000, g_timer_func[clockid].timer_flags); |     timer_id = UserTimerCreate(timer_name, NULL, (void *)&(timer_sem[clockid]), clockid, g_timer_func[clockid].timer_flags); | ||||||
|     *timerid = timer_id; |     *timerid = timer_id; | ||||||
|     return timer_id; |     return timer_id; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -775,19 +775,24 @@ uint8_t UserGetTaskPriority(int32_t id) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #ifdef KERNEL_SOFTTIMER | #ifdef KERNEL_SOFTTIMER | ||||||
| static int32 timer_sem; | #define TIMER_NUM 20 | ||||||
|  | static int32 timer_sem[TIMER_NUM]; | ||||||
|  | static uint32_t timer_id[TIMER_NUM]; | ||||||
| static void UserTimerCallback(void *parameter) | static void UserTimerCallback(void *parameter) | ||||||
| { | { | ||||||
|    KSemaphoreAbandon(timer_sem); |    uint32_t timer_id = *((uint32_t *)parameter); | ||||||
|  |    KSemaphoreAbandon(timer_sem[timer_id]); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int32 UserTimerCreate(const char *name, void (*timeout)(void *parameter), void *parameter, uint32_t time, uint8_t trigger_mode) | int32 UserTimerCreate(const char *name, void (*timeout)(void *parameter), void *parameter, uint32_t time, uint8_t trigger_mode) | ||||||
| { | { | ||||||
|    int32 ret; |    int32 ret; | ||||||
| 
 | 
 | ||||||
|    timer_sem = *((int *)parameter); |    timer_id[time] = time; | ||||||
|  |    timer_sem[time] = *((int *)parameter); | ||||||
|  | 
 | ||||||
|  |    ret = KCreateTimer(name, UserTimerCallback, (void *)&(timer_id[time]), 1000, trigger_mode); | ||||||
| 
 | 
 | ||||||
|    ret = KCreateTimer(name, UserTimerCallback, NONE, time, trigger_mode); |  | ||||||
|    return ret; |    return ret; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -301,7 +301,9 @@ void CheckTimerList(void) | ||||||
|                 ((WorkQueueDoneType *)sys_workq->done)->WorkSubmit((WorkqueueType *)sys_workq->property, t->t_work, 0); |                 ((WorkQueueDoneType *)sys_workq->done)->WorkSubmit((WorkqueueType *)sys_workq->property, t->t_work, 0); | ||||||
|                 lock = CriticalAreaLock(); |                 lock = CriticalAreaLock(); | ||||||
|             } else { |             } else { | ||||||
|                 KPrintf("sortlist run unactive timer(%s), quit this timer\n", t->name); |                 // KPrintf("sortlist run unactive timer(%s), current %d deadline %d quit this timer\n", 
 | ||||||
|  |                 //     t->name, current_tick, t->deadline_timeslice);
 | ||||||
|  |                 break; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         else |         else | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue