14 #include <sys/types.h> 28 sem_t *DIM_INIT_Semap;
59 sem_post(DIM_INIT_Semap);
94 sem_post(DIM_INIT_Semap);
142 DIM_INIT_Semap = sem_open(
"/Dim_INIT_Sem", O_CREAT, S_IRUSR | S_IWUSR,
INIT_count);
150 #if defined (LYNXOS) && !defined (__Lynx__) 151 pthread_attr_create(&attr);
157 pthread_attr_init(&attr);
158 pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
164 ret = sem_wait(DIM_INIT_Semap);
166 #if defined (LYNXOS) && !defined (__Lynx__) 174 ret = sem_wait(DIM_INIT_Semap);
203 sem_unlink(
"/Dim_INIT_Sem");
207 sem_close(DIM_INIT_Semap);
228 #if defined (LYNXOS) && !defined (__Lynx__) 229 pthread_attr_create(&attr);
230 pthread_create(&t_id, attr, (
void *)thread_ast, (
void *)tag);
232 pthread_attr_init(&attr);
233 pthread_create(&t_id, &attr, thread_ast, (
void *)tag);
241 ret = pthread_cancel((pthread_t)t_id);
243 printf(
"dim_stop_thread: this function is obsolete, it creates memory leaks\n");
251 struct sched_param param;
255 pclass = SCHED_OTHER;
265 prio = sched_get_priority_min(pclass);
266 ret = pthread_getschedparam(
MAIN_thread, &p, ¶m);
267 if( (p == SCHED_OTHER) || (pclass == SCHED_OTHER) )
268 param.sched_priority = prio;
269 ret = pthread_setschedparam(
MAIN_thread, pclass, ¶m);
272 ret = pthread_getschedparam(
IO_thread, &p, ¶m);
273 if( (p == SCHED_OTHER) || (pclass == SCHED_OTHER) )
274 param.sched_priority = prio;
275 ret = pthread_setschedparam(
IO_thread, pclass, ¶m);
278 ret = pthread_getschedparam(
ALRM_thread, &p, ¶m);
279 if( (p == SCHED_OTHER) || (pclass == SCHED_OTHER) )
280 param.sched_priority = prio;
281 ret = pthread_setschedparam(
ALRM_thread, pclass, ¶m);
292 struct sched_param param;
294 ret = pthread_getschedparam(
MAIN_thread, pclass, ¶m);
307 struct sched_param param;
311 else if(threadId == 2)
313 else if(threadId == 3)
316 ret = pthread_getschedparam(
id, &pclass, ¶m);
317 param.sched_priority = prio;
318 ret = pthread_setschedparam(
id, pclass, ¶m);
331 struct sched_param param;
335 else if(threadId == 2)
337 else if(threadId == 3)
340 ret = pthread_getschedparam(
id, &pclass, ¶m);
341 *prio = param.sched_priority;
351 struct sigaction sig_info;
355 if( sigaction(SIGPIPE, 0, &sig_info) < 0 )
357 perror(
"sigaction(SIGPIPE)" );
360 if(sig_info.sa_handler)
369 sig_info.sa_mask =
set;
371 sig_info.sa_flags = SA_RESTART;
373 sig_info.sa_flags = 0;
376 if( sigaction(SIGPIPE, &sig_info, 0) < 0 )
378 perror(
"sigaction(SIGPIPE)" );
440 pthread_mutex_t Global_DIM_mutex = PTHREAD_MUTEX_INITIALIZER;
441 pthread_mutex_t Global_cond_mutex = PTHREAD_MUTEX_INITIALIZER;
442 pthread_cond_t Global_cond = PTHREAD_COND_INITIALIZER;
448 if(Dim_thr_locker != pthread_self())
450 pthread_mutex_lock(&Global_DIM_mutex);
451 Dim_thr_locker=pthread_self();
465 pthread_mutex_unlock(&Global_DIM_mutex);
473 pthread_mutex_lock(&Global_cond_mutex);
474 pthread_cond_wait(&Global_cond, &Global_cond_mutex);
475 pthread_mutex_unlock(&Global_cond_mutex);
480 pthread_mutex_lock(&Global_cond_mutex);
481 pthread_cond_broadcast(&Global_cond);
482 pthread_mutex_unlock(&Global_cond_mutex);
512 printf(
"dim_start_thread: not available\n");
518 printf(
"dim_stop_thread: not available\n");
532 DllExp HANDLE Global_DIM_event_auto = 0;
533 DllExp HANDLE Global_DIM_mutex = 0;
534 DllExp HANDLE Global_DIM_event_manual = 0;
538 void (*thread_ast)();
553 hthread = CreateThread(
561 hthread = CreateThread(
569 return (
long)hthread;
577 ret = TerminateThread((HANDLE)thread_id, 0);
578 CloseHandle((HANDLE)thread_id);
579 printf(
"dim_stop_thread: this function is obsolete, it creates memory leaks\n");
584 void create_io_thread()
589 hIO_thread = CreateThread(
597 hIO_thread = CreateThread(
607 void create_alrm_thread()
613 hALRM_thread = CreateThread(
621 hALRM_thread = CreateThread(
637 hMAIN_thread = GetCurrentThread();
655 TerminateThread(hIO_thread, 0);
657 TerminateThread(hALRM_thread, 0);
659 CloseHandle(Global_DIM_mutex);
660 if(Global_DIM_event_auto)
661 CloseHandle(Global_DIM_event_auto);
662 if(Global_DIM_event_manual)
663 CloseHandle(Global_DIM_event_manual);
666 Global_DIM_mutex = 0;
667 Global_DIM_event_auto = 0;
668 Global_DIM_event_manual = 0;
685 hProc = GetCurrentProcess();
688 p = IDLE_PRIORITY_CLASS;
694 p = NORMAL_PRIORITY_CLASS;
700 p = HIGH_PRIORITY_CLASS;
702 p = REALTIME_PRIORITY_CLASS;
703 ret = SetPriorityClass(hProc, p);
706 ret = GetLastError();
707 printf(
"ret = %x %d\n",ret, ret);
720 hProc = GetCurrentProcess();
722 ret = GetPriorityClass(hProc);
725 if(ret == IDLE_PRIORITY_CLASS)
731 else if(ret == NORMAL_PRIORITY_CLASS)
737 else if(ret == HIGH_PRIORITY_CLASS)
739 else if(ret == REALTIME_PRIORITY_CLASS)
756 else if(threadId == 2)
758 else if(threadId == 3)
762 p = THREAD_PRIORITY_IDLE;
764 p = THREAD_PRIORITY_LOWEST;
766 p = THREAD_PRIORITY_BELOW_NORMAL;
768 p = THREAD_PRIORITY_NORMAL;
770 p = THREAD_PRIORITY_ABOVE_NORMAL;
772 p = THREAD_PRIORITY_HIGHEST;
774 p = THREAD_PRIORITY_TIME_CRITICAL;
776 ret = SetThreadPriority(
id, p);
793 else if(threadId == 2)
795 else if(threadId == 3)
798 ret = GetThreadPriority(
id);
799 if(ret == THREAD_PRIORITY_ERROR_RETURN)
801 if(ret == THREAD_PRIORITY_IDLE)
803 if(ret == THREAD_PRIORITY_LOWEST)
805 if(ret == THREAD_PRIORITY_BELOW_NORMAL)
807 if(ret == THREAD_PRIORITY_NORMAL)
809 if(ret == THREAD_PRIORITY_ABOVE_NORMAL)
811 if(ret == THREAD_PRIORITY_HIGHEST)
813 if(ret == THREAD_PRIORITY_TIME_CRITICAL)
839 if(!Global_DIM_mutex)
841 Global_DIM_mutex = CreateMutex(NULL,
FALSE,NULL);
843 WaitForSingleObject(Global_DIM_mutex, INFINITE);
848 ReleaseMutex(Global_DIM_mutex);
855 if(!Global_DIM_event_auto)
857 Global_DIM_event_auto = CreateEvent(NULL,
FALSE,
FALSE,NULL);
858 Global_DIM_event_manual = CreateEvent(NULL,
TRUE,
FALSE,NULL);
865 handles[0] = Global_DIM_event_auto;
866 handles[1] = Global_DIM_event_manual;
867 WaitForMultipleObjects(2, handles,
FALSE, INFINITE);
873 if(Global_DIM_event_auto)
875 SetEvent(Global_DIM_event_auto);
877 if(Global_DIM_event_manual)
879 SetEvent(Global_DIM_event_manual);
880 ResetEvent(Global_DIM_event_manual);
884 void dim_sleep(
unsigned int t)
889 void dim_win_usleep(
unsigned int t)
int dim_set_priority(int threadId, int prio)
DllExp DIM_NOSHARE int Curr_N_Conns
int dtq_task(void *dummy)
int dim_set_scheduler_class(int pclass)
DllExp DIM_NOSHARE NET_CONNECTION * Net_conns
int dim_dtq_init(int thr_flag)
int dim_tcpip_init(int thr_flag)
void pipe_sig_handler(int num)
void * dim_dtq_thread(void *tag)
long dim_start_thread(void *(*thread_ast)(void *), long tag)
int dim_stop_thread(long t_id)
pthread_cond_t Global_cond
void dim_print_date_time()
pthread_mutex_t Global_DIM_mutex
pthread_mutex_t Global_cond_mutex
void tcpip_task(void *dummy)
int dim_get_scheduler_class(int *pclass)
int dim_get_priority(int threadId, int *prio)
void * dim_tcpip_thread(void *tag)