Back to index

im-sdk  12.3.91
IMScheduler_MTPC.cpp
Go to the documentation of this file.
00001 #include <config.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #ifdef HAVE_SIGNAL
00005 #include <signal.h>
00006 #endif
00007 #include "IMScheduler_MTPC.hh"
00008 #include "IMProtocol.hh"
00009 #include "IMState.hh"
00010 
00011 struct IMScheduler_thread_arg {
00012     IMProtocol *pimp;
00013     IMState *pimstate;
00014 };
00015 
00016 extern "C" void* IMScheduler_MTPC_thread_entry(void *priv);
00017 void* IMScheduler_MTPC_thread_entry(
00018     void *priv
00019 )
00020 {
00021     IMScheduler_thread_arg *pa = (IMScheduler_thread_arg *) priv;
00022     IMProtocol *pimp = pa->pimp;
00023     IMState *pims = pa->pimstate;
00024 
00025     free(pa);
00026 
00027 #ifdef HAVE_SIGNAL
00028     // block signal handling
00029     sigset_t sset;
00030     sigfillset(&sset);
00031     pthread_sigmask(SIG_BLOCK, &sset, NULL);
00032 #endif
00033 
00034     for(;;) {
00035        if (!pimp->receive_and_dispatch(pims))
00036            break;
00037     }
00038 
00039     return NULL;
00040 }
00041 
00042 int
00043 IMScheduler_MTPC::
00044 start(
00045     IMAccept *pimaccept,
00046     IMProtocol *pimp,
00047     IMState *pims
00048 )
00049 {
00050     pthread_t th;
00051     pthread_attr_t attr;
00052 
00053     pthread_attr_init(&attr);
00054     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
00055 
00056 
00057     IMScheduler_thread_arg *pima;
00058     pima = (IMScheduler_thread_arg*) malloc(sizeof(IMScheduler_thread_arg));
00059     if (!pima) return 0;
00060     pima->pimp = pimp;
00061     pima->pimstate = pims;
00062     pthread_create(&th, &attr, IMScheduler_MTPC_thread_entry, pima);
00063 
00064     return 1;
00065 }
00066 
00067 int
00068 IMScheduler_MTPC::
00069 stop()
00070 {
00071     return 1;
00072 }
00073 
00074 IMScheduler_MTPC::IMScheduler_MTPC()
00075     : IMScheduler()
00076 {
00077 }
00078 
00079 IMScheduler_MTPC*
00080 IMScheduler_MTPC::construct()
00081 {
00082     IMScheduler_MTPC *pimsch = new IMScheduler_MTPC();
00083     pimsch->register_singleton();
00084 
00085     return pimsch;
00086 }
00087 
00088 
00089 /* Local Variables: */
00090 /* c-file-style: "iiim-project" */
00091 /* End: */