14 #include <sys/types.h> 28 sem_t *DIM_INIT_Semap;
58 sem_post(DIM_INIT_Semap);
94 sem_post(DIM_INIT_Semap);
148 DIM_INIT_Semap = sem_open(
"/Dim_INIT_Sem", O_CREAT, S_IRUSR | S_IWUSR, INIT_count);
156 #if defined (LYNXOS) && !defined (__Lynx__) 157 pthread_attr_create(&attr);
163 pthread_attr_init(&attr);
164 pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
170 sem_wait(DIM_INIT_Semap);
172 #if defined (LYNXOS) && !defined (__Lynx__) 180 sem_wait(DIM_INIT_Semap);
215 sem_unlink(
"/Dim_INIT_Sem");
219 sem_close(DIM_INIT_Semap);
236 #if defined (LYNXOS) && !defined (__Lynx__) 237 pthread_attr_create(&attr);
238 pthread_create(&t_id, attr, (
void *)thread_ast, (
void *)tag);
240 pthread_attr_init(&attr);
241 pthread_create(&t_id, &attr, thread_ast, (
void *)tag);
249 ret = pthread_cancel((pthread_t)t_id);
251 printf(
"dim_stop_thread: this function is obsolete, it creates memory leaks\n");
259 struct sched_param param;
263 pclass = SCHED_OTHER;
273 prio = sched_get_priority_min(pclass);
274 ret = pthread_getschedparam(
MAIN_thread, &p, ¶m);
275 if( (p == SCHED_OTHER) || (pclass == SCHED_OTHER) )
276 param.sched_priority = prio;
277 ret = pthread_setschedparam(
MAIN_thread, pclass, ¶m);
280 ret = pthread_getschedparam(
IO_thread, &p, ¶m);
281 if( (p == SCHED_OTHER) || (pclass == SCHED_OTHER) )
282 param.sched_priority = prio;
283 ret = pthread_setschedparam(
IO_thread, pclass, ¶m);
286 ret = pthread_getschedparam(
ALRM_thread, &p, ¶m);
287 if( (p == SCHED_OTHER) || (pclass == SCHED_OTHER) )
288 param.sched_priority = prio;
289 ret = pthread_setschedparam(
ALRM_thread, pclass, ¶m);
300 struct sched_param param;
302 ret = pthread_getschedparam(
MAIN_thread, pclass, ¶m);
315 struct sched_param param;
319 else if(threadId == 2)
321 else if(threadId == 3)
324 ret = pthread_getschedparam(
id, &pclass, ¶m);
325 param.sched_priority = prio;
326 ret = pthread_setschedparam(
id, pclass, ¶m);
339 struct sched_param param;
343 else if(threadId == 2)
345 else if(threadId == 3)
348 ret = pthread_getschedparam(
id, &pclass, ¶m);
349 *prio = param.sched_priority;
359 struct sigaction sig_info;
363 if( sigaction(SIGPIPE, 0, &sig_info) < 0 )
365 perror(
"sigaction(SIGPIPE)" );
368 if(sig_info.sa_handler)
377 sig_info.sa_mask =
set;
379 sig_info.sa_flags = SA_RESTART;
381 sig_info.sa_flags = 0;
384 if( sigaction(SIGPIPE, &sig_info, 0) < 0 )
386 perror(
"sigaction(SIGPIPE)" );
448 pthread_mutex_t Global_DIM_mutex = PTHREAD_MUTEX_INITIALIZER;
449 pthread_mutex_t Global_cond_mutex = PTHREAD_MUTEX_INITIALIZER;
450 pthread_cond_t Global_cond = PTHREAD_COND_INITIALIZER;
458 if(Dim_thr_locker != pthread_self())
465 pthread_mutex_lock(&Global_DIM_mutex);
466 Dim_thr_locker=pthread_self();
480 pthread_mutex_unlock(&Global_DIM_mutex);
488 pthread_mutex_lock(&Global_cond_mutex);
489 Global_cond_waiters++;
490 if(!Global_cond_counter)
492 pthread_cond_wait(&Global_cond, &Global_cond_mutex);
494 Global_cond_waiters--;
495 if(!Global_cond_waiters)
496 Global_cond_counter--;
497 pthread_mutex_unlock(&Global_cond_mutex);
502 pthread_mutex_lock(&Global_cond_mutex);
503 if(!Global_cond_waiters)
505 Global_cond_counter = 1;
509 Global_cond_counter++;
510 pthread_cond_broadcast(&Global_cond);
512 pthread_mutex_unlock(&Global_cond_mutex);
544 printf(
"dim_start_thread: not available\n");
551 printf(
"dim_stop_thread: not available\n");
565 DllExp HANDLE Global_DIM_event_auto = 0;
566 DllExp HANDLE Global_DIM_mutex = 0;
567 DllExp HANDLE Global_DIM_event_manual = 0;
571 void (*thread_ast)();
586 hthread = CreateThread(
594 hthread = CreateThread(
610 ret = TerminateThread((HANDLE)thread_id, 0);
611 CloseHandle((HANDLE)thread_id);
612 printf(
"dim_stop_thread: this function is obsolete, it creates memory leaks\n");
617 void create_io_thread()
622 hIO_thread = CreateThread(
630 hIO_thread = CreateThread(
640 void create_alrm_thread()
646 hALRM_thread = CreateThread(
654 hALRM_thread = CreateThread(
670 hMAIN_thread = GetCurrentThread();
690 TerminateThread(hIO_thread, 0);
692 TerminateThread(hALRM_thread, 0);
694 CloseHandle(Global_DIM_mutex);
695 if(Global_DIM_event_auto)
696 CloseHandle(Global_DIM_event_auto);
697 if(Global_DIM_event_manual)
698 CloseHandle(Global_DIM_event_manual);
701 Global_DIM_mutex = 0;
702 Global_DIM_event_auto = 0;
703 Global_DIM_event_manual = 0;
720 hProc = GetCurrentProcess();
723 p = IDLE_PRIORITY_CLASS;
729 p = NORMAL_PRIORITY_CLASS;
735 p = HIGH_PRIORITY_CLASS;
737 p = REALTIME_PRIORITY_CLASS;
738 ret = SetPriorityClass(hProc, p);
741 ret = GetLastError();
742 printf(
"ret = %x %d\n",ret, ret);
755 hProc = GetCurrentProcess();
757 ret = GetPriorityClass(hProc);
760 if(ret == IDLE_PRIORITY_CLASS)
766 else if(ret == NORMAL_PRIORITY_CLASS)
772 else if(ret == HIGH_PRIORITY_CLASS)
774 else if(ret == REALTIME_PRIORITY_CLASS)
791 else if(threadId == 2)
793 else if(threadId == 3)
797 p = THREAD_PRIORITY_IDLE;
799 p = THREAD_PRIORITY_LOWEST;
801 p = THREAD_PRIORITY_BELOW_NORMAL;
803 p = THREAD_PRIORITY_NORMAL;
805 p = THREAD_PRIORITY_ABOVE_NORMAL;
807 p = THREAD_PRIORITY_HIGHEST;
809 p = THREAD_PRIORITY_TIME_CRITICAL;
811 ret = SetThreadPriority(
id, p);
828 else if(threadId == 2)
830 else if(threadId == 3)
833 ret = GetThreadPriority(
id);
834 if(ret == THREAD_PRIORITY_ERROR_RETURN)
836 if(ret == THREAD_PRIORITY_IDLE)
838 if(ret == THREAD_PRIORITY_LOWEST)
840 if(ret == THREAD_PRIORITY_BELOW_NORMAL)
842 if(ret == THREAD_PRIORITY_NORMAL)
844 if(ret == THREAD_PRIORITY_ABOVE_NORMAL)
846 if(ret == THREAD_PRIORITY_HIGHEST)
848 if(ret == THREAD_PRIORITY_TIME_CRITICAL)
874 if(!Global_DIM_mutex)
876 Global_DIM_mutex = CreateMutex(NULL,
FALSE,NULL);
878 WaitForSingleObject(Global_DIM_mutex, INFINITE);
883 ReleaseMutex(Global_DIM_mutex);
890 if(!Global_DIM_event_auto)
892 Global_DIM_event_auto = CreateEvent(NULL,
FALSE,
FALSE,NULL);
893 Global_DIM_event_manual = CreateEvent(NULL,
TRUE,
FALSE,NULL);
900 handles[0] = Global_DIM_event_auto;
901 handles[1] = Global_DIM_event_manual;
902 WaitForMultipleObjects(2, handles,
FALSE, INFINITE);
908 if(Global_DIM_event_auto)
910 SetEvent(Global_DIM_event_auto);
912 if(Global_DIM_event_manual)
914 SetEvent(Global_DIM_event_manual);
915 ResetEvent(Global_DIM_event_manual);
919 void dim_sleep(
unsigned int t)
924 void dim_win_usleep(
unsigned int t)
void * dim_tcpip_thread(void *tag)
void pipe_sig_handler(int num)
int dtq_task(void *dummy)
dim_long dim_start_thread(void *(*thread_ast)(void *), dim_long tag)
int dim_dtq_init(int thr_flag)
pthread_cond_t Global_cond
pthread_mutex_t Global_DIM_mutex
void * dim_dtq_thread(void *tag)
int dim_get_scheduler_class(int *pclass)
int dim_tcpip_init(int thr_flag)
int dim_set_scheduler_class(int pclass)
int dim_stop_thread(dim_long t_id)
int dim_set_priority(int threadId, int prio)
void dim_print_date_time()
pthread_mutex_t Global_cond_mutex
void tcpip_task(void *dummy)
int dim_get_priority(int threadId, int *prio)