/*1* Copyright (c) 2001, 2002, 20092* The President and Fellows of Harvard College.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. Neither the name of the University nor the names of its contributors13* may be used to endorse or promote products derived from this software14* without specific prior written permission.15*16* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829/*30* Driver code for whale mating problem31*/32#include <types.h>33#include <lib.h>34#include <thread.h>35#include <test.h>36#include <synch.h>3738/*39* 08 Feb 2012 : GWA : Driver code is in kern/synchprobs/driver.c. We will40* replace that file. This file is yours to modify as you see fit.41*42* You should implement your solution to the whalemating problem below.43*/4445// 13 Feb 2012 : GWA : Adding at the suggestion of Isaac Elbaz. These46// functions will allow you to do local initialization. They are called at47// the top of the corresponding driver code.4849void whalemating_init() {50return;51}5253// 20 Feb 2012 : GWA : Adding at the suggestion of Nikhil Londhe. We don't54// care if your problems leak memory, but if you do, use this to clean up.5556void whalemating_cleanup() {57return;58}5960void61male(void *p, unsigned long which)62{63struct semaphore * whalematingMenuSemaphore = (struct semaphore *)p;64(void)which;6566male_start();67// Implement this function68male_end();6970// 08 Feb 2012 : GWA : Please do not change this code. This is so that your71// whalemating driver can return to the menu cleanly.72V(whalematingMenuSemaphore);73return;74}7576void77female(void *p, unsigned long which)78{79struct semaphore * whalematingMenuSemaphore = (struct semaphore *)p;80(void)which;8182female_start();83// Implement this function84female_end();8586// 08 Feb 2012 : GWA : Please do not change this code. This is so that your87// whalemating driver can return to the menu cleanly.88V(whalematingMenuSemaphore);89return;90}9192void93matchmaker(void *p, unsigned long which)94{95struct semaphore * whalematingMenuSemaphore = (struct semaphore *)p;96(void)which;9798matchmaker_start();99// Implement this function100matchmaker_end();101102// 08 Feb 2012 : GWA : Please do not change this code. This is so that your103// whalemating driver can return to the menu cleanly.104V(whalematingMenuSemaphore);105return;106}107108/*109* You should implement your solution to the stoplight problem below. The110* quadrant and direction mappings for reference: (although the problem is,111* of course, stable under rotation)112*113* | 0 |114* -- --115* 0 1116* 3 1117* 3 2118* -- --119* | 2 |120*121* As way to think about it, assuming cars drive on the right: a car entering122* the intersection from direction X will enter intersection quadrant X123* first.124*125* You will probably want to write some helper functions to assist126* with the mappings. Modular arithmetic can help, e.g. a car passing127* straight through the intersection entering from direction X will leave to128* direction (X + 2) % 4 and pass through quadrants X and (X + 3) % 4.129* Boo-yah.130*131* Your solutions below should call the inQuadrant() and leaveIntersection()132* functions in drivers.c.133*/134135// 13 Feb 2012 : GWA : Adding at the suggestion of Isaac Elbaz. These136// functions will allow you to do local initialization. They are called at137// the top of the corresponding driver code.138139void stoplight_init() {140return;141}142143// 20 Feb 2012 : GWA : Adding at the suggestion of Nikhil Londhe. We don't144// care if your problems leak memory, but if you do, use this to clean up.145146void stoplight_cleanup() {147return;148}149150void151gostraight(void *p, unsigned long direction)152{153struct semaphore * stoplightMenuSemaphore = (struct semaphore *)p;154(void)direction;155156// 08 Feb 2012 : GWA : Please do not change this code. This is so that your157// stoplight driver can return to the menu cleanly.158V(stoplightMenuSemaphore);159return;160}161162void163turnleft(void *p, unsigned long direction)164{165struct semaphore * stoplightMenuSemaphore = (struct semaphore *)p;166(void)direction;167168// 08 Feb 2012 : GWA : Please do not change this code. This is so that your169// stoplight driver can return to the menu cleanly.170V(stoplightMenuSemaphore);171return;172}173174void175turnright(void *p, unsigned long direction)176{177struct semaphore * stoplightMenuSemaphore = (struct semaphore *)p;178(void)direction;179180// 08 Feb 2012 : GWA : Please do not change this code. This is so that your181// stoplight driver can return to the menu cleanly.182V(stoplightMenuSemaphore);183return;184}185186187