From: Robert W. <wrw...@us...> - 2006-10-31 19:00:29
|
Update of /cvsroot/linuxisns/isnsNT/isnsserver/src In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9476/src Modified Files: iSNSLinux.c Log Message: Clean up thread code Index: iSNSLinux.c =================================================================== RCS file: /cvsroot/linuxisns/isnsNT/isnsserver/src/iSNSLinux.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** iSNSLinux.c 25 Oct 2006 16:21:35 -0000 1.4 --- iSNSLinux.c 31 Oct 2006 19:00:17 -0000 1.5 *************** *** 30,39 **** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ - /*#include <time.h>*/ - /*#include <sys/time.h>*/ #include <semaphore.h> #include "iSNSLinux.h" - /* Linux.h includes parse.h */ #include "iSNS.h" #include "iSNScomm.h" --- 30,37 ---- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include <semaphore.h> + #include <errno.h> #include "iSNSLinux.h" #include "iSNS.h" #include "iSNScomm.h" *************** *** 50,63 **** #endif - /*WSADATA g_WsaData;*/ - typedef u_int64_t __int64; - extern int sns_ready; extern int sns_local_priority; extern int sns_local_version; extern int sns_heartbeat_interval; - extern pthread_cond_t fsm_cond; extern int sns_esi_interval; extern pthread_cond_t esi_cond; int pauseFlag = TRUE; --- 48,67 ---- #endif extern int sns_ready; extern int sns_local_priority; extern int sns_local_version; extern int sns_heartbeat_interval; extern int sns_esi_interval; + extern int sns_request_timeout; + + /* Linux */ extern pthread_cond_t esi_cond; + extern pthread_cond_t fsm_cond; + extern pthread_cond_t resync_cond; + extern pthread_mutex_t sns_request_timer; + extern pthread_cond_t request_cond; + extern pthread_mutex_t sns_resync_timer; + extern pthread_mutex_t sns_fsm_timer; + extern pthread_mutex_t sns_esi_timer; int pauseFlag = TRUE; *************** *** 68,74 **** extern void SNSReqTimeoutHdlr(void); extern void SNSFSMTimeoutHdlr(void); ! /*extern void SNSESITimeoutHdlr(void);*/ ! void NTDebugOn (void); void --- 72,82 ---- extern void SNSReqTimeoutHdlr(void); extern void SNSFSMTimeoutHdlr(void); ! extern void SNSESITimeoutHdlr(void); ! extern int sns_comm_main_port_set; ! ! int TCP_RecvMain (); ! HANDLE init_ipc_rcv (void); ! void DebugOn (void); void *************** *** 84,128 **** } - #if 0 - #define _SECOND 10000000 - LARGE_INTEGER l; - LARGE_INTEGER * - - ConvertTime (int sec, LARGE_INTEGER * pl) - { - __int64 qwDueTime; - qwDueTime = -sec * _SECOND; - - /* Copy the relative time into a LARGE_INTEGER. */ - pl->LowPart = (DWORD) (qwDueTime & 0xFFFFFFFF); - pl->HighPart = (long) (qwDueTime >> 32); - return (pl); - } - - int - wdStart (pthread_mutex_t sns_request_timer, int next_timeout, - void *nptr1, void *nptr2) - { - int results; - int timeout; - timeout = next_timeout; - if (timeout < 1) - timeout = 1; - - results = - SetWaitableTimer ((void *) sns_request_timer, ConvertTime (timeout, &l), - 0, NULL, NULL, FALSE); - return (0); - } - - void - wdCancel (sem_t timer) - { - if (timer) - CancelWaitableTimer ((void *) timer); - /* Linux */ - sem_destroy (&timer); - } - #endif void taskDelete (int task) --- 92,95 ---- *************** *** 133,139 **** if ((void *)task != NULL) { ! /* TerminateThread ((void *)task, 0); */ ! /* Linux */ ! pthread_cancel ((pthread_t) task); } } --- 100,104 ---- if ((void *)task != NULL) { ! pthread_cancel ((pthread_t) task); } } *************** *** 155,183 **** LinuxTaskSpawn (char *taskName, void *funcPtr) { ! int result; ! pthread_t athread; ! /* int result; */ ! /* DWORD junk; */ ! /* result = NULL; */ ! /* result = CreateThread (0, 0, funcPtr, &junk, 0, &junk); */ ! /* Linux */ ! result = (pthread_create (&athread, NULL, (void*) funcPtr, NULL)); ! if (result != 0) ! perror ("taskSpawn"); ! return (result); } - #ifdef SNS_LINUX - int - #else - DWORD WINAPI - #endif - NTtimertaskWrapper () - { - /* Run Task */ - return (0); - } - HANDLE init_ipc_rcv (void); - char Usage[] = "\ Usage: isnss [options] -i IP -b BROADCAST IP\n\ --- 120,131 ---- LinuxTaskSpawn (char *taskName, void *funcPtr) { ! int result; ! pthread_t athread; ! result = (pthread_create (&athread, NULL, (void*) funcPtr, NULL)); ! if (result != 0) ! perror ("taskSpawn"); ! return (result); } char Usage[] = "\ Usage: isnss [options] -i IP -b BROADCAST IP\n\ *************** *** 191,207 **** [-?] Help.\n"; - #ifdef SNS_LINUX - int - #else - DWORD WINAPI - #endif - TCP_RecvMain (); - - extern int sns_comm_main_port_set; int main (int argc, char **argv) { ! pthread_t athread; int c; char sfilename[256] = { 0 }; --- 139,147 ---- [-?] Help.\n"; int main (int argc, char **argv) { ! pthread_t athread; int c; char sfilename[256] = { 0 }; *************** *** 250,254 **** case 'd': ! NTDebugOn(); break; --- 190,194 ---- case 'd': ! DebugOn(); break; *************** *** 275,327 **** sleep (10); ! /* ! if (WSAStartup (MAKEWORD (0x02, 0x00), &g_WsaData) == SOCKET_ERROR) ! { ! return (0); ! } ! */ ! ! /*CreateThread (0, 0, TCP_RecvMain, &junk, 0, &junk);*/ ! if (pthread_create (&athread, NULL, (void*) TCP_RecvMain, NULL) != 0) perror("Creating TCP_RecvMain"); SNSMain (role); - /* Linux */ /* Never should hit this. */ - /*WSACleanup ();*/ exit (-1); } /********************************************************* ! THIS FUNCTION WORKS *********************************************************/ - /* Linux */ - extern pthread_mutex_t sns_request_timer; - extern pthread_cond_t request_cond; - extern int sns_request_timeout; int SNSReqTimeoutThread () { struct timeval now; ! struct timespec timeout; ! printf ("SNSReqTimeoutHdlr Started.\n"); while (1) { ! pthread_mutex_lock(&sns_request_timer); ! gettimeofday(&now, NULL); ! timeout.tv_sec = now.tv_sec + sns_request_timeout; ! timeout.tv_nsec = now.tv_usec * 1000; ! /*results = WaitForSingleObject ((HANDLE)sns_request_timer, INFINITE); */ ! if (0 != pthread_cond_timedwait (&request_cond, &sns_request_timer, &timeout)); ! /*perror ("Timedwaid in Request Timeout");*/ ! pthread_mutex_unlock(&sns_request_timer); ! SNSReqTimeoutHdlr (); if (pauseFlag) ! return (0); } --- 215,256 ---- sleep (10); ! if (pthread_create (&athread, NULL, (void*) TCP_RecvMain, NULL) != 0) perror("Creating TCP_RecvMain"); SNSMain (role); /* Never should hit this. */ exit (-1); } + /********************************************************* ! SNSReqTimeoutThread *********************************************************/ int SNSReqTimeoutThread () { struct timeval now; ! struct timespec timeout; ! int rc; ! printf ("SNSReqTimeoutHdlr Started.\n"); while (1) { ! pthread_mutex_lock(&sns_request_timer); ! gettimeofday(&now, NULL); ! timeout.tv_sec = now.tv_sec + sns_request_timeout; ! timeout.tv_nsec = now.tv_usec * 1000; ! rc = pthread_cond_timedwait (&request_cond,&sns_request_timer,&timeout); ! if (rc != ETIMEDOUT) ! perror ("Error in Timeout Request in SNSReqTimeoutThread"); ! ! pthread_mutex_unlock(&sns_request_timer); ! SNSReqTimeoutHdlr (); if (pauseFlag) ! return (0); } *************** *** 330,361 **** /*********************************************************** ! THIS FUNCTION DOES NOT WORK ***********************************************************/ /* Linux */ - extern pthread_mutex_t sns_fsm_timer; int SNSFSMTimeoutThread () { ! struct timeval now; ! struct timespec timeout; ! printf ("SNSFSMTimeoutHdlr thread started.\n"); ! while (1) { ! pthread_mutex_lock(&sns_fsm_timer); ! gettimeofday(&now, NULL); ! timeout.tv_sec = now.tv_sec + sns_heartbeat_interval; ! timeout.tv_nsec = now.tv_usec * 1000; ! /* The condition is never signaled. This will always time out */ ! if (0 != pthread_cond_timedwait(&fsm_cond, &sns_fsm_timer, &timeout)); ! /*perror ("Timedwait in FSM Timeout");*/ SNSFSMTimeoutHdlr (); ! pthread_mutex_unlock(&sns_fsm_timer); if (pauseFlag) return (0); --- 259,291 ---- /*********************************************************** ! SSNSFSMTimeoutThread ***********************************************************/ /* Linux */ int SNSFSMTimeoutThread () { ! struct timeval now; ! struct timespec timeout; ! int rc; ! printf ("SNSFSMTimeoutHdlr thread started.\n"); ! while (1) { ! pthread_mutex_lock(&sns_fsm_timer); ! gettimeofday(&now, NULL); ! timeout.tv_sec = now.tv_sec + sns_heartbeat_interval; ! timeout.tv_nsec = now.tv_usec * 1000; ! rc = pthread_cond_timedwait(&fsm_cond, &sns_fsm_timer, &timeout); ! if (rc != ETIMEDOUT) ! perror ("Error in Timeout Request in SNSFSMTimeoutThread"); SNSFSMTimeoutHdlr (); ! pthread_mutex_unlock(&sns_fsm_timer); ! if (pauseFlag) return (0); *************** *** 366,382 **** /********************************************************* ! THIS FUNCTION WORKS UNDER THE GDB *********************************************************/ /* Linux */ - extern pthread_mutex_t sns_esi_timer; int SNSESITimeoutThread () { - #if 0 - DWORD results; - #endif struct timeval now; struct timespec timeout; printf ("SNSESITimeoutHdlr thread started.\n"); --- 296,309 ---- /********************************************************* ! SNSESITimeoutThread *********************************************************/ /* Linux */ int SNSESITimeoutThread () { struct timeval now; struct timespec timeout; + int rc; printf ("SNSESITimeoutHdlr thread started.\n"); *************** *** 384,402 **** while (1) { ! pthread_mutex_lock(&sns_esi_timer); ! gettimeofday(&now, NULL); ! timeout.tv_sec = now.tv_sec + sns_esi_interval; ! timeout.tv_nsec = now.tv_usec * 1000; ! #if 0 ! results = WaitForSingleObject ((HANDLE)sns_esi_timer, INFINITE); ! /* Linux */ ! /* The condition is never signaled. This will always time out */ ! if (0 != pthread_cond_timedwait(&esi_cond, &sns_esi_timer, &timeout)) ! perror("Timedwait in ESI Timeout"); ! #endif ! SNSESITimeoutHdlr (); ! pthread_mutex_unlock(&sns_esi_timer); ! if (pauseFlag) ! return (0); } return (0); --- 311,326 ---- while (1) { ! pthread_mutex_lock(&sns_esi_timer); ! gettimeofday(&now, NULL); ! timeout.tv_sec = now.tv_sec + sns_esi_interval; ! timeout.tv_nsec = now.tv_usec * 1000; ! rc = pthread_cond_timedwait(&esi_cond, &sns_esi_timer, &timeout); ! if (rc != ETIMEDOUT) ! perror ("Error in Timeout Request in SNSESITimeoutThread"); ! ! SNSESITimeoutHdlr (); ! pthread_mutex_unlock(&sns_esi_timer); ! if (pauseFlag) ! return (0); } return (0); *************** *** 404,437 **** /*********************************************************** ! THIS FUNCTION DOES NOT WORK ***********************************************************/ - /* Linux */ - extern pthread_mutex_t sns_resync_timer; int SNSResyncTimeoutThread () { - - #if 0 - DWORD results; struct timeval now; struct timespec timeout; ! #endif while (1) { ! #if 0 ! pthread_mutex_lock(&sns_resync_timer); ! gettimeofday(&now, NULL); ! timeout.tv_sec = now.tv_sec + sns_resync_interval; ! timeout.tv_nsec = now.tv_usec * 1000; ! results = WaitForSingleObject ((HANDLE)sns_resync_timer, INFINITE); ! /* Linux */ ! results = sem_wait (&sns_resync_timer); ! results = pthread_cond_timedwait(&sns_resync_timer, &resync_cond, &timeout); ! pthread_mutex_unlock(&sns_resync_timer); ! #endif ! if (pauseFlag){ ! return (0); ! } } --- 328,353 ---- /*********************************************************** ! SNSResyncTimeoutThread ***********************************************************/ int SNSResyncTimeoutThread () { struct timeval now; struct timespec timeout; ! int rc; while (1) { ! pthread_mutex_lock(&sns_resync_timer); ! gettimeofday(&now, NULL); ! timeout.tv_sec = now.tv_sec + 60; //sns_resync_interval; ! timeout.tv_nsec = now.tv_usec * 1000; ! rc = pthread_cond_timedwait(&resync_cond, &sns_resync_timer, &timeout); ! if (rc != ETIMEDOUT) ! perror ("Error in Timeout Request in SNSResyncTimeoutThread"); ! ! pthread_mutex_unlock(&sns_resync_timer); ! if (pauseFlag) ! return (0); } *************** *** 440,450 **** void ! SNSTrap (void) ! { ! } ! /***********************************************/ ! ! void ! NTDebugOn (void) { extern int sns_bcast_debug; --- 356,360 ---- void ! DebugOn (void) { extern int sns_bcast_debug; |