Skip to content

Commit

Permalink
Delete dead code.
Browse files Browse the repository at this point in the history
Now that lthreads aren't implementing pthreads, we don't need code for
some of the scary corner cases of pthreads.  Remove the cancellation
code that is on the critical path for context switches and is now dead.
  • Loading branch information
davidchisnall committed Aug 18, 2020
1 parent 47a5f0e commit 7716e93
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 60 deletions.
7 changes: 0 additions & 7 deletions src/include/enclave/lthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ enum lthread_st
LT_ST_SLEEPING, /* lthread is sleeping */
LT_ST_EXPIRED, /* lthread has expired and needs to run */
LT_ST_DETACH, /* lthread frees when done, else it waits to join */
LT_ST_CANCELLED, /* lthread has been cancelled */
LT_ST_CANCELSTATE, /* lthread cancellation has been disabled */
LT_ST_CANCEL_DISABLED, /* lthread cancellation has been deferred */
LT_ST_PINNED, /* lthread pinned to ethread */
};

Expand Down Expand Up @@ -238,8 +235,6 @@ extern "C"
void* lthread_func,
void* arg);

void lthread_cancel(struct lthread* lt);

void lthread_notify_completion(void);

bool lthread_should_stop(void);
Expand Down Expand Up @@ -273,8 +268,6 @@ extern "C"

struct lthread* lthread_self(void);

int lthread_setcancelstate(int, int*);

void lthread_set_expired(struct lthread* lt);

int lthread_key_create(long* k, void (*destructor)(void*));
Expand Down
54 changes: 1 addition & 53 deletions src/sched/lthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,21 +453,6 @@ void reset_tls_tp(struct lthread* lt)
int _lthread_resume(struct lthread* lt)
{
struct lthread_sched* sched = lthread_get_sched();
if (lt->attr.state & BIT(LT_ST_CANCELLED))
{
/* if an lthread was joining on it, schedule it to run */
if (lt->lt_join)
{
__scheduler_enqueue(lt->lt_join);
lt->lt_join = NULL;
}
/* if lthread is detached, then we can free it up */
if (lt->attr.state & BIT(LT_ST_DETACH))
{
_lthread_free(lt);
}
return (-1);
}

if (lt->attr.state & BIT(LT_ST_NEW))
_lthread_init(lt);
Expand Down Expand Up @@ -729,20 +714,6 @@ struct lthread* lthread_current(void)
return (lthread_get_sched()->current_lthread);
}

void lthread_cancel(struct lthread* lt)
{
if (lt == NULL)
return;

if (lt->attr.state & BIT(LT_ST_CANCELSTATE))
{
return;
}
lt->attr.state |= BIT(LT_ST_CANCELLED);
_lthread_desched_sleep(lt);
__scheduler_enqueue(lt);
}

static inline void _lthread_desched_ready(void* _lt)
{
// Update lthread state to sleep.
Expand Down Expand Up @@ -892,26 +863,6 @@ struct lthread* lthread_self(void)
}
}

int lthread_setcancelstate(int new, int* old)
{
if (new > 2U)
return EINVAL;
struct lthread* curr = lthread_get_sched()->current_lthread;
if (old)
{
*old = (curr->attr.state & BIT(LT_ST_CANCELSTATE)) > 0;
}
if (new)
{
curr->attr.state |= BIT(LT_ST_CANCELSTATE);
}
else
{
curr->attr.state &= ~BIT(LT_ST_CANCELSTATE);
}
return 0;
}

/**
* Find the TLS slot for a specified lthread. It is the caller's
* responsibility to ensure that the specified lthread is not concurrently
Expand Down Expand Up @@ -1077,9 +1028,6 @@ static void lthread_state_to_string(
STRINGIFY_LT_STATE(SLEEPING)
STRINGIFY_LT_STATE(EXPIRED)
STRINGIFY_LT_STATE(DETACH)
STRINGIFY_LT_STATE(CANCELLED)
STRINGIFY_LT_STATE(CANCELSTATE)
STRINGIFY_LT_STATE(CANCEL_DISABLED)
STRINGIFY_LT_STATE(PINNED)

lt_state_str[offset - 1] = '\0';
Expand Down Expand Up @@ -1137,4 +1085,4 @@ void lthread_dump_all_threads(bool is_lthread)
sgxlkl_info(
"=============================================================\n");
}
#endif
#endif

0 comments on commit 7716e93

Please sign in to comment.