Lines Matching defs:ctx
80 ctx_setup(struct context *ctx, size_t bufsiz)
84 if (pipe(ctx->c_pipe) == -1)
87 ctx->c_buf = malloc(bufsiz);
88 if (ctx->c_buf == NULL)
90 ctx->c_bufsiz = bufsiz;
91 ctx->c_nsyscalls = 0;
93 error = pthread_cond_init(&ctx->c_cv, NULL);
97 error = pthread_mutex_init(&ctx->c_mtx, NULL);
103 ctx_teardown(struct context *ctx)
107 if (ctx->c_pipe[0] != -1)
108 close(ctx->c_pipe[0]);
109 ctx->c_pipe[0] = -1;
110 if (ctx->c_pipe[1] != -1)
111 close(ctx->c_pipe[1]);
112 ctx->c_pipe[1] = -1;
114 free(ctx->c_buf);
116 error = pthread_cond_destroy(&ctx->c_cv);
120 error = pthread_mutex_destroy(&ctx->c_mtx);
126 ctx_lock(struct context *ctx)
130 error = pthread_mutex_lock(&ctx->c_mtx);
136 ctx_unlock(struct context *ctx)
140 error = pthread_mutex_unlock(&ctx->c_mtx);
148 struct context ctx;
152 ctx_setup(&ctx, bufsiz);
154 error = pthread_create(&th, NULL, write_thread, &ctx);
158 ctx_lock(&ctx);
160 if (ctx.c_nsyscalls > 0)
163 error = pthread_cond_wait(&ctx.c_cv, &ctx.c_mtx);
167 ctx_unlock(&ctx);
170 close(ctx.c_pipe[0]);
171 ctx.c_pipe[0] = -1;
180 ctx_teardown(&ctx);
188 struct context *ctx = arg;
194 n = write(ctx->c_pipe[1], ctx->c_buf, ctx->c_bufsiz);
201 ctx_lock(ctx);
202 ctx->c_nsyscalls++;
203 ctx_unlock(ctx);
205 error = pthread_cond_signal(&ctx->c_cv);