//Creates a mutex lock and returns an opaque ID int sys_mtx_create(void) { int locked; if (argint(0, &locked) < 0) return -1; return mtx_create(locked); }
int main(int argc, char**argv){ mutex = mtx_create(0); uint* returnstack = 0; uint* stack1[128]; uint* stack2[128]; thread_create(*prod,stack1,(void*)0); thread_create(*cons,stack2,(void*)0); thread_join((void*)returnstack); thread_join((void*)returnstack); exit(); return 0; }
/** Basic setup to connect NIC to socket. * @param[in] port = port context struct * @param[in] ifname = Name of NIC device, f.e. "eth0" * @param[in] secondary = if >0 then use secondary stack instead of primary * @return >0 if succeeded */ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary) { int i; int rVal; int *psock; port->getindex_mutex = mtx_create(); port->tx_mutex = mtx_create(); port->rx_mutex = mtx_create(); rVal = bfin_EMAC_init((uint8_t *)priMAC); if (rVal != 0) return 0; if (secondary) { /* secondary port struct available? */ if (port->redport) { /* when using secondary socket it is automatically a redundant setup */ psock = &(port->redport->sockhandle); *psock = -1; port->redstate = ECT_RED_DOUBLE; port->redport->stack.sock = &(port->redport->sockhandle); port->redport->stack.txbuf = &(port->txbuf); port->redport->stack.txbuflength = &(port->txbuflength); port->redport->stack.tempbuf = &(port->redport->tempinbuf); port->redport->stack.rxbuf = &(port->redport->rxbuf); port->redport->stack.rxbufstat = &(port->redport->rxbufstat); port->redport->stack.rxsa = &(port->redport->rxsa); ecx_clear_rxbufstat(&(port->redport->rxbufstat[0])); } else { /* fail */ return 0; } } else { port->getindex_mutex = mtx_create(); port->tx_mutex = mtx_create(); port->rx_mutex = mtx_create(); port->sockhandle = -1; port->lastidx = 0; port->redstate = ECT_RED_NONE; port->stack.sock = &(port->sockhandle); port->stack.txbuf = &(port->txbuf); port->stack.txbuflength = &(port->txbuflength); port->stack.tempbuf = &(port->tempinbuf); port->stack.rxbuf = &(port->rxbuf); port->stack.rxbufstat = &(port->rxbufstat); port->stack.rxsa = &(port->rxsa); ecx_clear_rxbufstat(&(port->rxbufstat[0])); psock = &(port->sockhandle); } /* setup ethernet headers in tx buffers so we don't have to repeat it */ for (i = 0; i < EC_MAXBUF; i++) { ec_setupheader(&(port->txbuf[i])); port->rxbufstat[i] = EC_BUF_EMPTY; } ec_setupheader(&(port->txbuf2)); return 1; }
/// Create and Initialize a Mutex object. /// \param[in] mutex_def mutex definition referenced with \ref osMutex. /// \return mutex ID for reference by other functions or NULL in case of error. /// \note MUST REMAIN UNCHANGED: \b osMutexCreate shall be consistent in every CMSIS-RTOS. osMutexId osMutexCreate (const osMutexDef_t *mutex_def) { (void) mutex_def; return mtx_create(); }