int main( void ) { pthread_t tid1, tid2; pthread_mutex_init( &mutex, NULL ); tid1 = Thread_create( thread1 ); tid2 = Thread_create( thread2 ); Thread_waitUntilExit( tid1 ); Thread_waitUntilExit( tid2 ); pthread_mutex_destroy( &mutex ); return 0; }
void IsoServer_startListening(IsoServer self) { if (self->state == ISO_SVR_STATE_RUNNING) { if (DEBUG_ISO_SERVER) printf("ISO_SERVER: server already in RUNNING state!\n"); goto exit_function; } self->state = ISO_SVR_STATE_IDLE; self->serverThread = Thread_create((ThreadExecutionFunction) isoServerThread, self, false); Thread_start(self->serverThread); /* wait until server is up */ while (self->state == ISO_SVR_STATE_IDLE) Thread_sleep(1); if (DEBUG_ISO_SERVER) printf("ISO_SERVER: new iso server thread started\n"); exit_function: return; }
void IsoServer_startListening(IsoServer self) { self->serverThread = Thread_create((ThreadExecutionFunction) isoServerThread, self, false); Thread_start(self->serverThread); /* wait until server is up */ while (self->state == ISO_SVR_STATE_IDLE) Thread_sleep(1); if (DEBUG_ISO_SERVER) printf("ISO_SERVER: new iso server thread started\n"); }
void IedServer_start(IedServer self, int tcpPort) { #if (CONFIG_MMS_SINGLE_THREADED == 1) MmsServer_startListeningThreadless(self->mmsServer, tcpPort); Thread serverThread = Thread_create((ThreadExecutionFunction) singleThreadedServerThread, (void*) self, true); Thread_start(serverThread); #else MmsServer_startListening(self->mmsServer, tcpPort); MmsMapping_startEventWorkerThread(self->mmsMapping); #endif }
// start GOOSE receiver in a separate thread void GooseReceiver_start(GooseReceiver self) { Thread thread = Thread_create((ThreadExecutionFunction) gooseReceiverLoop, (void*) self, true); if (thread != NULL) { if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: GOOSE receiver started for interface %s\n", self->interfaceId); Thread_start(thread); } else { if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Starting GOOSE receiver failed for interface %s\n", self->interfaceId); } }
IsoConnection IsoConnection_create(Socket socket, IsoServer isoServer) { IsoConnection self = calloc(1, sizeof(struct sIsoConnection)); self->socket = socket; self->receive_buf = malloc(RECEIVE_BUF_SIZE); self->send_buf_1 = malloc(SEND_BUF_SIZE); self->send_buf_2 = malloc(SEND_BUF_SIZE); self->msgRcvdHandler = NULL; self->msgRcvdHandlerParameter = NULL; self->isoServer = isoServer; self->state = ISO_CON_STATE_RUNNING; Thread thread = Thread_create(handleTcpConnection, self, true); Thread_start(thread); if (DEBUG) printf("new iso connection thread started\n"); return self; }
/** * @brief The BIOS main() entry point. * * @remark The purpose of this function is to create a BIOS worker task * to house our example. * * @remark This is called during BIOS_init, but before the scheduler * has begun running. */ Void main(Int argc, String argv[]) { Thread_Params threadParams; /* init Codec Engine */ CERuntime_init(); /* Enable all trace for xdc.runtime.Main */ Diags_setMask("xdc.runtime.Main+EX1234567"); Log_print0(Diags_USER2, "[+2] main> ti.sdo.ce.examples.apps.image_copy"); Thread_Params_init(&threadParams); threadParams.stackSize = 6 * 1024; threadParams.instance->name = taskName; if (Thread_create(workerFxn, &threadParams, NULL) == NULL) { System_abort("main: failed to create smain thread."); } BIOS_start(); }
/** * @brief The BIOS main() entry point. * * @remark The purpose of this function is to create a BIOS worker task * to house our example. * * @remark This is called during BIOS_init, but before the scheduler * has begun running. */ Void main(Int argc, String argv[]) { Thread_Params threadParams; /* init Codec Engine */ CERuntime_init(); /* Enable all trace for this module */ Diags_setMask("xdc.runtime.Main+EX012345678"); Log_print0(Diags_USER2, "[+2] main> Welcome to app's main()."); Thread_Params_init(&threadParams); threadParams.stackSize = 6 * 1024; threadParams.instance->name = taskName; if (Thread_create(workerFxn, &threadParams, NULL) == NULL) { System_abort("main: failed to create smain thread."); } BIOS_start(); }
IsoConnection IsoConnection_create(Socket socket, IsoServer isoServer) { IsoConnection self = (IsoConnection) calloc(1, sizeof(struct sIsoConnection)); self->socket = socket; self->receiveBuffer = (uint8_t*) malloc(RECEIVE_BUF_SIZE); self->sendBuffer = (uint8_t*) malloc(SEND_BUF_SIZE); self->msgRcvdHandler = NULL; self->msgRcvdHandlerParameter = NULL; self->isoServer = isoServer; self->state = ISO_CON_STATE_RUNNING; self->clientAddress = Socket_getPeerAddress(self->socket); self->thread = Thread_create((ThreadExecutionFunction) handleTcpConnection, self, true); self->conMutex = Semaphore_create(1); Thread_start(self->thread); if (DEBUG_ISO_SERVER) printf("ISO_SERVER: new iso connection thread started\n"); return self; }
/* * ======== Processor_init ======== */ Void Processor_init(Void) { if (curInit != TRUE) { curInit = TRUE; GT_create(&curTrace, Processor_GTNAME); /* Semaphore with count 0, will be posted when a command is present */ dcmd.cmdPresent = Sem_create(CMDKEY, 0); /* Semaphore with count 0, will be posted when reply is ready */ dcmd.replyPresent = Sem_create(REPLYKEY, 0); /* * Create lock to allow only one thread at a time to send command * to the daemon. */ dcmd.gate = Lock_create(NULL); if ((dcmd.cmdPresent == NULL) || (dcmd.replyPresent == NULL) || (dcmd.gate == NULL)) { // TODO: Shouldn't we abort? GT_0trace(curTrace, GT_7CLASS, "Processor_init> ERROR: cannot" " create semaphores or lock\n"); } if ((dcmd.dproc = Thread_create((Fxn)daemon, NULL)) == NULL) { GT_0trace(curTrace, GT_7CLASS, "Processor_init> " "ERROR: cannot create DSP daemon\n"); } Power_init(); Global_atexit((Fxn)cleanup); } }
/** * @brief The BIOS main() entry point. * * @remark The purpose of this function is to create several BIOS worker * tasks, one for each core including the one running this app, * each of which will execute this simple example. * * @remark This is called during initialization, but before the BIOS * scheduler has begun running. */ Void main(Int argc, String argv[]) { Thread_Params threadParams; int i; int numCores; sprintf(ti_sdo_ce_osal_bios_Global_CE_DEBUG, "1"); ti_sdo_ce_osal_bios_Global_CE_DEBUG[0] = '2'; ti_sdo_ce_osal_bios_Global_CE_DEBUG[1] = '\0'; /* init Codec Engine */ CERuntime_init(); /* Enable all trace for xdc.runtime.Main */ Diags_setMask("xdc.runtime.Main+EX1234567"); Log_print0(Diags_USER2, "main> ti.sdo.ce.examples.apps.audio1_copy.sync"); /* Determine number of cores on this device */ numCores = MultiProc_getNumProcessors(); /* Unfortunately, the rts library pre-built with CCS only supports 10 * open files at a time (and 3 are reserved for stdin, stdout, stderr. * This app creates a thread for each core, and each thread requires 2 * file handles. So, if numCores is > 3, we will run out of file handles * _with the prebuilt rtslib. You can modify the rtslib to support more * than 10 handles, and link that lib in, but that's beyond the scope of * this app. We limit the number to 3 cores here. * * If you rebuild rtslib to support more open file handles, you can remove * the following numCores limiting assignment. */ if (numCores > 3) { numCores = 3; } /* create a thread to communicate with each remote core */ for (i = 0; i < numCores; i++) { Thread_Params_init(&threadParams); /* 6K stack size */ threadParams.stackSize = 6 * 1024; /* priority - thread 0 gets lower pri as it uses a local alg */ threadParams.priority = (i == 0) ? Thread_Priority_BELOW_NORMAL : Thread_Priority_ABOVE_NORMAL; /* task name */ /* TODO, would be better if this taskName were unique for each task */ threadParams.instance->name = taskName; /* unique arg for each thread - so in/out file names are unique */ threadParams.arg = i; if (Thread_create(workerFxn, &threadParams, NULL) == NULL) { System_abort("main: failed to create smain thread."); } } BIOS_start(); }
int start_main_server(Server_Object *server_obj) { Thread_create(&server_obj->serverThread, (TSThreadProc)main_server_loop, server_obj); Thread_run(&server_obj->serverThread); return 0; }
void Thread::start() { m_alive=true; Thread_create(m_handle); }
/** * @brief The BIOS main() entry point. * * @remark The purpose of this function is to create a BIOS worker task * to house our example. * * @remark This is called during BIOS_init, but before the scheduler * has begun running. */ Void main(Int argc, String argv[]) { Thread_Params threadParams; Engine_Desc engDesc; Engine_AlgDesc algDesc; Engine_Error status; sprintf(ti_sdo_ce_osal_bios_Global_CE_DEBUG, "1"); ti_sdo_ce_osal_bios_Global_CE_DEBUG[0] = '2'; ti_sdo_ce_osal_bios_Global_CE_DEBUG[1] = '\0'; /* init Codec Engine */ CERuntime_init(); /* Enable all trace for xdc.runtime.Main */ Diags_setMask("xdc.runtime.Main+EX1234567"); Log_print0(Diags_USER2, "main> ti.sdo.ce.examples.apps.speech1_copy"); /* * Create the Engine and add our sphdec1_copy and sphenc1_copy algs to * it. Note, this can also be done in a config script. */ Engine_initDesc(&engDesc); engDesc.name = "speech1_copy"; engDesc.remoteName = NULL; status = Engine_add(&engDesc); if (status != Engine_EOK) { Log_print1(Diags_ERROR, "main-> ERROR: Runtime Engine_add() " "failed (0x%x)\n", status); /* don't continue */ while (1) {} } /* * Add the "sphdecl_copy" and "sphenc1_copy" algs to the * "speech1_copy" engine. */ Engine_initAlgDesc(&algDesc); /* Set fields to defaults */ algDesc.name = "sphdec1_copy"; algDesc.fxns = (IALG_Fxns *)&SPHDEC1COPY_TI_ISPHDEC1COPY; algDesc.idmaFxns = NULL; algDesc.isLocal = TRUE; algDesc.groupId = 0; algDesc.iresFxns = NULL; algDesc.types = SPHDEC1_VISATYPE; status = Engine_addAlg("speech1_copy", NULL, NULL, &algDesc); if (status != Engine_EOK) { Log_print1(Diags_USER7, "App-> ERROR: can't add Alg (0x%x)\n", (IArg)status); /* don't continue */ while (1) {} } algDesc.name = "sphenc1_copy"; algDesc.fxns = (IALG_Fxns *)&SPHENC1COPY_TI_ISPHENC1COPY; algDesc.idmaFxns = NULL; algDesc.isLocal = TRUE; algDesc.groupId = 0; algDesc.iresFxns = NULL; algDesc.types = SPHENC1_VISATYPE; status = Engine_addAlg("speech1_copy", NULL, NULL, &algDesc); if (status != Engine_EOK) { Log_print1(Diags_USER7, "App-> ERROR: can't add Alg (0x%x)\n", (IArg)status); /* don't continue */ while (1) {} } /* Spawn a task to run once the BIOS scheduler is started */ Thread_Params_init(&threadParams); /* 6K stack size */ threadParams.stackSize = 6 * 1024; /* task name */ threadParams.instance->name = taskName; /* used for in/out file names */ threadParams.arg = 0; if (Thread_create(workerFxn, &threadParams, NULL) == NULL) { System_abort("main: failed to create smain thread."); } /* Start the BIOS scheduler */ BIOS_start(); }
/* * ======== Processor_init ======== */ Void Processor_init(Void) { GateThread_Params params; Registry_Result result; /* * No need to reference count for Registry_addModule(), since there * is no way to remove the module. */ if (regInit == 0) { /* Register this module for logging */ result = Registry_addModule(&ti_sdo_ce_ipc_processor_desc, Processor_MODNAME); Assert_isTrue(result == Registry_SUCCESS, (Assert_Id)NULL); if (result == Registry_SUCCESS) { /* Set the diags mask to the CE default */ CESettings_init(); CESettings_setDiags(Processor_MODNAME); } regInit = 1; } if (curInit != TRUE) { curInit = TRUE; /* Semaphore with count 0, will be posted when a command is present */ dcmd.cmdPresent = SemThread_create(0, NULL, NULL); /* Semaphore with count 0, will be posted when reply is ready */ dcmd.replyPresent = SemThread_create(0, NULL, NULL); /* * Create lock to allow only one thread at a time to send command * to the daemon. */ GateThread_Params_init(¶ms); dcmd.gate = GateThread_create(¶ms, NULL); if ((dcmd.cmdPresent == NULL) || (dcmd.replyPresent == NULL) || (dcmd.gate == NULL)) { // TODO: Shouldn't we abort? Log_print0(Diags_USER7, "[+7] Processor_init> ERROR: cannot" " create semaphores or lock"); } Log_print0(Diags_USER2, "[+2] Processor_init> SysLink_setup()..."); SysLink_setup(); Log_print0(Diags_USER2, "[+2] Processor_init> " "... SysLink_setup() done"); if ((dcmd.dproc = Thread_create((Thread_RunFxn)daemon, NULL, NULL)) == NULL) { Log_print0(Diags_USER7, "[+7] Processor_init> " "ERROR: cannot create DSP daemon"); } if (Thread_start(NULL) != TRUE) { Log_print0(Diags_USER7, "[+7] Processor_init> " "ERROR: cannot start threads"); } Global_atexit((Fxn)cleanup); } }
void IsoClientConnection_associate(IsoClientConnection self, IsoConnectionParameters* params, ByteBuffer* payload) { Socket socket = TcpSocket_create(); self->socket = socket; if (!Socket_connect(socket, params->hostname, params->tcpPort)) goto returnError; self->cotpBuf = malloc(ISO_CLIENT_BUFFER_SIZE); self->cotpBuffer = calloc(1, sizeof(ByteBuffer)); ByteBuffer_wrap(self->cotpBuffer, self->cotpBuf, 0, ISO_CLIENT_BUFFER_SIZE); self->cotpConnection = calloc(1, sizeof(CotpConnection)); CotpConnection_init(self->cotpConnection, socket, self->cotpBuffer); /* COTP handshake */ CotpIndication cotpIndication = CotpConnection_sendConnectionRequestMessage(self->cotpConnection); cotpIndication = CotpConnection_parseIncomingMessage(self->cotpConnection); if (cotpIndication != CONNECT_INDICATION) goto returnError; /* Upper layers handshake */ AcseConnection acse; ByteBuffer acseBuffer; ByteBuffer_wrap(&acseBuffer, self->buffer1, 0, ISO_CLIENT_BUFFER_SIZE); AcseConnection_init(&acse); if (params != NULL) AcseConnection_setAuthenticationParameter(&acse, params->acseAuthParameter); AcseConnection_createAssociateRequestMessage(&acse, &acseBuffer, payload); ByteBuffer presentationBuffer; ByteBuffer_wrap(&presentationBuffer, self->buffer2, 0, ISO_CLIENT_BUFFER_SIZE); self->presentation = calloc(1, sizeof(IsoPresentation)); IsoPresentation_init(self->presentation); IsoPresentation_createConnectPdu(self->presentation, &presentationBuffer, &acseBuffer); ByteBuffer sessionBuffer; ByteBuffer_wrap(&sessionBuffer, self->buffer1, 0, ISO_CLIENT_BUFFER_SIZE); self->session = calloc(1, sizeof(IsoSession)); IsoSession_init(self->session); IsoSession_createConnectSpdu(self->session, &sessionBuffer, ByteBuffer_getSize(&presentationBuffer)); ByteBuffer_append(&sessionBuffer, ByteBuffer_getBuffer(&presentationBuffer), ByteBuffer_getSize(&presentationBuffer)); CotpConnection_sendDataMessage(self->cotpConnection, &sessionBuffer); cotpIndication = CotpConnection_parseIncomingMessage(self->cotpConnection); if (cotpIndication != DATA_INDICATION) goto returnError; IsoSessionIndication sessionIndication; sessionIndication = IsoSession_parseMessage(self->session, CotpConnection_getPayload(self->cotpConnection)); if (sessionIndication != SESSION_CONNECT) { if (DEBUG) printf("IsoClientConnection_associate: no session connect indication\n"); goto returnError; } IsoPresentationIndication presentationIndication; presentationIndication = IsoPresentation_parseAcceptMessage(self->presentation, IsoSession_getUserData(self->session)); if (presentationIndication != PRESENTATION_OK) { if (DEBUG) printf("IsoClientConnection_associate: no presentation ok indication\n"); goto returnError; } AcseIndication acseIndication; acseIndication = AcseConnection_parseMessage(&acse, &self->presentation->nextPayload); if (acseIndication != ACSE_ASSOCIATE) { if (DEBUG) printf("IsoClientConnection_associate: no ACSE_ASSOCIATE indication\n"); goto returnError; } ByteBuffer acsePayload; //TODO allocate buffer dynamically??? ByteBuffer_wrap(&acsePayload, acse.userDataBuffer, acse.userDataBufferSize, 1024); self->callback(ISO_IND_ASSOCIATION_SUCCESS, self->callbackParameter, &acsePayload); self->state = STATE_ASSOCIATED; AcseConnection_destroy(&acse); self->thread = Thread_create(connectionHandlingThread, self, false); Thread_start(self->thread); return; returnError: self->callback(ISO_IND_ASSOCIATION_FAILED, self->callbackParameter, &acsePayload); AcseConnection_destroy(&acse); self->state = STATE_ERROR; return; }