int threadpool_add_task(threadpool_t *pool, void (*function)(void *), void *argument, int flags) { if(pool == NULL || function == NULL) return threadpool_invalid; /* Are we shutting down ? */ if(pool->shutdown) return threadpool_shutdown; int idx = get_lowload_thread(pool); if(idx == -1) return threadpool_invalid; thread_t *thread = &pool->threads[idx]; task_queue_t *queue = thread->task_queue; if(queue == NULL) return threadpool_invalid; pthread_mutex_lock(&(thread->lock)); int err = 0; do{ /* Add task to queue */ thread_task_t task = {function, argument}; if(_push_queue(queue, task) != 0) { err = threadpool_lock_failure; break; } thread->task_num++; }while(0); pthread_mutex_unlock(&pool->lock); return err; }
static int _remote_send_name(struct harbor *h, struct skynet_context * context, uint32_t source, const char name[GLOBALNAME_LENGTH], int type, int session, const char * msg, size_t sz) { struct keyvalue * node = _hash_search(h->map, name); if (node == NULL) { node = _hash_insert(h->map, name); } if (node->value == 0) { if (node->queue == NULL) { node->queue = _new_queue(); } struct remote_message_header header; header.source = source; header.destination = type << HANDLE_REMOTE_SHIFT; header.session = (uint32_t)session; _push_queue(node->queue, msg, sz, &header); // 0 for request _remote_register_name(h, context, name, 0); return 0; } else { return _remote_send_handle(h, context, source, node->value, type, session, msg, sz); } }