示例#1
0
ENTRYPOINT void 
init_rubikblocks(ModeInfo *mi) 
{
  rubikblocks_conf *cp;
  if(!rubikblocks) 
  {
    rubikblocks = (rubikblocks_conf *)calloc(MI_NUM_SCREENS(mi), sizeof(rubikblocks_conf));
    if(!rubikblocks) return;
  }
  cp = &rubikblocks[MI_SCREEN(mi)];

  if(tex)
    make_texture(cp);

  if ((cp->glx_context = init_GL(mi)) != NULL) 
  {
    init_gl(mi);
    init_cp(cp);
    init_lists(cp);
    reshape_rubikblocks(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  }
  else 
  {
    MI_CLEARWINDOW(mi);
  }
}
示例#2
0
文件: hello_led.c 项目: kamngur/inet
int main(void)
{
	int i = 0;

	tx_control = 0;
	link_control = 0;
	int a=0;


    unsigned char TXT[] = { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
                          0x01,0x60,0x6E,0x11,0x02,0x0F,
                          0x08,0x00,0x11,0x22,0x33,0x44,
                          0x55,0x66,0x77,0x88,0x99,0xAA,
                          0x55,0x66,0x77,0x88,0x99,0xAA,
                          0x55,0x66,0x77,0x88,0x99,0xAA,
                          0x55,0x66,0x77,0x88,0x99,0xAA,
                          0x55,0x66,0x77,0x88,0x99,0xAA,
                          0x55,0x66,0x77,0x88,0x99,0xAA,
                          0x55,0x66,0x77,0x88,0x99,0xAA,
                          0x00,0x00,0x00,0x20 };
 // LCD_Test();
  init_lists();
  DM9000_init();



  //alt_irq_register( JTAG_UART_0_IRQ, NULL, NULL);
  //alt_irq_register( UART_0_IRQ, NULL, (void*)uart_interrupt);
//  alt_irq_register( TIMER_0_IRQ, NULL, NULL );
//  alt_irq_register( TIMER_1_IRQ, NULL, NULL);
//  alt_irq_register( BUTTON_PIO_IRQ, NULL, (void*)button_interrupt );
 alt_irq_register( DM9000A_IRQ, NULL, (void*)ethernet_interrupts_simple );
//  alt_irq_disable_all();

  for(i=0; i <2 ; i++)
    {
  	  arp_register();
  	  client_register();
    }
  printf("Client registered\n");


  return ethernet_main_loop();
 // return 0;
}
示例#3
0
int main(int argc, char **argv) {
    // check options passed
    if (argc != 2) {
        printf("\nInvalid argument list. Please use '--help' for usage.\n\n");
        return -1;
    }
    // print help 
    if (strcmp("--help", argv[1]) == 0) {
        printf("\nUsage : %s <dump file name>\n", argv[0]);
        printf("\tEx : %s traceroute.pcap\n\n", argv[0]);
        exit(0);
    }
    // pcap file pointer
    pcap_t *pcap_p;
    // error buffer to hold errors on pcap call
    char errorbuf[PCAP_ERRBUF_SIZE];
    // initialize all lists used
    init_lists();

    // open dump file
    pcap_p = pcap_open_offline(argv[1], errorbuf);
    if (pcap_p == NULL) {
        printf("Error while opening dump file.\n%s\n", errorbuf);
        exit(0);
    }
    // check whether the link layer type is Ethernet, return otherwise
    if (pcap_datalink(pcap_p) != DLT_EN10MB) {
        printf("Dump file provided is not captured from Ethernet.\n");
        exit(0);
    }    
    // read all packets from dump file 
    if (pcap_loop(pcap_p, 0, callback_handler, NULL) == -1) {
        printf("Error while reading dump file.\n");
        exit(0);
    }
    // close the pcap file
    pcap_close(pcap_p);       
    // print results stored in lists
    print_results();
    // free memory allocated for lists
    free_lists();
    return 0;
}
示例#4
0
Boolean Prefs_Form_HandleEvent(EventPtr e)
{
  Boolean handled = false;
  FormPtr frm;
  static Short rw = 0;
  static Short ws = 0;
    
  switch (e->eType) {

  case frmOpenEvent:
    frm = FrmGetActiveForm();
    rw = max(1, my_prefs.run_walk_border - my_prefs.walk_center_border);
    ws = max(1, my_prefs.walk_center_border);
    init_checkboxes_1();
    init_checkboxes_2();
    FrmDrawForm(frm);
    init_lists(rw, ws);
    show_box_color(true);
    handled = true;
    break;

  case ctlSelectEvent:
    switch(e->data.ctlSelect.controlID) {
    case btn_prefs_ok:
      prefs_form_save_prefs(rw, ws);
      handled = true;
      break;
    case btn_prefs_cancel:
      LeaveForm();
      handled = true;
      break;
    }
    break;

  default:
    break;
  }
  return handled;
}
示例#5
0
ENTRYPOINT void 
init_rubikblocks(ModeInfo *mi) 
{
  rubikblocks_conf *cp;
  MI_INIT(mi, rubikblocks);
  cp = &rubikblocks[MI_SCREEN(mi)];

  if(tex)
    make_texture(cp);

  if ((cp->glx_context = init_GL(mi)) != NULL) 
  {
    init_gl(mi);
    init_cp(cp);
    init_lists(cp);
    reshape_rubikblocks(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  }
  else 
  {
    MI_CLEARWINDOW(mi);
  }
}
示例#6
0
void    scan(char *file_name)
{
	t_file  file;
	t_list_content *t;
	t_list_reason *r;

	t = malloc(sizeof(t_list_content));
	r = malloc(sizeof(t_list_reason));
	file.name = file_name;
	init_lists(t, r);
	get_extension(&file, r);
	if (file.is_valid)
	{
		if (ft_open_file(&file, t))
		{
			ft_print_name(file.name);
			scan_file_type(&file, t, r, file.extension);
		}
	}
	view_reason_list(&file, r);
	clear_reason_list(r);
}
示例#7
0
/*
 * Slow path try-lock function:
 */
static inline int
rt_mutex_slowtrylock(struct rt_mutex *lock)
{
	unsigned long flags;
	int ret = 0;

	spin_lock_irqsave(&lock->wait_lock, flags);

	if (likely(rt_mutex_owner(lock) != current)) {

		init_lists(lock);

		ret = try_to_take_rt_mutex(lock);
		/*
		 * try_to_take_rt_mutex() sets the lock waiters
		 * bit unconditionally. Clean this up.
		 */
		fixup_rt_mutex_waiters(lock);
	}

	spin_unlock_irqrestore(&lock->wait_lock, flags);

	return ret;
}
示例#8
0
int main(int argc, char **argv, char **env)
{
	int c, ret;
	my_argv	= argv;
        char *ce;

    uselogchan  = 1;
    starttime   = time(NULL);
    skip_banner = 0;

#if defined(RLIMIT_CORE) && defined(HAVE_SYS_RESOURCE_H)
    // Make sure we can dump a core
    struct rlimit   rlim;
    ret = getrlimit (RLIMIT_CORE, &rlim);

    if (ret == 0)
    {
        if (rlim.rlim_cur == 0)
        {
            //fprintf (stderr, "Core limit 0, attempting to set to %d\n", rlim.rlim_max);

            rlim.rlim_cur    = rlim.rlim_max;

            setrlimit (RLIMIT_CORE, &rlim);
        }
    }
#endif

#ifdef HAVE_GNUTLS
    gnutls_global_init ();

    gnutls_certificate_allocate_credentials (&tls_x509_cred);
#endif

		SetTime();

        sprintf (CfgSettings.conf_name, "%s/%s", EPATH, "security.cfg");

        my_env = env;

        while ((c = getopt (argc, argv, "xrshbvntd:c:l:")) != -1)
        {
            switch (c)
            {
                case 'x':
			skip_banner = 1;
			break; 
				case 'h':
					showHelp ();
                    break;
                case 'v':
                        printf("Version: \033[1;31m%s %s-%s\033[0m\n",PACKAGE_NAME,PACKAGE_VERSION,VERSION_STRING);
                        exit(0);
                case 's':
                        nomodules = 1;
                        break;
                case 'd':
						if (optarg)	{
							debug	= atoi(optarg);
							if ((debug < 1) || (debug > 3))
							{
								fprintf (stderr, "Invalid value for -d (%d)\n", debug);
								exit (0);
							}
						}
                        break;
                case 'n':
                        nofork = 1;
                        break;
                case 'c':
						if (optarg) {
	                        if ((optarg[strlen(optarg) - 4] == '.') && optarg[strlen(optarg) - 3] == 'c') {
                                if ((*optarg == '/') || (*optarg == '.'))
                                    strlcpy (CfgSettings.conf_name, optarg, sizeof(CfgSettings.conf_name));
                                else
	                                sprintf (CfgSettings.conf_name, "%s/%s", EPATH, optarg);
                            }
							else
								fprintf(stderr,"Invalid config file specified with -c option skipping.\n");
						}
                        break;
                case 'l':
                        if (optarg)
                            memcpy(logchan,optarg,sizeof(logchan));
                        break;
                case 't':
			config_test();
			exit(0);
            }
        }


        //check to see if were running under root and bail
        if ((getuid() == 0) && (getgid() == 0))
        {
            printf("Error: You are currently trying to run this program as root\n");
            printf("This program does not require root privileges ...\n");
            printf(" \n");
            printf("Running an application as root that does not require root privileges\n");
            printf("can and may have undesirable side effects. \n");
            printf("    We strongly caution against this.       \n");
            exit(0);
        }

        if (chdir (DPATH))
        {
              fprintf (stderr, "Unable to chdir to %s: %s\n", DPATH, strerror(errno));
              exit (EXIT_FAILURE);
        }


		Omega = Core_Construct(); //initialize our core class.
		
        init_lists ();
		InitDefaults();
	
        //we should work on making this more detailed in its error throws
        if (!config_load (CfgSettings.conf_name)) {
               fprintf(stderr, "Unable to read config file.\n");
               exit(0);
        } 
		VerifyConf();
		 

        DaemonSeed();

        atexit(AtExit);
	 
        Run();

        //we returned from Run() Some how :/ i shit you not.. we need to exit ;( *tear*
            Exit(0);
        return 0;
}
示例#9
0
文件: config.c 项目: kzalewski/squirm
/* parse the squirm.conf file
   returns 1 on success, 0 on failure
   */
int parse_squirm_conf(char *filename)
{
    FILE *fp;
    char buff[MAX_BUFF];
    struct cidr src_cidr;
    char *tmp1, *tmp2, *pattern_filename, *fq_pattern_filename;
    struct subnet_block *curr_block;
    int methods;

    pattern_filename = NULL;
    curr_block = NULL;
    fp = fopen(filename, "rt");
    init_lists();

    if(fp == NULL) {
        logprint(LOG_ERROR, "unable to open configuration file [%s]\n", filename);
        dodo_mode = 1;
        return 0;
    }

    logprint(LOG_INFO, "processing configuration file [%s]\n", filename);

    while(!dodo_mode && (fgets(buff, MAX_BUFF, fp) != NULL)) {

        /* skip blank lines and comments */
        if((strncmp(buff, "#", 1) == 0) || (strncmp(buff, "\n", 1) == 0))
            continue;

        if(strlen(buff) != 1) {
            /* chop newline */
            buff[strlen(buff) - 1] = '\0';

            /* do our stuff with the line */
            /* we can have the following appear

            begin
             network
             log
             abort-log
             pattern
             end

             */


            /* begin */
            if(starts_with(buff, "begin") == 1) {
                if (curr_block != NULL) {
                    logprint(LOG_ERROR, "begin keyword found within block in %s\n", filename);
                    dodo_mode = 1;
                    return 0;
                } else {
                    curr_block = add_subnet_block();
                }
                continue;
            }


            /* network */
            if (starts_with(buff, "network") == 1) {
                if (curr_block == NULL) {
                    logprint(LOG_ERROR, "network keyword found outside of block in  %s\n", filename);
                    dodo_mode = 1;
                    return 0;
                } else {
                    /* we need to get the network cidr from after the keyword network */
                    if(load_cidr(strpbrk(buff, "0123456789"), &src_cidr)) {
                        logprint(LOG_ERROR, "Invalid IP network [%s] in config file\n", buff);
                        dodo_mode = 1;
                        return 0;
                    } else {
                        add_to_ip_list(src_cidr, curr_block);
                    }

                }
                continue;
            }


            /* check for an optional abort-log file name */
            if (starts_with(buff, "abort-log") == 1) {
                if (curr_block == NULL) {
                    logprint(LOG_ERROR, "abort-log keyword found outside of block in %s\n", filename);
                    dodo_mode = 1;
                    return 0;
                } else {
                    curr_block->abort_log_name = gen_fq_name(get_stuff_after_keyword(buff), LOGDIR);
                    if (curr_block->abort_log_name == NULL) {
                        logprint(LOG_ERROR, "couldn't allocate memory in parse_squirm_conf()\n");
                        dodo_mode = 1;
                        return 0;
                    }
                }
                continue;
            }


            /* check for an optional log file name (logs matches) */
            if (starts_with(buff, "log")) {
                if (curr_block == NULL) {
                    logprint(LOG_ERROR, "log keyword found outside of block in %s\n", filename);
                    dodo_mode = 1;
                    return 0;
                } else {
                    curr_block->log_name = gen_fq_name(get_stuff_after_keyword(buff), LOGDIR);
                    if (curr_block->log_name == NULL) {
                        logprint(LOG_ERROR, "couldn't allocate memory in parse_squirm_conf()\n");
                        dodo_mode = 1;
                        return 0;
                    }
                }
                continue;
            }



            /* checking for a pattern filename */
            if (starts_with(buff, "pattern") == 1) {
                if (curr_block == NULL) {
                    logprint(LOG_ERROR, "pattern keyword found outside of block in %s\n", filename);
                    dodo_mode = 1;
                    return -1;
                } else {
                    /* format is pattern filename method[, method...] */
                    tmp1 = get_stuff_after_keyword (buff);

                    /* find where white space begins again  */
                    tmp2 = index(tmp1, ' ');
                    if (tmp2 == NULL) {
                        /* no white space at end, but there must be white space between the
                           filename and obligatory method */
                        logprint(LOG_ERROR, "error parsing pattern file name in %s\n", filename);
                        dodo_mode = 1;
                        return -1;
                    } else {
                        pattern_filename = (char *)malloc((tmp2 - tmp1) * sizeof(char)+1);
                        strncpy(pattern_filename, tmp1, tmp2-tmp1);
                        pattern_filename[tmp2-tmp1] = '\0';
                    }
                    if (pattern_filename == NULL) {
                        logprint(LOG_ERROR, "couldn't allocate memory in parse_squirm_conf()\n");
                        dodo_mode = 1;
                        return 0;
                    }

                    fq_pattern_filename = gen_fq_name(pattern_filename, ETCDIR);
                    if (fq_pattern_filename == NULL) {
                        logprint(LOG_ERROR, "couldn't allocate memory in parse_squirm_conf()\n");
                        dodo_mode = 1;
                        return 0;
                    }

                    free(pattern_filename);

                    /* now we start looking for methods */
                    tmp1 = tmp2;
                    methods = 0;
                    while (tmp1 != NULL) {
                        tmp1 = trim_leading_white_space(tmp1);
                        if (tmp1 == NULL) {
                            break;
                        }
                        if (strncasecmp(tmp1, "get", min(strlen("get"), strlen(tmp1))) == 0) {
                            methods |= GET;
                            tmp1 += strlen("get");
                        }
                        else if (strncasecmp(tmp1,"put", min(strlen("put"), strlen(tmp1))) == 0) {
                            methods |= PUT;
                            tmp1 += strlen("put");
                        }
                        else if (strncasecmp(tmp1,"post", min(strlen("post"), strlen(tmp1))) == 0) {
                            methods |= POST;
                            tmp1 += strlen("post");
                        }
                        else if (strncasecmp(tmp1, "head", min(strlen("head"), strlen(tmp1))) == 0) {
                            methods |= HEAD;
                            tmp1 += strlen("head");
                        }
                        else if (strncasecmp(tmp1, "all", min(strlen("all"), strlen(tmp1))) == 0) {
                            methods |= ALL;
                            tmp1 += strlen("all");
                        }

                        tmp1 = index(tmp1, ',');
                        if (tmp1 != NULL) {
                            tmp1++;
                        }
                    }

                    /* insert all the information */
                    if (add_pattern_file(fq_pattern_filename, curr_block, methods) == -1) {
                        logprint(LOG_ERROR, "couldn't parse pattern file %s\n", fq_pattern_filename);
                        dodo_mode = 1;
                        return 0;
                    }
                    free(fq_pattern_filename);
                }

                continue;
            }

            /* check for the presence of an end */
            if (strstr(buff, "end") != NULL) {
                if (curr_block == NULL) {
                    logprint(LOG_ERROR, "found keyword end outside of block in file %s\n", filename);
                    dodo_mode = 1;
                    return -1;
                } else {
                    curr_block = NULL;
                }
                continue;
            }

            /* oops... not a valid option */
            logprint(LOG_ERROR, "found garbage [%s] in configuration file [%s]\n", buff, filename);
        }
    }

    fclose(fp);
    return 1;
}
示例#10
0
static INT_PTR CALLBACK ps_dlg_proc(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp)
{
    /* native uses prop name "Structure", but we're not compatible
       with that so we'll prepend "Wine_". */
    static const WCHAR prop_name[] = {'W','i','n','e','_','S','t','r','u','c','t','u','r','e',0};
    ps_struct_t *ps_struct;

    TRACE("(%p, %04x, %08lx, %08lx)\n", hdlg, msg, wp, lp);

    ps_struct = GetPropW(hdlg, prop_name);

    if(msg != WM_INITDIALOG)
    {
        if(!ps_struct)
            return 0;

        if(ps_struct->ps->lpfnHook)
        {
            INT_PTR ret = ps_struct->ps->lpfnHook(hdlg, msg, wp, lp);
            if(ret) return ret;
        }
    }

    switch(msg)
    {
    case WM_INITDIALOG:
    {
        ps_struct = HeapAlloc(GetProcessHeap(), 0, sizeof(*ps_struct));
        ps_struct->ps = (OLEUIPASTESPECIALW*)lp;
        ps_struct->type_name = NULL;
        ps_struct->source_name = NULL;
        ps_struct->link_type_name = NULL;
        ps_struct->link_source_name = NULL;
        ps_struct->app_name = NULL;
        ps_struct->flags = ps_struct->ps->dwFlags;

        SetPropW(hdlg, prop_name, ps_struct);

        if(!(ps_struct->ps->dwFlags & PSF_SHOWHELP))
        {
            ShowWindow(GetDlgItem(hdlg, IDC_OLEUIHELP), SW_HIDE);
            EnableWindow(GetDlgItem(hdlg, IDC_OLEUIHELP), 0);
        }

        if(ps_struct->ps->lpszCaption)
            SetWindowTextW(hdlg, ps_struct->ps->lpszCaption);

        get_descriptors(hdlg, ps_struct);

        init_lists(hdlg, ps_struct);

        update_src_text(hdlg, ps_struct);

        selection_change(hdlg, ps_struct);

        SetFocus(GetDlgItem(hdlg, IDC_PS_DISPLAYLIST));

        if(ps_struct->ps->lpfnHook)
            ps_struct->ps->lpfnHook(hdlg, msg, 0, 0);
        return FALSE; /* use new focus */
    }
    case WM_COMMAND:
        switch(LOWORD(wp))
        {
        case IDC_PS_DISPLAYLIST:
            switch(HIWORD(wp))
            {
            case LBN_SELCHANGE:
                selection_change(hdlg, ps_struct);
                return FALSE;
            default:
                return FALSE;
            }
        case IDC_PS_PASTE:
        case IDC_PS_PASTELINK:
            switch(HIWORD(wp))
            {
            case BN_CLICKED:
                mode_change(hdlg, ps_struct, LOWORD(wp));
                return FALSE;

            default:
                return FALSE;
            }
        case IDC_OLEUIHELP:
            switch(HIWORD(wp))
            {
            case BN_CLICKED:
                post_help_msg(hdlg, ps_struct);
                return FALSE;
            default:
                return FALSE;
            }
        case IDOK:
        case IDCANCEL:
            switch(HIWORD(wp))
            {
            case BN_CLICKED:
                send_end_dialog_msg(hdlg, ps_struct, LOWORD(wp));
                return FALSE;
            default:
                return FALSE;
            }
        }
        return FALSE;
    default:
        if(msg == oleui_msg_enddialog)
        {
            if(wp == IDOK)
                update_structure(hdlg, ps_struct);
            EndDialog(hdlg, wp);
            /* native does its cleanup in WM_DESTROY */
            RemovePropW(hdlg, prop_name);
            free_structure(ps_struct);
            return TRUE;
        }
        return FALSE;
    }

}
示例#11
0
/*
 * Slow path lock function spin_lock style: this variant is very
 * careful not to miss any non-lock wakeups.
 *
 * The wakeup side uses wake_up_process_mutex, which, combined with
 * the xchg code of this function is a transparent sleep/wakeup
 * mechanism nested within any existing sleep/wakeup mechanism. This
 * enables the seemless use of arbitrary (blocking) spinlocks within
 * sleep/wakeup event loops.
 */
static void  noinline __sched
rt_spin_lock_slowlock(struct rt_mutex *lock)
{
	struct rt_mutex_waiter waiter;
	unsigned long saved_state, flags;
	/* orig_owner is only set if next_waiter is set */
	struct task_struct *uninitialized_var(orig_owner);
	int next_waiter;
	int saved_lock_depth;
	int ret;

	debug_rt_mutex_init_waiter(&waiter);
	waiter.task = NULL;

	raw_spin_lock_irqsave(&lock->wait_lock, flags);
	init_lists(lock);

	if (do_try_to_take_rt_mutex(lock, current, NULL, STEAL_LATERAL)) {
		raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
		return;
	}

	BUG_ON(rt_mutex_owner(lock) == current);

	/*
	 * Here we save whatever state the task was in originally,
	 * we'll restore it at the end of the function and we'll take
	 * any intermediate wakeup into account as well, independently
	 * of the lock sleep/wakeup mechanism. When we get a real
	 * wakeup the task->state is TASK_RUNNING and we change
	 * saved_state accordingly. If we did not get a real wakeup
	 * then we return with the saved state. We need to be careful
	 * about original state TASK_INTERRUPTIBLE as well, as we
	 * could miss a wakeup_interruptible()
	 */
	saved_state = rt_set_current_blocked_state(current->state);

	/*
	 * Prevent schedule() to drop BKL, while waiting for
	 * the lock ! We restore lock_depth when we come back.
	 */
	saved_lock_depth = current->lock_depth;
	current->lock_depth = -1;

	ret = task_blocks_on_rt_mutex(lock, &waiter, current, 0, flags, 1);
	BUG_ON(ret);

	for (;;) {
		int sleep = 1;

		/* Try to acquire the lock again. */
		if (do_try_to_take_rt_mutex(lock, current, &waiter, STEAL_LATERAL))
			break;

		next_waiter = &waiter == rt_mutex_top_waiter(lock);
		if (next_waiter) {
			orig_owner = rt_mutex_owner(lock);
			if (orig_owner)
				get_task_struct(orig_owner);
		}
		raw_spin_unlock_irqrestore(&lock->wait_lock, flags);

		debug_rt_mutex_print_deadlock(&waiter);

		if (next_waiter && orig_owner) {
			if (!adaptive_wait(&waiter, orig_owner))
				sleep = 0;
			put_task_struct(orig_owner);
		}
		if (sleep)
			schedule_rt_mutex(lock);

		raw_spin_lock_irqsave(&lock->wait_lock, flags);
		saved_state = rt_set_current_blocked_state(saved_state);
	}
	current->lock_depth = saved_lock_depth;

	rt_restore_current_state(saved_state);

	/*
	 * try_to_take_rt_mutex() sets the waiter bit
	 * unconditionally. We might have to fix that up:
	 */
	fixup_rt_mutex_waiters(lock);

	BUG_ON(rt_mutex_has_waiters(lock) && &waiter == rt_mutex_top_waiter(lock));
	BUG_ON(!plist_node_empty(&waiter.list_entry));

	raw_spin_unlock_irqrestore(&lock->wait_lock, flags);

	debug_rt_mutex_free_waiter(&waiter);
}
示例#12
0
/*
 * Slow path lock function:
 */
static int __sched
rt_mutex_slowlock(struct rt_mutex *lock, int state,
		  struct hrtimer_sleeper *timeout,
		  int detect_deadlock)
{
	int ret = 0, saved_lock_depth = -1;
	struct rt_mutex_waiter waiter;
	unsigned long flags;

	debug_rt_mutex_init_waiter(&waiter);

	raw_spin_lock_irqsave(&lock->wait_lock, flags);
	init_lists(lock);

	/* Try to acquire the lock again: */
	if (try_to_take_rt_mutex(lock, current, NULL)) {
		raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
		return 0;
	}

	set_current_state(state);

	/* Setup the timer, when timeout != NULL */
	if (unlikely(timeout)) {
		hrtimer_start_expires(&timeout->timer, HRTIMER_MODE_ABS);
		if (!hrtimer_active(&timeout->timer))
			timeout->task = NULL;
	}

	ret = task_blocks_on_rt_mutex(lock, &waiter, current, detect_deadlock, flags, 0);

	/*
	 * We drop the BKL here before we go into the wait loop to avoid a
	 * possible deadlock in the scheduler.
	 *
	 * Note: This must be done after we call task_blocks_on_rt_mutex
	 *  because rt_release_bkl() releases the wait_lock and will
	 *  cause a race between setting the mark waiters flag in
	 *  the owner field and adding this task to the wait list. Those
	 *  two must be done within the protection of the wait_lock.
	 */
	if (unlikely(current->lock_depth >= 0))
		saved_lock_depth = rt_release_bkl(lock, flags);

	if (likely(!ret))
		ret = __rt_mutex_slowlock(lock, state, timeout, &waiter, flags);

	set_current_state(TASK_RUNNING);

	if (unlikely(ret))
		remove_waiter(lock, &waiter, flags);
	BUG_ON(!plist_node_empty(&waiter.list_entry));

	/*
	 * try_to_take_rt_mutex() sets the waiter bit
	 * unconditionally. We might have to fix that up.
	 */
	fixup_rt_mutex_waiters(lock);

	raw_spin_unlock_irqrestore(&lock->wait_lock, flags);

	/* Remove pending timer: */
	if (unlikely(timeout))
		hrtimer_cancel(&timeout->timer);

	/* Must we reaquire the BKL? */
	if (unlikely(saved_lock_depth >= 0))
		rt_reacquire_bkl(saved_lock_depth);

	debug_rt_mutex_free_waiter(&waiter);

	return ret;
}
示例#13
0
文件: MyBot.c 项目: bol/Ants
int main() {
    int action = -1;

    Info = calloc(1, sizeof(struct game_info));
    Game = calloc(1, sizeof(struct game_state));
    Game->map = 0;

    Game->my_ants = 0;
    Game->enemy_ants = 0;
    Game->food = 0;
    Game->dead_ants = 0;

#ifdef DEBUG
	init_log();
#endif

    while (42) {
        int initial_buffer = 100000;

        char *data = malloc(initial_buffer);
        memset(data, 0, initial_buffer);

        *data = '\n';

        char *ins_data = data + 1;

        int i = 0;

        while (1 > 0) {
            ++i;

            if (i > initial_buffer) {
                initial_buffer *= 2;
                data = realloc(data, initial_buffer);
                memset(ins_data, 0, initial_buffer/2);
            }

            *ins_data = getchar();

            if (*ins_data == '\n') {
                char *backup = ins_data;

                while (*(backup - 1) != '\n') {
                    --backup;
                }

                char *test_cmd = get_line(backup);

                if (strcmp(test_cmd, "go") == 0) {
                    action = 0; 
                    free(test_cmd);
                    break;
                }
                else if (strcmp(test_cmd, "ready") == 0) {
                    action = 1;
                    free(test_cmd);
                    break;
                }
                free(test_cmd);
            }
            
            ++ins_data;
        }

        if (action == 0) {
			Log("Playing turn %d\n", Game->turn);
            char *skip_line = data + 1;
            while (*++skip_line != '\n');
            ++skip_line;

			init_lists();
            _init_map(skip_line);
            do_turn();
            fprintf(stdout, "go\n");
            fflush(stdout);
        }
        else if (action == 1) {
			Log("Read game start data\n");
            _init_ants(data + 1);
            Game->my_ant_index = -1;
			Log("Initializing memory\n");
			allocate_map();
			allocate_lists();
			Game->turn = 1;
			Log("Ready to play, signaling engine\n");
            fprintf(stdout, "go\n");
            fflush(stdout);
        }

        free(data);
    }
}
示例#14
0
文件: toc.c 项目: Cloudxtreme/bitchx
int toc_login(char *username, char *password)
{
	char *config;
	struct in_addr *sin;
	char buf[80];
	char buf2[2048];
	
	toc_debug_printf("looking up host! %s", aim_host);

	sin = (struct in_addr *)get_address(aim_host);
	if (!sin) {  
		set_state(STATE_OFFLINE); 
		toc_msg_printf(TOC_CONNECT_MSGS,"Unable to lookup %s", aim_host);
		return -1;
	}
	
	snprintf(toc_addy, sizeof(toc_addy), "%s", inet_ntoa(*sin));
	snprintf(buf, sizeof(buf), "Connecting to %s", inet_ntoa(*sin));
	
	toc_msg_printf(TOC_CONNECT_MSGS,"%s",buf); 
	
	toc_fd = connect_address(sin->s_addr, aim_port);

        if (toc_fd < 0) {
                set_state(STATE_OFFLINE); 
		toc_msg_printf(TOC_CONNECT_MSGS,"Connect to %s failed", inet_ntoa(*sin));
		return -1;
        }

        free(sin);
	
	toc_msg_printf(TOC_CONNECT_MSGS,"Signon: %s",username);
	
	if (toc_signon(username, password) < 0) {
                set_state(STATE_OFFLINE);
		toc_msg_printf(TOC_CONNECT_MSGS,"Disconnected.");
		return -1;
	}

	toc_msg_printf(TOC_CONNECT_MSGS,"Waiting for reply...");
	if (toc_wait_signon() < 0) {
                set_state(STATE_OFFLINE);
		toc_msg_printf(TOC_CONNECT_MSGS,"Authentication Failed");
		return -1;
	}


	snprintf(aim_username, sizeof(aim_username), "%s", username);
	snprintf(aim_password, sizeof(aim_password), "%s", password);

	save_prefs();

	toc_msg_printf(TOC_CONNECT_MSGS,"Retrieving config...");
        if ((config=toc_wait_config()) == NULL) {
		toc_msg_printf(TOC_CONNECT_MSGS,"No Configuration\n");
		set_state(STATE_OFFLINE);
		return -1;

	}
	
	init_lists();
/*        gtk_widget_hide(mainwindow);
	show_buddy_list();  */
        parse_toc_buddy_list(config);
/*        refresh_buddy_window(); */
   
	snprintf(buf2, sizeof(buf2), "toc_init_done");
	sflap_send(buf2, -1, TYPE_DATA);
        
        serv_finish_login();
	return 0;
}
示例#15
0
/*!
 ************************************************************************
 * \brief
 *    Reads new slice from bit_stream
 ************************************************************************
 */
int read_new_slice()
{
  NALU_t *nalu = AllocNALU(MAX_CODED_FRAME_SIZE);
  int current_header;
  int ret;
  int BitsUsedByHeader;
  Slice *currSlice = img->currentSlice;
  Bitstream *currStream;
  int newframe;

  int slice_id_a, slice_id_b, slice_id_c;
  int redundant_pic_cnt_a, redundant_pic_cnt_b, redundant_pic_cnt_c;
  long ftell_position, expected_slice_type;
  
//  int i;
  expected_slice_type = NALU_TYPE_DPA;

  while (1)
  {
    ftell_position = ftell(bits);

    if (input->FileFormat == PAR_OF_ANNEXB)
      ret=GetAnnexbNALU (nalu);
    else
      ret=GetRTPNALU (nalu);

    NALUtoRBSP(nalu);
//    printf ("nalu->len %d\n", nalu->len);
    
    if (ret < 0)
      printf ("Error while getting the NALU in file format %s, exit\n", input->FileFormat==PAR_OF_ANNEXB?"Annex B":"RTP");
    if (ret == 0)
    {
//      printf ("read_new_slice: returning %s\n", "EOS");
      if(expected_slice_type != NALU_TYPE_DPA)
      {
        /* oops... we found the next slice, go back! */
	      fseek(bits, ftell_position, SEEK_SET);
        FreeNALU(nalu);
	      return current_header;
      }
      else
        return EOS;
    }

    // Got a NALU
    if (nalu->forbidden_bit)
    {
      printf ("Found NALU w/ forbidden_bit set, bit error?  Let's try...\n");
    }

    switch (nalu->nal_unit_type)
    {
      case NALU_TYPE_SLICE:
      case NALU_TYPE_IDR:
        img->idr_flag = (nalu->nal_unit_type == NALU_TYPE_IDR);
        img->nal_reference_idc = nalu->nal_reference_idc;
        img->disposable_flag = (nalu->nal_reference_idc == NALU_PRIORITY_DISPOSABLE);
        currSlice->dp_mode = PAR_DP_1;
        currSlice->max_part_nr = 1;
        currSlice->ei_flag = 0;
        currStream = currSlice->partArr[0].bitstream;
        currStream->ei_flag = 0;
        currStream->frame_bitoffset = currStream->read_len = 0;
        memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1);
        currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1);

        // Some syntax of the Slice Header depends on the parameter set, which depends on
        // the parameter set ID of the SLice header.  Hence, read the pic_parameter_set_id
        // of the slice header first, then setup the active parameter sets, and then read
        // the rest of the slice header
        BitsUsedByHeader = FirstPartOfSliceHeader();
        UseParameterSet (currSlice->pic_parameter_set_id);
        BitsUsedByHeader+= RestOfSliceHeader ();

        FmoInit (active_pps, active_sps);

        init_lists(img->type, img->currentSlice->structure);
        reorder_lists (img->type, img->currentSlice);

/*        if (img->frame_num==1) // write a reference list
        {
          count ++;
          if (count==1)
            for (i=0; i<listXsize[0]; i++)
              write_picture(listX[0][i], p_out2);
        }
*/
        if (img->MbaffFrameFlag)
        {
          init_mbaff_lists();
        }

        if (img->currentSlice->structure!=0)
        {
          img->height /=2 ;
          img->height_cr /=2;
        }

        // From here on, active_sps, active_pps and the slice header are valid
        img->current_mb_nr = currSlice->start_mb_nr;

        if (img->tr_old != img->ThisPOC)
        {
          newframe=1;
          img->tr_old = img->ThisPOC;
        }
        else
          newframe = 0;
        if (newframe)
          current_header = SOP;
        else
          current_header = SOS;

        if(img->structure != img->structure_old)        
          newframe |= 1;

        img->structure_old = img->structure; 
//! new stuff StW
        if(newframe || g_new_frame)
        {
          current_header = SOP;
          g_new_frame=0;
        }
        else
          current_header = SOS;

        if (active_pps->entropy_coding_mode_flag)
        {
          int ByteStartPosition = currStream->frame_bitoffset/8;
          if (currStream->frame_bitoffset%8 != 0) 
          {
            ByteStartPosition++;
          }
          arideco_start_decoding (&currSlice->partArr[0].de_cabac, currStream->streamBuffer, ByteStartPosition, &currStream->read_len, img->type);
        }
// printf ("read_new_slice: returning %s\n", current_header == SOP?"SOP":"SOS");
        FreeNALU(nalu);
        return current_header;
        break;
      case NALU_TYPE_DPA:
        //! The state machine here should follow the same ideas as the old readSliceRTP()
        //! basically:
        //! work on DPA (as above)
        //! read and process all following SEI/SPS/PPS/PD/Filler NALUs
        //! if next video NALU is dpB, 
        //!   then read and check whether it belongs to DPA, if yes, use it
        //! else
        //!   ;   // nothing
        //! read and process all following SEI/SPS/PPS/PD/Filler NALUs
        //! if next video NALU is dpC
        //!   then read and check whether it belongs to DPA (and DPB, if present), if yes, use it, done
        //! else
        //!   use the DPA (and the DPB if present)

        /* 
            LC: inserting the code related to DP processing, mainly copying some of the parts
	          related to NALU_TYPE_SLICE, NALU_TYPE_IDR.
        */

        if(expected_slice_type != NALU_TYPE_DPA)
        {
          /* oops... we found the next slice, go back! */
          fseek(bits, ftell_position, SEEK_SET);
          FreeNALU(nalu);
          return current_header;
        }

        img->idr_flag          = (nalu->nal_unit_type == NALU_TYPE_IDR);
        img->nal_reference_idc = nalu->nal_reference_idc;
        img->disposable_flag   = (nalu->nal_reference_idc == NALU_PRIORITY_DISPOSABLE);
        currSlice->dp_mode     = PAR_DP_3;
        currSlice->max_part_nr = 3;
        currSlice->ei_flag     = 0;
        currStream             = currSlice->partArr[0].bitstream;
        currStream->ei_flag    = 0;
        currStream->frame_bitoffset = currStream->read_len = 0;
        memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1);
        currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1);
        
        BitsUsedByHeader     = FirstPartOfSliceHeader();
        UseParameterSet (currSlice->pic_parameter_set_id);
        BitsUsedByHeader    += RestOfSliceHeader ();
        
        FmoInit (active_pps, active_sps);
        
        init_lists(img->type, img->currentSlice->structure);
        reorder_lists (img->type, img->currentSlice);
        
        if (img->MbaffFrameFlag)
        {
          init_mbaff_lists();
        }

        if (img->currentSlice->structure!=0)
        {
          img->height /=2 ;
          img->height_cr /=2;
        }
	
        // From here on, active_sps, active_pps and the slice header are valid
        img->current_mb_nr = currSlice->start_mb_nr;

        if (img->tr_old != img->ThisPOC)
        {
          newframe=1;
          img->tr_old = img->ThisPOC;
        }
        else
          newframe = 0;
        if (newframe)
          current_header = SOP;
        else
          current_header = SOS;

        if(img->structure != img->structure_old)        
          newframe |= 1;

        img->structure_old = img->structure; 
//! new stuff StW
        if(newframe || g_new_frame)
        {
          current_header = SOP;
          g_new_frame=0;
        }
        else
          current_header = SOS;

        /* 
           LC:
              Now I need to read the slice ID, which depends on the value of 
              redundant_pic_cnt_present_flag (pag.49). 
        */
        
        slice_id_a  = ue_v("NALU:SLICE_A slice_idr", currStream);
        if (active_pps->redundant_pic_cnt_present_flag)
          redundant_pic_cnt_a = ue_v("NALU:SLICE_A redudand_pic_cnt", currStream);
        else
          redundant_pic_cnt_a = 0;
        
        if (active_pps->entropy_coding_mode_flag)
        {
          int ByteStartPosition = currStream->frame_bitoffset/8;
          if (currStream->frame_bitoffset%8 != 0) 
          {
            ByteStartPosition++;
          }
          arideco_start_decoding (&currSlice->partArr[0].de_cabac, currStream->streamBuffer, ByteStartPosition, &currStream->read_len, img->type);
        }
// printf ("read_new_slice: returning %s\n", current_header == SOP?"SOP":"SOS");
        break;
      case NALU_TYPE_DPB:
        /* LC: inserting the code related to DP processing */

        currStream             = currSlice->partArr[1].bitstream;
        currStream->ei_flag    = 0;
        currStream->frame_bitoffset = currStream->read_len = 0;
        memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1);
        currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1);

        slice_id_b  = ue_v("NALU:SLICE_B slice_idr", currStream);
        if (active_pps->redundant_pic_cnt_present_flag)
          redundant_pic_cnt_b = ue_v("NALU:SLICE_B redudand_pic_cnt", currStream);
        else
          redundant_pic_cnt_b = 0;
        
        /*  LC: Initializing CABAC for the current data stream. */

        if (active_pps->entropy_coding_mode_flag)
        {
          int ByteStartPosition = currStream->frame_bitoffset/8;
          if (currStream->frame_bitoffset % 8 != 0) 
            ByteStartPosition++;
          
          arideco_start_decoding (&currSlice->partArr[1].de_cabac, currStream->streamBuffer, 
            ByteStartPosition, &currStream->read_len, img->type);
          
        }

        /* LC: resilience code to be inserted */
        /*         FreeNALU(nalu); */
        /*         return current_header; */

        break;
      case NALU_TYPE_DPC:
        /* LC: inserting the code related to DP processing */
        currStream             = currSlice->partArr[2].bitstream;
        currStream->ei_flag    = 0;
        currStream->frame_bitoffset = currStream->read_len = 0;
        memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1);
        currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1);
        
        slice_id_c  = ue_v("NALU:SLICE_C slice_idr", currStream);
        if (active_pps->redundant_pic_cnt_present_flag)
          redundant_pic_cnt_c = ue_v("NALU:SLICE_C redudand_pic_cnt", currStream);
        else
          redundant_pic_cnt_c = 0;
        
        /* LC: Initializing CABAC for the current data stream. */

        if (active_pps->entropy_coding_mode_flag)
        {
          int ByteStartPosition = currStream->frame_bitoffset/8;
          if (currStream->frame_bitoffset % 8 != 0) 
            ByteStartPosition++;
          
          arideco_start_decoding (&currSlice->partArr[2].de_cabac, currStream->streamBuffer, 
            ByteStartPosition, &currStream->read_len, img->type);
        }

        /* LC: resilience code to be inserted */

        FreeNALU(nalu);
        return current_header;

        break;
      case NALU_TYPE_SEI:
        printf ("read_new_slice: Found NALU_TYPE_SEI, len %d\n", nalu->len);
        InterpretSEIMessage(nalu->buf,nalu->len,img);
        break;
      case NALU_TYPE_PPS:
        ProcessPPS(nalu);
        break;

      case NALU_TYPE_SPS:
        ProcessSPS(nalu);
        break;
      case NALU_TYPE_PD:
//        printf ("read_new_slice: Found 'Access Unit Delimiter' NAL unit, len %d, ignored\n", nalu->len);
        break;
      case NALU_TYPE_EOSEQ:
//        printf ("read_new_slice: Found 'End of Sequence' NAL unit, len %d, ignored\n", nalu->len);
        break;
      case NALU_TYPE_EOSTREAM:
//        printf ("read_new_slice: Found 'End of Stream' NAL unit, len %d, ignored\n", nalu->len);
        break;
      case NALU_TYPE_FILL:
        printf ("read_new_slice: Found NALU_TYPE_FILL, len %d\n", nalu->len);
        printf ("Skipping these filling bits, proceeding w/ next NALU\n");
        break;
      default:
        printf ("Found NALU type %d, len %d undefined, ignore NALU, moving on\n", nalu->nal_unit_type, nalu->len);
    }
  }

  FreeNALU(nalu);

  return  current_header;
}
示例#16
0
/*
 * Slow path lock function spin_lock style: this variant is very
 * careful not to miss any non-lock wakeups.
 *
 * The wakeup side uses wake_up_process_mutex, which, combined with
 * the xchg code of this function is a transparent sleep/wakeup
 * mechanism nested within any existing sleep/wakeup mechanism. This
 * enables the seemless use of arbitrary (blocking) spinlocks within
 * sleep/wakeup event loops.
 */
static void fastcall noinline __sched
rt_spin_lock_slowlock(struct rt_mutex *lock)
{
	struct rt_mutex_waiter waiter;
	unsigned long saved_state, state, flags;

	debug_rt_mutex_init_waiter(&waiter);
	waiter.task = NULL;

	spin_lock_irqsave(&lock->wait_lock, flags);
	init_lists(lock);

	/* Try to acquire the lock again: */
	if (try_to_take_rt_mutex(lock)) {
		spin_unlock_irqrestore(&lock->wait_lock, flags);
		return;
	}

	BUG_ON(rt_mutex_owner(lock) == current);

	/*
	 * Here we save whatever state the task was in originally,
	 * we'll restore it at the end of the function and we'll take
	 * any intermediate wakeup into account as well, independently
	 * of the lock sleep/wakeup mechanism. When we get a real
	 * wakeup the task->state is TASK_RUNNING and we change
	 * saved_state accordingly. If we did not get a real wakeup
	 * then we return with the saved state.
	 */
	saved_state = xchg(&current->state, TASK_UNINTERRUPTIBLE);

	for (;;) {
		unsigned long saved_flags;
		int saved_lock_depth = current->lock_depth;

		/* Try to acquire the lock */
		if (try_to_take_rt_mutex(lock))
			break;
		/*
		 * waiter.task is NULL the first time we come here and
		 * when we have been woken up by the previous owner
		 * but the lock got stolen by an higher prio task.
		 */
		if (!waiter.task) {
			task_blocks_on_rt_mutex(lock, &waiter, 0, flags);
			/* Wakeup during boost ? */
			if (unlikely(!waiter.task))
				continue;
		}

		/*
		 * Prevent schedule() to drop BKL, while waiting for
		 * the lock ! We restore lock_depth when we come back.
		 */
		saved_flags = current->flags & PF_NOSCHED;
		current->lock_depth = -1;
		current->flags &= ~PF_NOSCHED;
		spin_unlock_irqrestore(&lock->wait_lock, flags);

		debug_rt_mutex_print_deadlock(&waiter);

		schedule_rt_mutex(lock);

		spin_lock_irqsave(&lock->wait_lock, flags);
		current->flags |= saved_flags;
		current->lock_depth = saved_lock_depth;
		state = xchg(&current->state, TASK_UNINTERRUPTIBLE);
		if (unlikely(state == TASK_RUNNING))
			saved_state = TASK_RUNNING;
	}

	state = xchg(&current->state, saved_state);
	if (unlikely(state == TASK_RUNNING))
		current->state = TASK_RUNNING;

	/*
	 * Extremely rare case, if we got woken up by a non-mutex wakeup,
	 * and we managed to steal the lock despite us not being the
	 * highest-prio waiter (due to SCHED_OTHER changing prio), then we
	 * can end up with a non-NULL waiter.task:
	 */
	if (unlikely(waiter.task))
		remove_waiter(lock, &waiter, flags);
	/*
	 * try_to_take_rt_mutex() sets the waiter bit
	 * unconditionally. We might have to fix that up:
	 */
	fixup_rt_mutex_waiters(lock);

	spin_unlock_irqrestore(&lock->wait_lock, flags);

	debug_rt_mutex_free_waiter(&waiter);
}
示例#17
0
/*
 * Slow path lock function:
 */
static int __sched
rt_mutex_slowlock(struct rt_mutex *lock, int state,
		  struct hrtimer_sleeper *timeout,
		  int detect_deadlock)
{
	int ret = 0, saved_lock_depth = -1;
	struct rt_mutex_waiter waiter;
	unsigned long flags;

	debug_rt_mutex_init_waiter(&waiter);
	waiter.task = NULL;

	spin_lock_irqsave(&lock->wait_lock, flags);
	init_lists(lock);

	/* Try to acquire the lock again: */
	if (try_to_take_rt_mutex(lock)) {
		spin_unlock_irqrestore(&lock->wait_lock, flags);
		return 0;
	}

	/*
	 * We drop the BKL here before we go into the wait loop to avoid a
	 * possible deadlock in the scheduler.
	 */
	if (unlikely(current->lock_depth >= 0))
		saved_lock_depth = rt_release_bkl(lock, flags);

	set_current_state(state);

	/* Setup the timer, when timeout != NULL */
	if (unlikely(timeout))
		hrtimer_start(&timeout->timer, timeout->timer.expires,
			      HRTIMER_MODE_ABS);

	for (;;) {
		unsigned long saved_flags;

		/* Try to acquire the lock: */
		if (try_to_take_rt_mutex(lock))
			break;

		/*
		 * TASK_INTERRUPTIBLE checks for signals and
		 * timeout. Ignored otherwise.
		 */
		if (unlikely(state == TASK_INTERRUPTIBLE)) {
			/* Signal pending? */
			if (signal_pending(current))
				ret = -EINTR;
			if (timeout && !timeout->task)
				ret = -ETIMEDOUT;
			if (ret)
				break;
		}

		/*
		 * waiter.task is NULL the first time we come here and
		 * when we have been woken up by the previous owner
		 * but the lock got stolen by a higher prio task.
		 */
		if (!waiter.task) {
			ret = task_blocks_on_rt_mutex(lock, &waiter,
						      detect_deadlock, flags);
			/*
			 * If we got woken up by the owner then start loop
			 * all over without going into schedule to try
			 * to get the lock now:
			 */
			if (unlikely(!waiter.task))
				continue;

			if (unlikely(ret))
				break;
		}
		saved_flags = current->flags & PF_NOSCHED;
		current->flags &= ~PF_NOSCHED;

		spin_unlock_irq(&lock->wait_lock);

		debug_rt_mutex_print_deadlock(&waiter);

		if (waiter.task)
			schedule_rt_mutex(lock);

		spin_lock_irq(&lock->wait_lock);

		current->flags |= saved_flags;
		set_current_state(state);
	}

	set_current_state(TASK_RUNNING);

	if (unlikely(waiter.task))
		remove_waiter(lock, &waiter, flags);

	/*
	 * try_to_take_rt_mutex() sets the waiter bit
	 * unconditionally. We might have to fix that up.
	 */
	fixup_rt_mutex_waiters(lock);

	spin_unlock_irqrestore(&lock->wait_lock, flags);

	/* Remove pending timer: */
	if (unlikely(timeout))
		hrtimer_cancel(&timeout->timer);

	/*
	 * Readjust priority, when we did not get the lock. We might
	 * have been the pending owner and boosted. Since we did not
	 * take the lock, the PI boost has to go.
	 */
	if (unlikely(ret))
		rt_mutex_adjust_prio(current);

	/* Must we reaquire the BKL? */
	if (unlikely(saved_lock_depth >= 0))
		rt_reacquire_bkl(saved_lock_depth);

	debug_rt_mutex_free_waiter(&waiter);

	return ret;
}
int main(int argc, char *argv[]) {

    if (argc != 9) {
        fprintf(stderr, "Usage: web_server_http <port> <path> <num_dispatch> <num_workers> <num_prefetch> <qlen> <mode> <cache_entries>\n");
        exit(1);
    }


    // argv[1] := <port>
    // Port number on which to accept incoming connections
    init( atoi( argv[1] ) );

    // argv[2] := <path>
    // Web tree root directory
    if ( chdir( argv[2] ) != 0 ) {
    	fprintf(stderr, "Error! Could not set the web tree root directory to %s", argv[2]);
    	exit(1);
    }

    // argv[3] := <num_dispatch>
    // The number of dispatch threads to start
    int num_dispatch = atoi( argv[3] );
    if (num_dispatch <= 0 || num_dispatch > MAX_DISPATCH_THREADS) {
    	fprintf(stderr, "Error! Invalid number of dispatch threads (Max is %d)\n", MAX_DISPATCH_THREADS);
    	exit(1);
    }

    // argv[4] := <num_workers>
    // The number of worker threads to start
    int num_workers = atoi( argv[4] );
    if (num_workers <= 0 || num_workers > MAX_WORKER_THREADS) {
    	fprintf(stderr, "Error! Invalid number of worker threads (Max is %d)\n", MAX_WORKER_THREADS);
    	exit(1);
    }

    // argv[5] := <num_prefetch>
    // The number of prefetch threads to start
    int num_prefetch = atoi( argv[5] );
    if (num_prefetch <= 0 || num_prefetch > MAX_PREFETCH_THREADS) {
    	fprintf(stderr, "Error! Invalid number of prefetch threads. (Max is %d)\n", MAX_PREFETCH_THREADS);
    	exit(1);
    }

    // argv[6] := <qlen>
    // The fixed, bounded length of the request queue
    max_queue_size = atoi( argv[6] );
    if (max_queue_size <= 0 || max_queue_size > MAX_REQUEST_QUEUE_LENGTH) {
    	fprintf(stderr, "Error! Invalid request queue length (Max length is %d)\n", MAX_REQUEST_QUEUE_LENGTH);
    	exit(1);
    }

    // argv[7] := <mode>
    // The mode (FCFS, CRF, SFF) to run the worker thread(s) in
    // FCFS: First Come First Serve
    // CRF: Cached Requests First
    // SFF: Smallest File First
    enum mode m = atoi( argv[7] );

    switch (m) {
    case FCFS:
    	getRequest = &queue_getRequest;
    	break;
    case CRF:
    	getRequest = &getCachedRequest;
    	break;
    case SFF:
    	getRequest = &queue_getSmallRequest;
    	break;
    default:
    	fprintf(stderr, "Error! Invalid mode (Must be 0 for FCFS, 1 for CRF, or 2 for SFF)\n");
    	exit(1);
    }

    // argv[8] := <cache-entries>
    // The size of the cache, in number of entries
    max_cache_size = atoi( argv[8] );
    if (max_cache_size <= 0 || max_cache_size > MAX_CACHE_SIZE) {
    	fprintf(stderr, "Error! Invalid cache size (Max size is %d)\n", MAX_CACHE_SIZE);
    	exit(1);
    }


    // Initialize request queue, prefetch queue, and cache
    init_lists();

    logfile = fopen("web_server_log", "a");

    assert( logfile != NULL );



    pthread_t dispatch_threads[num_dispatch];
    pthread_t worker_threads[num_workers];
    pthread_t prefetch_threads[num_prefetch];

    int worker_thread_ids[num_workers];
    int i;

    for (i = 0; i < num_workers; ++i)
    	worker_thread_ids[i] = i + 1;

    for (i = 0; i < num_dispatch; ++i)
    	pthread_create(&dispatch_threads[i], NULL, &dispatch_thread, NULL);
    for (i = 0; i < num_workers; ++i)
    	pthread_create(&worker_threads[i], NULL, &worker_thread, (void*)&worker_thread_ids[i]);
    for (i = 0; i < num_prefetch; ++i)
    	pthread_create(&prefetch_threads[i], NULL, &prefetch_thread, NULL);

    for (i = 0; i < num_dispatch; ++i)
    	pthread_join(dispatch_threads[i], NULL);

    global_exit = 1;

    for (i = 0; i < num_workers; ++i)
    	pthread_join(worker_threads[i], NULL);
    for (i = 0; i < num_prefetch; ++i)
    	pthread_join(prefetch_threads[i], NULL);

    printf("Shutting down\n");

    return 0;
}