10 ABTD_xstream_context *p_ctx = (ABTD_xstream_context *)arg;
11 void *(*thread_f)(
void *) = p_ctx->thread_f;
12 void *p_arg = p_ctx->p_arg;
13 ABTI_ASSERT(p_ctx->state == ABTD_XSTREAM_CONTEXT_STATE_RUNNING);
19 pthread_mutex_lock(&p_ctx->state_lock);
22 if (p_ctx->state == ABTD_XSTREAM_CONTEXT_STATE_REQ_JOIN) {
23 pthread_cond_signal(&p_ctx->state_cond);
25 p_ctx->state = ABTD_XSTREAM_CONTEXT_STATE_WAITING;
30 pthread_cond_wait(&p_ctx->state_cond, &p_ctx->state_lock);
31 }
while (p_ctx->state == ABTD_XSTREAM_CONTEXT_STATE_WAITING);
32 if (p_ctx->state == ABTD_XSTREAM_CONTEXT_STATE_REQ_TERMINATE) {
37 ABTI_ASSERT(p_ctx->state == ABTD_XSTREAM_CONTEXT_STATE_RUNNING ||
38 p_ctx->state == ABTD_XSTREAM_CONTEXT_STATE_REQ_JOIN);
41 pthread_mutex_unlock(&p_ctx->state_lock);
48 int ABTD_xstream_context_create(
void *(*f_xstream)(
void *),
void *p_arg,
49 ABTD_xstream_context *p_ctx)
52 p_ctx->thread_f = f_xstream;
54 p_ctx->state = ABTD_XSTREAM_CONTEXT_STATE_RUNNING;
55 pthread_mutex_init(&p_ctx->state_lock, NULL);
56 pthread_cond_init(&p_ctx->state_cond, NULL);
57 int ret = pthread_create(&p_ctx->native_thread, NULL,
66 int ABTD_xstream_context_free(ABTD_xstream_context *p_ctx)
70 pthread_mutex_lock(&p_ctx->state_lock);
71 ABTI_ASSERT(p_ctx->state == ABTD_XSTREAM_CONTEXT_STATE_WAITING);
72 p_ctx->state = ABTD_XSTREAM_CONTEXT_STATE_REQ_TERMINATE;
73 pthread_cond_signal(&p_ctx->state_cond);
74 pthread_mutex_unlock(&p_ctx->state_lock);
76 int ret = pthread_join(p_ctx->native_thread, NULL);
81 pthread_cond_destroy(&p_ctx->state_cond);
82 pthread_mutex_destroy(&p_ctx->state_lock);
86 int ABTD_xstream_context_join(ABTD_xstream_context *p_ctx)
90 pthread_mutex_lock(&p_ctx->state_lock);
91 if (p_ctx->state != ABTD_XSTREAM_CONTEXT_STATE_WAITING) {
92 ABTI_ASSERT(p_ctx->state == ABTD_XSTREAM_CONTEXT_STATE_RUNNING);
93 p_ctx->state = ABTD_XSTREAM_CONTEXT_STATE_REQ_JOIN;
96 pthread_cond_wait(&p_ctx->state_cond, &p_ctx->state_lock);
97 }
while (p_ctx->state == ABTD_XSTREAM_CONTEXT_STATE_REQ_JOIN);
99 ABTI_ASSERT(p_ctx->state == ABTD_XSTREAM_CONTEXT_STATE_WAITING);
100 pthread_mutex_unlock(&p_ctx->state_lock);
104 int ABTD_xstream_context_revive(ABTD_xstream_context *p_ctx)
108 pthread_mutex_lock(&p_ctx->state_lock);
109 ABTI_ASSERT(p_ctx->state == ABTD_XSTREAM_CONTEXT_STATE_WAITING);
110 p_ctx->state = ABTD_XSTREAM_CONTEXT_STATE_RUNNING;
111 pthread_cond_signal(&p_ctx->state_cond);
112 pthread_mutex_unlock(&p_ctx->state_lock);
116 int ABTD_xstream_context_set_self(ABTD_xstream_context *p_ctx)
119 p_ctx->native_thread = pthread_self();
#define HANDLE_ERROR(msg)
static void * ABTDI_xstream_context_thread_func(void *arg)