/** * camel_operation_cancel: * @cc: operation context * * Cancel a given operation. If @cc is NULL then all outstanding * operations are cancelled. **/ void camel_operation_cancel (CamelOperation *cc) { CamelOperationMsg *msg; LOCK(); if (cc == NULL) { CamelOperation *cn; cc = (CamelOperation *)operation_list.head; cn = cc->next; while (cn) { cc->flags |= CAMEL_OPERATION_CANCELLED; msg = g_malloc0(sizeof(*msg)); e_msgport_put(cc->cancel_port, (EMsg *)msg); cc = cn; cn = cn->next; } } else if ((cc->flags & CAMEL_OPERATION_CANCELLED) == 0) { d(printf("cancelling thread %d\n", cc->id)); cc->flags |= CAMEL_OPERATION_CANCELLED; msg = g_malloc0(sizeof(*msg)); e_msgport_put(cc->cancel_port, (EMsg *)msg); } UNLOCK(); }
void e_msgport_reply (EMsg *msg) { g_return_if_fail (msg != NULL); if (msg->reply_port) e_msgport_put (msg->reply_port, msg); /* else lost? */ }
void *client(void *data) { EMsg *msg; EMsgPort *replyport; int i; replyport = e_msgport_new(); msg = g_malloc0(sizeof(*msg)); msg->reply_port = replyport; for (i=0;i<10;i++) { /* synchronous operation */ printf("client: sending\n"); e_msgport_put(server_port, msg); printf("client: waiting for reply\n"); e_msgport_wait(replyport); printf("client: got reply\n"); } printf("client: sleeping ...\n"); g_usleep(2000000); printf("client: sending multiple\n"); for (i=0;i<10;i++) { msg = g_malloc0(sizeof(*msg)); msg->reply_port = replyport; e_msgport_put(server_port, msg); } printf("client: receiving multiple\n"); for (i=0;i<10;i++) { msg = e_msgport_wait(replyport); g_free(msg); } printf("client: done\n"); return NULL; }