From 257b9e11ab6cf503d0b9582eb855ea0b50ec8877 Mon Sep 17 00:00:00 2001 From: hemagx Date: Tue, 1 Mar 2016 07:48:59 +0200 Subject: Interface thread.c --- src/common/thread.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src/common/thread.c') diff --git a/src/common/thread.c b/src/common/thread.c index b724344e6..7bcffaf86 100644 --- a/src/common/thread.c +++ b/src/common/thread.c @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) rAthena Project (www.rathena.org) * * Hercules is free software: you can redistribute it and/or modify @@ -68,6 +68,9 @@ struct rAthread { __thread int g_rathread_ID = -1; #endif +struct thread_interface thread_s; +struct thread_interface *thread; + /// /// Subystem Code /// @@ -100,7 +103,7 @@ void rathread_final(void) { for(i = 1; i < RA_THREADS_MAX; i++){ if(l_threads[i].proc != NULL){ ShowWarning("rAthread_final: unterminated Thread (tid %u entryPoint %p) - forcing to terminate (kill)\n", i, l_threads[i].proc); - rathread_destroy(&l_threads[i]); + thread->destroy(&l_threads[i]); } } @@ -159,7 +162,7 @@ static void *raThreadMainRedirector( void *p ){ /// API Level /// rAthread *rathread_create(rAthreadProc entryPoint, void *param) { - return rathread_createEx( entryPoint, param, (1<<23) /*8MB*/, RAT_PRIO_NORMAL ); + return thread->createEx(entryPoint, param, (1<<23) /*8MB*/, RAT_PRIO_NORMAL); }//end: rathread_create() rAthread *rathread_createEx(rAthreadProc entryPoint, void *param, size_t szStack, RATHREAD_PRIO prio) { @@ -205,7 +208,7 @@ rAthread *rathread_createEx(rAthreadProc entryPoint, void *param, size_t szStack pthread_attr_destroy(&attr); #endif - rathread_prio_set( handle, prio ); + thread->prio_set( handle, prio ); return handle; }//end: rathread_createEx @@ -301,3 +304,19 @@ void rathread_yield(void) { sched_yield(); #endif }//end: rathread_yield() + +void thread_defaults(void) +{ + thread = &thread_s; + thread->create = rathread_create; + thread->createEx = rathread_createEx; + thread->destroy = rathread_destroy; + thread->self = rathread_self; + thread->get_tid = rathread_get_tid; + thread->wait = rathread_wait; + thread->prio_set = rathread_prio_set; + thread->prio_get = rathread_prio_get; + thread->yield = rathread_yield; + thread->init = rathread_init; + thread->final = rathread_final; +} -- cgit v1.2.3-60-g2f50