int main(void) { if(init_kernel() != OK) { /* Memory allocation problems */ while(1); } if(create_task( car_movement, 3000 ) != OK ) { /* Memory allocation problems */ while(1); } if (create_task(cruisecontrol, 3500 ) != OK ) { /* Memory allocation problems */ while(1); } if ((mbi=create_mailbox(1,sizeof(int))) == NULL) { /* Memory allocation problems */ while (1); } if ((mbf=create_mailbox(1,sizeof(double))) == NULL) { /* Memory allocation problems */ while (1); } run(); return 0; }
/* * Copy the specified messages to another mailbox. */ int request_copy(const char *server, const char *port, const char *user, const char *mesg, const char *mbox) { int t, r; session *s; const char *m; if (!(s = session_find(server, port, user))) return -1; m = apply_namespace(mbox, s->ns.prefix, s->ns.delim); do { t = imap_copy(s, mesg, m); switch (r = response_generic(s, t)) { case STATUS_RESPONSE_TRYCREATE: if (create_mailbox(s, mbox) == -1) goto fail; break; case -1: goto fail; break; } } while (r == STATUS_RESPONSE_TRYCREATE); return r; fail: close_connection(s); session_destroy(s); return -1; }
/** * send message to given destination */ asmlinkage long sys_SendMsg(pid_t dest, void *a_msg, int len, bool block){ pid_t my_pid = current->pid; void* msg = new_msg(); message* this_mail; mailbox* dest_mailbox; signal* dest_signal; struct task_struct* dest_ts; int existence; if ((len > MAX_MSG_SIZE) || (len < 0)) return MSG_LENGTH_ERROR; if (copy_from_user(msg, a_msg, len)) return MSG_ARG_ERROR; //check if destination is valid if (dest <= 0) return MAILBOX_INVALID; //find task struct for destination pid dest_ts = pid_task(find_vpid(dest), PIDTYPE_PID); // find_task_by_vpid(dest); if (dest_ts == NULL) return MAILBOX_INVALID; //state not 0 or kernel task, invalid dest existence = dest_ts->state; if ((existence != 0) || (dest_ts->mm == NULL)) return MAILBOX_INVALID; //get destination mailbox dest_signal = get_signal(dest); if (dest_signal == NULL) { dest_signal = create_signal(dest, TRUE); } dest_mailbox = get_mailbox(dest); if (dest_mailbox == NULL) { dest_mailbox = create_mailbox(dest); if (dest_mailbox == NULL) return MAILBOX_ERROR; } wake_up(&(dest_signal->wait_null)); if ((block == TRUE) && (dest_mailbox->full == TRUE)){ //wait until not full and send message } else if (block == FALSE && (dest_mailbox->full == TRUE)) return MAILBOX_FULL; if (dest_mailbox->stop) return MAILBOX_STOPPED; this_mail = create_message(my_pid, len, msg); spin_lock(&(dest_mailbox->lock)); add_message(&dest_mailbox, &this_mail); spin_unlock(&(dest_mailbox->lock)); //successfully sent return 0; }
/* * Append supplied message to the specified mailbox. */ int request_append(const char *server, const char *port, const char *user, const char *mbox, const char *mesg, size_t mesglen, const char *flags, const char *date) { int t, r; session *s; const char *m; if (!(s = session_find(server, port, user))) return -1; m = apply_namespace(mbox, s->ns.prefix, s->ns.delim); do { if ((t = imap_append(s, m, flags, date, mesglen)) == -1) goto fail; if ((r = response_continuation(s)) == -1) goto fail; switch (r) { case STATUS_RESPONSE_CONTINUE: if (imap_continuation(s, mesg, mesglen) == -1) goto fail; if ((r = response_generic(s, t)) == -1) goto fail; break; case STATUS_RESPONSE_TRYCREATE: if (create_mailbox(s, mbox) == -1) goto fail; break; case -1: goto fail; break; } } while (r == STATUS_RESPONSE_TRYCREATE); return r; fail: close_connection(s); session_destroy(s); return -1; }