CellMutex::CellMutex () : Mutex(0) { sys_mutex_attribute_t attr; sys_mutex_attribute_initialize(attr); sys_mutex_create(&Mutex, &attr); }
void gsiInitializeCriticalSection(GSICriticalSection *theCrit) { int ret; sys_mutex_attribute_t defaultAttr; sys_mutex_attribute_initialize(defaultAttr); ret = sys_mutex_create(theCrit, &defaultAttr); if (ret != CELL_OK) { gsDebugFormat(GSIDebugCat_Common, GSIDebugType_Misc, GSIDebugLevel_WarmError, "Failed to initialize critical section: %d\r\n", ret); } }
RJ_API rj_net_m_conn_h rj_m_conn_create(uint32 s_sbl, uint32 sbl, uint32 s_rbl, uint32 rbl) { rj_net_multi_conn_t *p_m_conn = (rj_net_multi_conn_t *)sys_malloc(sizeof(rj_net_multi_conn_t));//new rj_net_multi_conn_t; assert (NULL != p_m_conn); p_m_conn->p_sys_mutex = sys_mutex_create(); p_m_conn->conn_list = rj_list_create(); assert (NULL != p_m_conn->conn_list); p_m_conn->curr_conn = rj_list_end(p_m_conn->conn_list); p_m_conn->sub_send_buf_len = s_sbl; p_m_conn->send_buf_len = sbl; p_m_conn->sub_recv_buf_len = s_rbl; p_m_conn->recv_buf_len = rbl; return (rj_net_m_conn_h)(p_m_conn); }
error_code sys_lwmutex_create(vm::ptr<sys_lwmutex_t> lwmutex, vm::ptr<sys_lwmutex_attribute_t> attr) { sysPrxForUser.trace("sys_lwmutex_create(lwmutex=*0x%x, attr=*0x%x)", lwmutex, attr); const u32 recursive = attr->recursive; if (recursive != SYS_SYNC_RECURSIVE && recursive != SYS_SYNC_NOT_RECURSIVE) { sysPrxForUser.error("sys_lwmutex_create(): invalid recursive attribute (0x%x)", recursive); return CELL_EINVAL; } const u32 protocol = attr->protocol; switch (protocol) { case SYS_SYNC_FIFO: break; case SYS_SYNC_RETRY: break; case SYS_SYNC_PRIORITY: break; default: sysPrxForUser.error("sys_lwmutex_create(): invalid protocol (0x%x)", protocol); return CELL_EINVAL; } vm::var<u32> out_id; vm::var<sys_mutex_attribute_t> attrs; attrs->protocol = protocol == SYS_SYNC_FIFO ? SYS_SYNC_FIFO : SYS_SYNC_PRIORITY; attrs->recursive = attr->recursive; attrs->pshared = SYS_SYNC_NOT_PROCESS_SHARED; attrs->adaptive = SYS_SYNC_NOT_ADAPTIVE; attrs->ipc_key = 0; attrs->flags = 0; attrs->name_u64 = attr->name_u64; if (error_code res = g_cfg.core.hle_lwmutex ? sys_mutex_create(out_id, attrs) : _sys_lwmutex_create(out_id, protocol, lwmutex, 0x80000001, attr->name_u64)) { return res; } lwmutex->lock_var.store({ lwmutex_free, 0 }); lwmutex->attribute = attr->recursive | attr->protocol; lwmutex->recursive_count = 0; lwmutex->sleep_queue = *out_id; return CELL_OK; }
sys_threadpool * sys_threadpool_create(uint32_t num_workers) { sys_threadpool *pool = (sys_threadpool *)calloc(1, sizeof(*pool)); sys_worker *worker = NULL; size_t i; if (!pool) return NULL; pool->task_mutex = sys_mutex_create(); pool->task_notify = sys_cond_var_create(); pool->num_workers = num_workers; pool->shutdown = false; if (pool->num_workers <= 0) { if ((pool->num_workers = sys_cpu_count()) <= 0) { log_entry(THREADPOOL_MODULE, LOG_WARNING, "Failed to determine processor count. Limiting server to one thread. To avoid this, specify the number of threads"); pool->num_workers = 1; } } if (rt_array_init(&pool->workers, pool->num_workers, sizeof(sys_worker)) != SYS_OK) goto free_task; if (rt_array_init(&pool->active_tasks, pool->num_workers, sizeof(sys_task *)) != SYS_OK) goto free_workers; if (rt_queue_init(&pool->task_queue, (size_t)pool->num_workers * 2, sizeof(sys_task)) != SYS_OK) goto free_active_tasks; pool->worker_key = sys_tls_alloc_key(); rt_array_fill(&pool->workers); for (i = 0; i < pool->num_workers; ++i) { worker = rt_array_get(&pool->workers, i); worker->id = i; worker->idle = true; worker->pool = pool; worker->thread = sys_thread_create(_threadpool_worker_proc); sys_thread_start(worker->thread, worker); sys_thread_detach(worker->thread); } return pool; free_active_tasks: rt_array_release(&pool->active_tasks); free_workers: rt_array_release(&pool->workers); free_task: sys_mutex_destroy(pool->task_mutex); sys_cond_var_destroy(pool->task_notify); free(pool); return NULL; }