mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 10:46:51 -07:00
Stub Discovery Thread
This commit is contained in:
parent
e1befb2e90
commit
76bafc25c2
4 changed files with 28 additions and 35 deletions
|
@ -29,9 +29,7 @@ typedef struct chiaki_congestion_control_t
|
|||
{
|
||||
ChiakiTakion *takion;
|
||||
ChiakiThread thread;
|
||||
ChiakiCond stop_cond;
|
||||
ChiakiMutex stop_cond_mutex;
|
||||
bool stop_cond_predicate;
|
||||
ChiakiPredCond stop_cond;
|
||||
} ChiakiCongestionControl;
|
||||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_congestion_control_start(ChiakiCongestionControl *control, ChiakiTakion *takion);
|
||||
|
|
|
@ -60,7 +60,7 @@ typedef struct chiaki_discovery_thread_t
|
|||
ChiakiThread thread;
|
||||
} ChiakiDiscoveryThread;
|
||||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_thread_start(ChiakiDiscoveryThread *thread);
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_thread_start(ChiakiDiscoveryThread *thread, ChiakiDiscovery *discovery);
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_thread_stop(ChiakiDiscoveryThread *thread);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -25,25 +25,24 @@ static void *congestion_control_thread_func(void *user)
|
|||
{
|
||||
ChiakiCongestionControl *control = user;
|
||||
|
||||
ChiakiErrorCode err = chiaki_mutex_lock(&control->stop_cond_mutex);
|
||||
ChiakiErrorCode err = chiaki_pred_cond_lock(&control->stop_cond);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
return NULL;
|
||||
|
||||
while(true)
|
||||
{
|
||||
err = chiaki_cond_timedwait(&control->stop_cond, &control->stop_cond_mutex, CONGESTION_CONTROL_INTERVAL);
|
||||
err = chiaki_pred_cond_timedwait(&control->stop_cond, CONGESTION_CONTROL_INTERVAL);
|
||||
if(err != CHIAKI_ERR_SUCCESS && err != CHIAKI_ERR_TIMEOUT)
|
||||
break;
|
||||
if(control->stop_cond_predicate)
|
||||
if(err != CHIAKI_ERR_TIMEOUT)
|
||||
break;
|
||||
// TODO: detect non-stop and non-timeout (spurious) wakeup and wait the rest of the timeout
|
||||
|
||||
CHIAKI_LOGD(control->takion->log, "Sending Congestion Control Packet\n");
|
||||
ChiakiTakionCongestionPacket packet = { 0 }; // TODO: fill with real values
|
||||
chiaki_takion_send_congestion(control->takion, &packet);
|
||||
}
|
||||
|
||||
chiaki_mutex_unlock(&control->stop_cond_mutex);
|
||||
chiaki_pred_cond_unlock(&control->stop_cond);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -51,22 +50,14 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_congestion_control_start(ChiakiCongestionCo
|
|||
{
|
||||
control->takion = takion;
|
||||
|
||||
control->stop_cond_predicate = false;
|
||||
ChiakiErrorCode err = chiaki_cond_init(&control->stop_cond);
|
||||
ChiakiErrorCode err = chiaki_pred_cond_init(&control->stop_cond);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
return err;
|
||||
err = chiaki_mutex_init(&control->stop_cond_mutex);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
chiaki_cond_fini(&control->stop_cond);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = chiaki_thread_create(&control->thread, congestion_control_thread_func, control);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
chiaki_mutex_fini(&control->stop_cond_mutex);
|
||||
chiaki_cond_fini(&control->stop_cond);
|
||||
chiaki_pred_cond_fini(&control->stop_cond);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -75,14 +66,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_congestion_control_start(ChiakiCongestionCo
|
|||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_congestion_control_stop(ChiakiCongestionControl *control)
|
||||
{
|
||||
ChiakiErrorCode err = chiaki_mutex_lock(&control->stop_cond_mutex);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
return err;
|
||||
control->stop_cond_predicate = true;
|
||||
err = chiaki_cond_signal(&control->stop_cond);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
return err;
|
||||
err = chiaki_mutex_unlock(&control->stop_cond_mutex);
|
||||
ChiakiErrorCode err = chiaki_pred_cond_signal(&control->stop_cond);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
return err;
|
||||
|
||||
|
@ -90,8 +74,5 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_congestion_control_stop(ChiakiCongestionCon
|
|||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
return err;
|
||||
|
||||
chiaki_mutex_fini(&control->stop_cond_mutex);
|
||||
chiaki_cond_fini(&control->stop_cond);
|
||||
|
||||
return CHIAKI_ERR_SUCCESS;
|
||||
return chiaki_pred_cond_fini(&control->stop_cond);
|
||||
}
|
||||
|
|
|
@ -98,15 +98,29 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_send(ChiakiDiscovery *discovery,
|
|||
return CHIAKI_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
static void *discovery_thread_func(void *user);
|
||||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_thread_start(ChiakiDiscoveryThread *thread)
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_thread_start(ChiakiDiscoveryThread *thread, ChiakiDiscovery *discovery)
|
||||
{
|
||||
// TODO
|
||||
return CHIAKI_ERR_SUCCESS;
|
||||
thread->discovery = discovery;
|
||||
|
||||
// TODO: stop pipe
|
||||
|
||||
return chiaki_thread_create(&thread->thread, discovery_thread_func, thread);
|
||||
}
|
||||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_thread_stop(ChiakiDiscoveryThread *thread)
|
||||
{
|
||||
// TODO
|
||||
return CHIAKI_ERR_SUCCESS;
|
||||
|
||||
return chiaki_thread_join(&thread->thread, NULL);
|
||||
}
|
||||
|
||||
static void *discovery_thread_func(void *user)
|
||||
{
|
||||
ChiakiDiscoveryThread *thread = user;
|
||||
|
||||
// TODO
|
||||
|
||||
return NULL;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue