Functions | |
INT | ss_system (char *command) |
midas_thread_t | ss_thread_create (INT(*thread_func)(void *), void *param) |
INT | ss_thread_kill (midas_thread_t thread_id) |
DWORD | ss_millitime () |
DWORD | ss_time () |
INT | ss_sleep (INT millisec) |
DWORD ss_millitime | ( | ) |
Returns the actual time in milliseconds with an arbitrary origin. This time may only be used to calculate relative times.
Overruns in the 32 bit value don't hurt since in a subtraction calculated with 32 bit accuracy this overrun cancels (you may think about!)..
... DWORD start, stop: start = ss_millitime(); < do operations > stop = ss_millitime(); printf("Operation took %1.3lf seconds\n",(stop-start)/1000.0); ...
Definition at line 2667 of file system.c.
Referenced by analyze_run(), bm_check_buffers(), bm_cleanup(), bm_open_buffer(), check_polled_events(), close_channels(), cm_cleanup(), cm_get_watchdog_info(), cm_set_watchdog_params(), cm_shutdown(), cm_transition1(), cmd_edit(), command_loop(), db_open_database(), debug_print(), dm_buffer_create(), ftp_get(), ftp_put(), generate_hist_graph(), lazy_copy(), lazy_main(), lazy_maintain_free_space(), lazy_statistics_update(), log_write(), loop_online(), main(), process_event(), rotate_wheel(), sc_thread(), scan_fragment(), scheduler(), send_event(), tr_stop(), and update_stats().
02668 { 02669 #ifdef OS_WINNT 02670 02671 return (int) GetTickCount(); 02672 02673 #endif /* OS_WINNT */ 02674 #ifdef OS_MSDOS 02675 02676 return clock() * 55; 02677 02678 #endif /* OS_MSDOS */ 02679 #ifdef OS_VMS 02680 02681 { 02682 char time[8]; 02683 DWORD lo, hi; 02684 02685 sys$gettim(time); 02686 02687 lo = *((DWORD *) time); 02688 hi = *((DWORD *) (time + 4)); 02689 02690 /* return *lo / 10000; */ 02691 02692 return lo / 10000 + hi * 429496.7296; 02693 02694 } 02695 02696 #endif /* OS_VMS */ 02697 #ifdef OS_UNIX 02698 { 02699 struct timeval tv; 02700 02701 gettimeofday(&tv, NULL); 02702 02703 return tv.tv_sec * 1000 + tv.tv_usec / 1000; 02704 } 02705 02706 #endif /* OS_UNIX */ 02707 #ifdef OS_VXWORKS 02708 { 02709 int count; 02710 static int ticks_per_msec = 0; 02711 02712 if (ticks_per_msec == 0) 02713 ticks_per_msec = 1000 / sysClkRateGet(); 02714 02715 return tickGet() * ticks_per_msec; 02716 } 02717 #endif /* OS_VXWORKS */ 02718 }
Suspend the calling process for a certain time.
The function is similar to the sleep() function, but has a resolution of one milliseconds. Under VxWorks the resolution is 1/60 of a second. It uses the socket select() function with a time-out. See examples in ss_time()
millisec | Time in milliseconds to sleep. Zero means infinite (until another process calls ss_wake) |
Definition at line 2905 of file system.c.
Referenced by cm_shutdown(), command_loop(), device_driver(), ma_read_event(), main(), ps7106_set(), rb_get_rp(), rb_get_wp(), ModbusTcp::Read(), read_trigger_event(), readout_enable(), readout_thread(), register_equipment(), sc_thread(), show_cnaf_page(), show_programs_page(), and thread().
02906 { 02907 if (millisec == 0) { 02908 #ifdef OS_WINNT 02909 SuspendThread(GetCurrentThread()); 02910 #endif 02911 #ifdef OS_VMS 02912 sys$hiber(); 02913 #endif 02914 #ifdef OS_UNIX 02915 signal(SIGCONT, ss_cont); 02916 pause(); 02917 #endif 02918 return SS_SUCCESS; 02919 } 02920 #ifdef OS_WINNT 02921 Sleep(millisec); 02922 #endif 02923 #ifdef OS_UNIX 02924 struct timespec ts; 02925 int status; 02926 02927 ts.tv_sec = millisec / 1000; 02928 ts.tv_nsec = (millisec % 1000) * 1E6; 02929 02930 do { 02931 status = nanosleep(&ts, &ts); 02932 } while (status == -1 && errno == EINTR); 02933 #endif 02934 02935 return SS_SUCCESS; 02936 }
INT ss_system | ( | char * | command | ) |
Execute command in a separate process, close all open file descriptors invoke ss_exec() and ignore pid.
{ ... char cmd[256]; sprintf(cmd,"%s %s %i %s/%s %1.3lf %d",lazy.commandAfter, lazy.backlabel, lazyst.nfiles, lazy.path, lazyst.backfile, lazyst.file_size/1024.0/1024.0, blockn); cm_msg(MINFO,"Lazy","Exec post file write script:%s",cmd); ss_system(cmd); } ...
command | Command to execute. |
Definition at line 1711 of file system.c.
Referenced by al_check(), cm_transition1(), exec_script(), lazy_copy(), lazy_log_update(), lazy_main(), and show_programs_page().
01712 { 01713 #ifdef OS_UNIX 01714 INT childpid; 01715 01716 return ss_exec(command, &childpid); 01717 01718 #else 01719 01720 system(command); 01721 return SS_SUCCESS; 01722 01723 #endif 01724 }
midas_thread_t ss_thread_create | ( | INT(*)(void *) | thread_func, | |
void * | param | |||
) |
Creates and returns a new thread of execution.
Note the difference when calling from vxWorks versus Linux and Windows. The parameter pointer for a vxWorks call is a VX_TASK_SPAWN structure, whereas for Linux and Windows it is a void pointer. Early versions returned SS_SUCCESS or SS_NO_THREAD instead of thread ID.
Example for VxWorks
... VX_TASK_SPAWN tsWatch = {"Watchdog", 100, 0, 2000, (int) pDevice, 0, 0, 0, 0, 0, 0, 0, 0 ,0}; midas_thread_t thread_id = ss_thread_create((void *) taskWatch, &tsWatch); if (thread_id == 0) { printf("cannot spawn taskWatch\n"); } ...
... midas_thread_t thread_id = ss_thread_create((void *) taskWatch, pDevice); if (thread_id == 0) { printf("cannot spawn taskWatch\n"); } ...
(*thread_func) | Thread function to create. | |
param | a pointer to a VX_TASK_SPAWN structure for vxWorks and a void pointer for Unix and Windows |
Definition at line 1837 of file system.c.
Referenced by command_loop(), device_driver(), dm_buffer_create(), and main().
01838 { 01839 #if defined(OS_WINNT) 01840 01841 HANDLE status; 01842 DWORD thread_id; 01843 01844 if (thread_func == NULL) { 01845 return 0; 01846 } 01847 01848 status = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) thread_func, (LPVOID) param, 0, &thread_id); 01849 01850 return status == NULL ? 0 : (midas_thread_t) thread_id; 01851 01852 #elif defined(OS_MSDOS) 01853 01854 return 0; 01855 01856 #elif defined(OS_VMS) 01857 01858 return 0; 01859 01860 #elif defined(OS_VXWORKS) 01861 01862 /* taskSpawn which could be considered as a thread under VxWorks 01863 requires several argument beside the thread args 01864 taskSpawn (taskname, priority, option, stacksize, entry_point 01865 , arg1, arg2, ... , arg9, arg10) 01866 all the arg will have to be retrieved from the param list. 01867 through a structure to be simpler */ 01868 01869 INT status; 01870 VX_TASK_SPAWN *ts; 01871 01872 ts = (VX_TASK_SPAWN *) param; 01873 status = 01874 taskSpawn(ts->name, ts->priority, ts->options, ts->stackSize, 01875 (FUNCPTR) thread_func, ts->arg1, ts->arg2, ts->arg3, 01876 ts->arg4, ts->arg5, ts->arg6, ts->arg7, ts->arg8, ts->arg9, ts->arg10); 01877 01878 return status == ERROR ? 0 : status; 01879 01880 #elif defined(OS_UNIX) 01881 01882 INT status; 01883 pthread_t thread_id; 01884 01885 status = pthread_create(&thread_id, NULL, (void *) thread_func, param); 01886 01887 return status != 0 ? 0 : thread_id; 01888 01889 #endif 01890 }
INT ss_thread_kill | ( | midas_thread_t | thread_id | ) |
Destroys the thread identified by the passed thread id. The thread id is returned by ss_thread_create() on creation.
... midas_thread_t thread_id = ss_thread_create((void *) taskWatch, pDevice); if (thread_id == 0) { printf("cannot spawn taskWatch\n"); } ... ss_thread_kill(thread_id); ...
thread_id | the thread id of the thread to be killed. |
Definition at line 1910 of file system.c.
Referenced by device_driver().
01911 { 01912 #if defined(OS_WINNT) 01913 01914 DWORD status; 01915 HANDLE th; 01916 01917 th = OpenThread(THREAD_TERMINATE, FALSE, (DWORD)thread_id); 01918 if (th == 0) 01919 status = GetLastError(); 01920 01921 status = TerminateThread(th, 0); 01922 01923 if (status == 0) 01924 status = GetLastError(); 01925 01926 return status != 0 ? SS_SUCCESS : SS_NO_THREAD; 01927 01928 #elif defined(OS_MSDOS) 01929 01930 return 0; 01931 01932 #elif defined(OS_VMS) 01933 01934 return 0; 01935 01936 #elif defined(OS_VXWORKS) 01937 01938 INT status; 01939 status = taskDelete(thread_id); 01940 return status == OK ? 0 : ERROR; 01941 01942 #elif defined(OS_UNIX) 01943 01944 INT status; 01945 status = pthread_kill(thread_id, SIGKILL); 01946 return status == 0 ? SS_SUCCESS : SS_NO_THREAD; 01947 01948 #endif 01949 }
DWORD ss_time | ( | ) |
Returns the actual time in seconds since 1.1.1970 UTC.
... DWORD start, stop: start = ss_time(); ss_sleep(12000); stop = ss_time(); printf("Operation took %1.3lf seconds\n",stop-start); ...
Definition at line 2734 of file system.c.
Referenced by al_check(), al_trigger_alarm(), bm_compose_event(), bm_push_event(), cm_synchronize(), cm_time(), cm_yield(), command_loop(), db_get_key_time(), db_set_data(), db_set_data_index(), db_set_link_data(), db_set_link_data_index(), db_set_value(), export_hist(), generate_hist_graph(), lazy_copy(), log_history(), log_system_history(), log_write(), main(), scheduler(), send_event(), server_loop(), show_alarm_page(), show_query_page(), taxis(), tr_start(), and tr_stop().
02735 { 02736 #if !defined(OS_VXWORKS) 02737 #if !defined(OS_VMS) 02738 #if 0 02739 static int once = 0; 02740 if (once == 0) { 02741 tzset(); 02742 once = 1; 02743 } 02744 #endif 02745 #endif 02746 #endif 02747 return (DWORD) time(NULL); 02748 }