void* ioThread(t_ioThreadsArgs* ioThreadsArgs) { t_ioProcessing* ioProcessing; uint32_t sleepArg; t_logs* log = logCreate("I/O", ioThreadsArgs->log_mutex); char* msg = NULL; while (true) { sem_wait(ioThreadsArgs->LPB_empty); //para llevar la cuenta segura de los que estan ejecutando nomas: sem_wait(ioThreadsArgs->io_threads); pthread_mutex_lock(ioThreadsArgs->LPB_mutex); ioProcessing = queue_pop(ioThreadsArgs->LPB); pthread_mutex_unlock(ioThreadsArgs->LPB_mutex); sleepArg = (uint32_t) (ioProcessing->ioInfo->ioTime * (uint32_t) (*ioThreadsArgs->IO_TIME)); if (!ioProcessing->ioInfo->flagNonBlocking) { //si es bloqueante, lo mete a LFIO asprintf(&msg, "PID:%u; Realizando E/S, bloqueante", ioProcessing->processImage->pid); logWriteINFO(log, msg); free(msg); sleep(sleepArg); logWriteLSCH(log, ioProcessing->processImage->pid, "Bloqueados", "Fin I/0"); pthread_mutex_lock(ioThreadsArgs->LFIO_mutex); queue_push(ioThreadsArgs->LFIO, ioProcessing->processImage); sem_post(ioThreadsArgs->LFIO_empty); sem_post(ioThreadsArgs->STS_in_empty); pthread_mutex_unlock(ioThreadsArgs->LFIO_mutex); } // si era no bloqueante, ademas solo libera, no mete a LFIO else { asprintf(&msg, "PID:%u; Realizando E/S, no bloqueante", ioProcessing->processImage->pid); logWriteINFO(log, msg); free(msg); sleep(sleepArg); } free(ioProcessing->ioInfo); free(ioProcessing); sem_post(ioThreadsArgs->io_threads); // terminó de ejecutar, un hilo disponible más // processImage, no se libera la memoria alocada, esta en LFIO o está siendo utilizada por PROCER } logDestroy(log); return NULL ; }
/** * Create and open a file * * If the file does not exist, first create it with the specified * mode, and then open it. * * If this method is not implemented or under Linux kernel * versions earlier than 2.6.15, the mknod() and open() methods * will be called instead. * * Introduced in version 2.5 */ int sfs_create(const char *path, mode_t mode, struct fuse_file_info *fi) { int retstat = 0; char fpath[PATH_MAX]; int fd; sfs_fullpath(fpath, path); fd = creat(fpath, mode); if (fd != -1) // log only successful attempts logCreate(path, mode); if (fd < 0) retstat = sfs_error("sfs_create creat"); fi->fh = fd; return retstat; }
int main(int argc, char *argv[]) { int i, sub = argv[1][0] - '0'; char my_name[6] = "Testx"; MX_Type msg[4]; my_name[4] = argv[1][0]; MX *mx = mxConnect(NULL, "localhost", my_name); logger = logCreate(); logToFP(logger, stdout); #if 0 logWithDate(logger); logWithTime(logger, 6); #endif logWithString(logger, my_name); mxOnNewComponent(mx, on_new_component, NULL); mxOnEndComponent(mx, on_end_component, NULL); mxOnNewMessage(mx, on_new_message, NULL); for (i = 1; i <= sub; i++) { char msg_name[5]; snprintf(msg_name, sizeof(msg_name), "Msg%d", i); msg[i] = mxRegister(mx, msg_name); on_new_message(mx, msg_name, msg[i], NULL); if (i == sub) { mxPublish(mx, msg[i]); } else { mxSubscribe(mx, msg[i], on_message, NULL); } } mxRun(mx); return 0; }
// ============================================================================================== // // Get Logs // extern void ewmHandleAnnounceLog (BREthereumEWM ewm, BREthereumEWMClientAnnounceLogBundle *bundle, int id) { switch (ewm->mode) { case BRD_ONLY: case BRD_WITH_P2P_SEND: { // This 'announce' call is coming from the guaranteed BRD endpoint; thus we don't need to // worry about the validity of the transaction - it is surely confirmed. BREthereumLogTopic topics [bundle->topicCount]; for (size_t index = 0; index < bundle->topicCount; index++) topics[index] = logTopicCreateFromString(bundle->arrayTopics[index]); // In general, log->data is arbitrary data. In the case of an ERC20 token, log->data // is a numeric value - for the transfer amount. When parsing in logRlpDecode(), // log->data is assigned with rlpDecodeBytes(coder, items[2]); we'll need the same // thing, somehow BRCoreParseStatus parseStatus = CORE_PARSE_OK; UInt256 value = createUInt256Parse(bundle->data, 0, &parseStatus); assert (CORE_PARSE_OK == parseStatus); BRRlpItem item = rlpEncodeUInt256 (ewm->coder, value, 1); BREthereumLog log = logCreate(bundle->contract, bundle->topicCount, topics, rlpGetDataSharedDontRelease(ewm->coder, item)); rlpReleaseItem (ewm->coder, item); // Given {hash,logIndex}, initialize the log's identifier assert (bundle->logIndex <= (uint64_t) SIZE_MAX); logInitializeIdentifier(log, bundle->hash, (size_t) bundle->logIndex); BREthereumTransactionStatus status = transactionStatusCreateIncluded (hashCreateEmpty(), bundle->blockNumber, bundle->blockTransactionIndex, bundle->blockTimestamp, gasCreate(0)); logSetStatus(log, status); // If we had a `bcs` we might think about `bcsSignalLog(ewm->bcs, log);` ewmSignalLog(ewm, BCS_CALLBACK_LOG_UPDATED, log); // Do we need a transaction here? No, if another originated this Log, then we can't ever // care and if we originated this Log, then we'll get the transaction (as part of the BRD // 'getTransactions' endpoint). // // Of course, see the comment in bcsHandleLog asking how to tell the client about a Log... break; } case P2P_WITH_BRD_SYNC: case P2P_ONLY: bcsSendLogRequest(ewm->bcs, bundle->hash, bundle->blockNumber, bundle->blockTransactionIndex); break; } ewmClientAnnounceLogBundleRelease(bundle); }