struct xenbus_event *xenbus_wait_for_watch_return(xenbus_event_queue *queue) { struct xenbus_event *event; if (!queue) queue = &xenbus_events; while (!(event = *queue)) { wait_on(&xenbus_watch_queue); } *queue = event->next; return event; }
void ManualConnect(void) { char ssidName[] = "YourAP"; char AP_KEY[] = "yourpass"; uint8_t rval; if (!isInitialized) { printf("CC3000 not initialized; can't run manual connect.\n"); return; } printf("Starting manual connect...\n"); printf(" Disabling auto-connect policy...\n"); (void)wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE); printf(" Deleting all existing profiles...\n"); (void)wlan_ioctl_del_profile(255); wait_on(15*MS_PER_SEC, &ulCC3000Connected, 0, " Waiting until disconnected"); printf(" Manually connecting...\n"); /* Parameter 1 is the security type: WLAN_SEC_UNSEC, WLAN_SEC_WEP, * WLAN_SEC_WPA or WLAN_SEC_WPA2 * Parameter 3 is the MAC adddress of the AP. All the TI examples * use NULL. I suppose you would want to specify this * if you were security paranoid. */ rval = wlan_connect(WLAN_SEC_WPA2, ssidName, strlen(ssidName), NULL, (uint8_t *)AP_KEY, strlen(AP_KEY)); if (rval == 0) { printf(" Manual connect success.\n"); } else { printf(" Unusual return value: %d\n", rval); } }
error_t rwlock_wrlock(struct rwlock_s *rwlock) { uint_t irq_state; mcs_lock(&rwlock->lock, &irq_state); //spinlock_lock(&rwlock->lock); if(rwlock->count == 0) { rwlock->count --; //spinlock_unlock(&rwlock->lock); mcs_unlock(&rwlock->lock, irq_state); return 0; } wait_on(&rwlock->wr_wait_queue, WAIT_LAST); //spinlock_unlock_nosched(&rwlock->lock); mcs_unlock(&rwlock->lock, irq_state); sched_sleep(current_thread); return 0; }
error_t rwlock_rdlock(struct rwlock_s *rwlock) { uint_t irq_state; //spinlock_lock(&rwlock->lock); mcs_lock(&rwlock->lock, &irq_state); /* priority is given to writers */ if((rwlock->count >= 0) && (wait_queue_isEmpty(&rwlock->wr_wait_queue))) { rwlock->count ++; //spinlock_unlock(&rwlock->lock); mcs_unlock(&rwlock->lock, irq_state); return 0; } wait_on(&rwlock->rd_wait_queue, WAIT_LAST); //spinlock_unlock_nosched(&rwlock->lock); mcs_unlock(&rwlock->lock, irq_state); sched_sleep(current_thread); return 0; }
void StartSmartConfig(void) { long rval; if (!isInitialized) { printf("CC3000 not initialized; can't run Smart Config.\n"); return; } printf("Starting Smart Config\n"); printf(" Disabling auto-connect policy..."); if ((rval = wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE)) !=0) { printf(" Failed!\n Setting auto connection policy failed, error: %lx\n", (unsigned long)rval); return; } printf(" Succeed\n"); printf(" Deleting all existing profiles..."); fflush(stdout); if ((rval = wlan_ioctl_del_profile(255)) !=0) { printf(" Failed!\n Deleting all profiles failed, error: %lx\n", (unsigned long)rval); return; } printf(" Succeed\n"); wait_on(20*MS_PER_SEC, &ulCC3000Connected, 0, " Waiting until disconnected"); printf(" Setting smart config prefix..."); fflush(stdout); if ((rval = wlan_smart_config_set_prefix(simpleConfigPrefix)) !=0) { printf(" Failed!\n Setting smart config prefix failed, error: %lx", (unsigned long)rval); return; } printf(" Succeed\n"); printf(" Starting smart config..."); fflush(stdout); if ((rval = wlan_smart_config_start(0)) !=0) { printf(" Failed!\n Starting smart config failed, error: %lx\n", (unsigned long)rval); return; } printf(" Succeed\n"); if (!wait_on(30*MS_PER_SEC, &ulSmartConfigFinished, 1, " Waiting on Starting smart config done")) { printf(" Timed out waiting for Smart Config to finish. Hopefully it did anyway\n"); } printf(" Smart Config packet %s!\n",ulSmartConfigFinished ? "seen" : "NOT seen"); printf(" Enabling auto-connect policy..."); fflush(stdout); if ((rval = wlan_ioctl_set_connection_policy(DISABLE, DISABLE, ENABLE)) !=0) { printf(" Failed!\n Setting auto connection policy failed, error: %lx\n", (unsigned long)rval); return; } printf(" Succeed\n"); printf(" Stopping CC3000...\n"); fflush(stdout); wlan_stop(); /* No error returned here, so nothing to check */ printf(" Pausing for 2 seconds...\n"); sleep(2); printf(" Restarting CC3000... \n"); wlan_start(0); /* No error returned here, so nothing to check */ if (!wait_on(20*MS_PER_SEC, &ulCC3000Connected, 1, " Waiting for connection to AP")) { printf(" Timed out waiting for connection to AP\n"); return; } if (!wait_on(15*MS_PER_SEC, &ulCC3000DHCP, 1, " Waiting for IP address from DHCP")) { printf(" Timed out waiting for IP address from DHCP\n"); return; } printf(" Sending mDNS broadcast to signal we're done with Smart Config...\n"); fflush(stdout); /* The API documentation says mdnsAdvertiser() is supposed to return 0 on * success and SOC_ERROR on failure, but it looks like what it actually * returns is the socket number it used. So we ignore it. */ mdnsadvertiser(1, device_name, strlen(device_name)); printf(" Smart Config finished Successfully!\n"); ShowInformation(); fflush(stdout); }
NTSTATUS thread_impl_t::wait_on_handles( ULONG count, PHANDLE handles, WAIT_TYPE type, BOOLEAN alert, PLARGE_INTEGER timeout) { NTSTATUS r = STATUS_SUCCESS; Alertable = alert; WaitType = type; // iterate the array and wait on each handle for (ULONG i=0; i<count; i++) { dprintf("handle[%ld] = %08lx\n", i, (ULONG) handles[i]); object_t *any = 0; r = object_from_handle( any, handles[i], SYNCHRONIZE ); if (r < STATUS_SUCCESS) { end_wait(); return r; } sync_object_t *obj = dynamic_cast<sync_object_t*>( any ); if (!obj) { end_wait(); return STATUS_INVALID_HANDLE; } r = wait_on( obj ); if (r < STATUS_SUCCESS) { end_wait(); return r; } } // make sure we wait for a little bit every time LARGE_INTEGER t; if (timeout && timeout->QuadPart <= 0 && timeout->QuadPart> -100000LL) { t.QuadPart = -100000LL; timeout = &t; } set_timeout( timeout ); while (1) { r = check_wait(); if (r != STATUS_PENDING) break; if (alerted) { alerted = FALSE; r = STATUS_ALERTED; break; } if (timeout && has_expired()) { r = STATUS_TIMEOUT; break; } in_wait = TRUE; wait(); assert( in_wait == FALSE ); } end_wait(); set_timeout( 0 ); return r; }