Exemple #1
0
static void bce_delete(struct bcentry *bce, int flush)
{
    pthread_rwlock_wrlock(&bce->lock);
    if (bce->type != BCE_DAD) {
        del_task(&bce->tqe);
        if (bce->type != BCE_NONCE_BLOCK)
            xfrm_del_bce(&bce->our_addr, &bce->peer_addr);
    }
    if (bce->cleanup)
        bce->cleanup(bce);
    if (!flush &&
            (bce->type == BCE_CACHED || bce->type == BCE_CACHE_DYING)) {
        struct timespec minlft;
        if (!rr_cn_nonce_lft(bce->nonce_hoa, &minlft)) {
            bce->type = BCE_NONCE_BLOCK;
            add_task_abs(&minlft, &bce->tqe, _expire);
            pthread_rwlock_unlock(&bce->lock);
            return;
        }
    }
    bcache_count--;
    hash_delete(&bc_hash, &bce->our_addr, &bce->peer_addr);
    pthread_rwlock_unlock(&bce->lock);
    bcache_free(bce);
}
Exemple #2
0
/* tell to remove element with zero refcount */
static gboolean
remove_stale_tasks(Window *win, task *tk, gpointer data)
{
    ENTER;
    if (tk->refcount-- == 0) {
        del_task(tk->ics, tk, 0);
        RET(TRUE);
    }
    RET(FALSE);
}
Exemple #3
0
/*      
 ******************************************************************************
 * wrapper --                                                             *//**
 *  
 * \brief This routine is a wrapper function which help to reclaim allocated 
 *        resource after application function exits.
 *  
 * \param [in]  tid     Task Id.
 *
 * \retval None
 *
 *****************************************************************************/
static void *wrapper(void *arg)
{
    task_info *ti = (task_info *)arg;

    ti->fn(ti->arg);

    del_task((long)ti);

    return NULL;
}
//---------------------------------------------------------------------------------------------------------------------
void pmip_bce_delete(pmip_entry_t * bce)
{
	pthread_rwlock_wrlock(&bce->lock);
	del_task(&bce->tqe);
	if (bce->cleanup) {
		bce->cleanup(bce);
	}
	g_pmip_cache_count--;
	hash_delete(&g_pmip_hash, &bce->our_addr, &bce->mn_hw_address);
	pthread_rwlock_unlock(&bce->lock);
	pmipcache_free(bce);
	//dbg("PMIP cache entry is deleted!\n");
}
	bool Scheduler::SchedulerImpl::cancel_task(ITask* task)
	{
		LogTraceObj("(%p)", task);
		auto deleted = del_task(task);
		if (!deleted && task == currentTask) {
			LogDebug("we are trying to cancel task already running: %p", task);
			if (thread::get_id() == thread->get_id()) {
				LogInfo("cancelling task from itself: %p", task);
			} else {
				LogAtten("waiting till task is finished: %p", task);
				while (task == currentTask)
					sync::sleep(0);
			}
		}
		LogTraceObj("(%p) -> %d", task, deleted);
		return deleted;
	}
Exemple #6
0
void
taskbar_read_clientlist (void)
{
	Window *win, focus_win;
	int num, i, rev, desk, new_desk = 0;
	task *list, *next;

	desk = get_current_desktop ();
	if (desk != tb.my_desktop)
	{
		new_desk = 1;
		tb.my_desktop = desk;
	}

	XGetInputFocus (dd, &focus_win, &rev);

	win = get_prop_data (root_win, atom__NET_CLIENT_LIST, XA_WINDOW, &num);
	if (!win)
		return;

	/* remove windows that arn't in the _NET_CLIENT_LIST anymore */
	list = tb.task_list;
	while (list)
	{
		list->focused = (focus_win == list->win);
		next = list->next;

		if (!new_desk)
			for (i = num - 1; i >= 0; i--)
				if (list->win == win[i])
					goto dontdel;
		del_task (list->win);
dontdel:

		list = next;
	}

	/* add any new windows */
	for (i = 0; i < num; i++)
	{
		if (!find_task (win[i]))
			add_task (win[i], (win[i] == focus_win));
	}

	XFree (win);
}
Exemple #7
0
static void dps_statistics_main(void *pDummy)
{
	struct timespec   ts;
	struct timeval    tp;
	int               it;
	int               rc;

	Py_Initialize();

	while (TRUE) {
		pthread_mutex_lock(&dps_statistics_mp);

		it = dps_statistics_sample_interval;
		gettimeofday(&tp, NULL);
		/* Convert from timeval to timespec */
		ts.tv_sec  = tp.tv_sec;
		ts.tv_nsec = tp.tv_usec * 1000;
		ts.tv_sec += it;
		rc = pthread_cond_timedwait(&dps_statistics_cv, &dps_statistics_mp, &ts);
		if (rc == ETIMEDOUT) {
			pthread_mutex_unlock(&dps_statistics_mp);
			/* Update statistics we are interested in. */
			//log_info(PythonDataHandlerLogLevel, "Updating statistics");
			dps_statistics_process();
			//log_info(PythonDataHandlerLogLevel, "Updated statistics");
			continue;
		}
		if (rc == 0) {
			log_info(PythonDataHandlerLogLevel, "Thread exiting");
			pthread_mutex_unlock(&dps_statistics_mp);
			pthread_mutex_destroy(&dps_statistics_mp);
			pthread_cond_destroy(&dps_statistics_cv);
			del_task(statisticsTaskId);
			return;
		}
		pthread_mutex_unlock(&dps_statistics_mp);
	}

	Py_Finalize();
	return;
}
//---------------------------------------------------------------------------------------------------------------------
void pmip_bce_delete(pmip_entry_t * bce)
{
    int mutex_return_code;

    mutex_return_code = pthread_rwlock_wrlock(&bce->lock);
    if (mutex_return_code != 0) {
        dbg("pthread_rwlock_wrlock(&bce->lock) %s\n", strerror(mutex_return_code));
    }
    del_task(&bce->tqe);
    if (bce->cleanup) {
        bce->cleanup(bce);
    }
    g_pmip_cache_count--;
    pmip_hash_delete(&g_pmip_hash, &bce->mn_nai, &bce->mn_serv_mag_addr);
    mutex_return_code = pthread_rwlock_unlock(&bce->lock);
    if (mutex_return_code != 0) {
        dbg("pthread_rwlock_unlock(&bce->lock) %s\n", strerror(mutex_return_code));
    }
    pmipcache_free(bce);
    dbg("PMIP cache entry is deleted!\n");
}
Exemple #9
0
/* bul_delete - deletes a bul entry */
void bul_delete(struct bulentry *bule)
{
	struct home_addr_info *hai = bule->home;

	del_task(&bule->tqe);
	hash_delete(&bul_hash, &bule->hoa, &bule->peer_addr);
	hash_delete(&hai->bul, NULL, &bule->peer_addr);

	if (!IN6_ARE_ADDR_EQUAL(&bule->hoa, &bule->coa)) {
		bule->last_coa = bule->coa;
		bule->coa = bule->hoa;
		bule->coa_changed = 1;
	}
	if (bule->type == BUL_ENTRY) {
		xfrm_del_bule(bule);
		if (!(bule->flags & IP6_MH_BU_HOME))
			mn_rr_delete_bule(bule);
	}
	if (bule->flags & IP6_MH_BU_HOME) {
		if (bule->type == UNREACH_ENTRY) {
			pthread_mutex_lock(&hai->ha_list.c_lock);
			if (IN6_ARE_ADDR_EQUAL(&bule->peer_addr, 
					       &hai->ha_list.last_ha))
				hai->ha_list.last_ha = in6addr_any;
			pthread_mutex_unlock(&hai->ha_list.c_lock);
		} else {
			if (hai->home_block & HOME_LINK_BLOCK)
				xfrm_unblock_link(hai);
			if (hai->home_block & HOME_ADDR_BLOCK)
				xfrm_unblock_hoa(hai);
		}
	}
	while (bule->ext_cleanup)
		bule->ext_cleanup(bule);
	dbg("Deleting bule\n");
	dbg_func(bule, dump_bule);
	free_bule(bule);
}
Exemple #10
0
//---------------------------------------------------------------------------------------------------------------------
void mar_fsm(msg_info_t * info)
{
	int aaa_result = 0;
	dmm_entry *bce = NULL;
	struct in6_addr *prefix;
	struct in6_addr hw_address = EUI64_to_EUI48(info->mn_iid);
	int mutex_return_code;

	mutex_return_code = pthread_rwlock_wrlock(&fsm_lock);
	if (mutex_return_code != 0) {
		dbg("pthread_rwlock_wrlock(&fsm_lock) %s\n", strerror(mutex_return_code));
	}
	//dbg("Entered FSM\n");
	bce = dmm_cache_get(&conf.OurAddress, &hw_address);
	switch (info->msg_event) {
	//--------------------------------------
	case hasRS:
		if (!bce) {
			dbg("New MN is found sending RS, checking AAA ...\n");
			prefix = mnid_hnp_map(&hw_address);
			if (prefix) {
				//dbg("AAA success: prefix to assign: %x:%x:%x:%x:%x:%x:%x:%x \n", NIP6ADDR(prefix));
				memcpy(&info->mn_prefix, prefix, sizeof(struct in6_addr));
				/* allocate memory for BCE */
				bce = dmm_cache_alloc(BCE_TEMP);
				if (bce) {				
					/* Fill BCE with MN's parameters */
					mar_create_binding_entry(info, bce);
					/* Send PBU to CMD for registration */
					mar_start_registration(bce);
					dmm_cache_add(bce);
					dbg("BCE registered\n");
				} else {
					dbg("Problems creating BCE\n");
					break;
				}
			} else {
				dbg("AAA failed\n");
			}
		} else {
			switch (bce->type) {
				case BCE_TEMP:
					dbg("BCE already existing but not finalized -> Request Rejected\n");
					dmm_cache_release(bce);
				break;
				case BCE_DMM:
					dbg("Router solicitation received for existing MN:\n");
					int update = mar_update_binding_entry(bce, info);
					if (update == 1) mar_start_registration(bce);
					else {
						mar_force_update_registration(bce, info);
					}
					dmm_cache_release(bce);
					break;
				default:
					dbg("No action for this event (%d) at current state (%d) !\n", info->msg_event, bce->type);
					dmm_cache_release(bce);
				}
		}
	break;
		//--------------------------------------
	case hasPBA:
		if (!bce) {
			dbg("PBA received for not registered MN -> discarded\n");
			break;
		} else {
			switch (bce->type) {
			case BCE_TEMP:
				if (is_pba_is_response_to_last_pbu_sent(info, bce)) {
					dbg("Handling PBA. Moving from BCE_TEMP to BCE_DMM\n");
					
					del_task(&bce->tqe);    //Delete timer retransmission PBU (if any)
					bce->PBA_flags = info->PBA_flags;
					if (info->lifetime.tv_sec > 30) {
						bce->lifetime.tv_sec = info->lifetime.tv_sec - 8;
						dbg("Set BCE lifetime to PBA lifetime (%d seconds) - 8 second = %d seconds\n", info->lifetime.tv_sec, bce->lifetime.tv_sec);
					} else if (info->lifetime.tv_sec > 5) {
						bce->lifetime.tv_sec = info->lifetime.tv_sec - 3;
						dbg("Set BCE lifetime to PBA lifetime (%d seconds) - 3 second = %d seconds\n", info->lifetime.tv_sec, bce->lifetime.tv_sec);
					} else if (info->lifetime.tv_sec > 1) {
							bce->lifetime.tv_sec = info->lifetime.tv_sec - 1;
							dbg("Set BCE lifetime to PBA lifetime (%d seconds) - 1 second = %d seconds\n", info->lifetime.tv_sec, bce->lifetime.tv_sec);
					} else {
						bce->lifetime.tv_sec = info->lifetime.tv_sec;
						dbg("Set BCE lifetime to PBA lifetime (%d seconds) =  %d seconds\n", info->lifetime.tv_sec, bce->lifetime.tv_sec);
					}
					if (info->mn_p_mar_addr) {
						mar_list_clean(bce->mar_list);
						bce->mar_list = info->mn_p_mar_addr;
					}
					mar_end_registration(bce, info->iif);
				}
				dmm_cache_release(bce);
			break;
		//--------------------------------------
			case BCE_DMM:
				if (is_pba_is_response_to_last_pbu_sent(info, bce)) {
					del_task(&bce->tqe);    //Delete timer retransmission PBU (if any)
					bce->PBA_flags = info->PBA_flags;
					bce->lifetime.tv_nsec = 0;
					if (info->lifetime.tv_sec > 10) {
						bce->lifetime.tv_sec = info->lifetime.tv_sec - 8;
						dbg("Set BCE lifetime to PBA lifetime (%d seconds) - 8 second = %d seconds\n", info->lifetime.tv_sec, bce->lifetime.tv_sec);
					} else if (info->lifetime.tv_sec > 5) {
						bce->lifetime.tv_sec = info->lifetime.tv_sec - 3;
						dbg("Set BCE lifetime to PBA lifetime (%d seconds) - 3 second = %d seconds\n", info->lifetime.tv_sec, bce->lifetime.tv_sec);
					} else if (info->lifetime.tv_sec > 1) {
						bce->lifetime.tv_sec = info->lifetime.tv_sec - 1;
						dbg("Set BCE lifetime to PBA lifetime (%d seconds) - 1 second = %d seconds\n", info->lifetime.tv_sec, bce->lifetime.tv_sec);
					} else {
						bce->lifetime.tv_sec = info->lifetime.tv_sec;
						dbg("Set BCE lifetime to PBA lifetime (%d seconds) =  %d seconds\n", info->lifetime.tv_sec, bce->lifetime.tv_sec);
					}
					mar_end_registration_no_new_tunnel(bce, info->iif);
				}
				dmm_cache_release(bce);
			break;
			default:
				dbg("No action for this event (%d) at current state (%d) !\n", info->msg_event, bce->type);
				dmm_cache_release(bce);
			}
		}
	break;
	case hasNA:
		//Reset counter, Delete task for entry deletion  & Add a new task for NS expiry.
		if (!bce) {
			dbg("Received NA for a not registered MN -> reject\n");
			break;
		} else if (bce->type == BCE_DMM) {
			if (bce->n_rets_counter == conf.MaxMessageRetransmissions)
				dbg("Received NA for not expired BCE");
			else {
				bce->n_rets_counter = conf.MaxMessageRetransmissions;    //Reset the Retransmissions Counter.
				dbg("Reset the Reachability Counter = %d for %x:%x:%x:%x:%x:%x:%x:%x\n", bce->n_rets_counter, NIP6ADDR(&info->mn_iid));
				del_task(&bce->tqe);
				mar_force_update_registration(bce, info->iif);
			}
			dmm_cache_release(bce);
		} else {
			dbg("Cannot accept NA for not registered MN\n");
			dmm_cache_release(bce);
		}
	break;
	case hasPBU:
		if (!bce) {
			dbg("Received PBU for a not registered MN -> reject\n");
			break;
		} else if (bce->type == BCE_DMM) {
			/* 
			Install routes and tunnel for the MN
			Send a PBA to the CMD with the P-MAR option
			*/
			if (!IN6_ARE_ADDR_EQUAL(&conf.CmdAddress, &info->src)){
				dbg("Received PBU from a non-CMD node -> rejected\n");
				break;
			} else {
				if (info->lifetime.tv_sec > 0) {
					if (!IN6_IS_ADDR_UNSPECIFIED(&info->mn_serv_mar_addr)) {
						dbg("Stopping BCE timer, no longer needed\n");
						bce->mn_serv_mar_addr = info->mn_serv_mar_addr;
						bce->timestamp.first    = info->timestamp.first;
						bce->timestamp.second   = info->timestamp.second;
						mar_end_registration_dmm(bce, info->iif);
					} else
						dbg("ERROR: No Serving MAR found\n");
				} else if (info->lifetime.tv_sec == 0 && info->lifetime.tv_nsec == 0) {
					bce->seqno_in = info->seqno;
					mar_dereg_dmm(bce);
					dmm_cache_delete(bce);
				}
			}
			dmm_cache_release(bce);
		} else	{
			dbg("Cannot accept PBU for not registered MN\n");
			dmm_cache_release(bce);
		}
	break;
	default:
		dbg("No action for this event (%d) at current state !\n", info->msg_event);
	}
	mutex_return_code = pthread_rwlock_unlock(&fsm_lock);
	if (mutex_return_code != 0) {
		dbg("pthread_rwlock_unlock(&fsm_lock) %s\n", strerror(mutex_return_code));
	}
	dbg("exiting FSM - Waiting for new messages ...\n\n\n");
	return;
}
Exemple #11
0
main (int argc, char *argv[])
#endif
{
	XEvent ev;
	fd_set fd;
	int xfd;

	dd = XOpenDisplay (NULL);
	if (!dd)
		return 0;
	scr_screen = DefaultScreen (dd);
	scr_depth = DefaultDepth (dd, scr_screen);
	scr_height = DisplayHeight (dd, scr_screen);
	scr_width = DisplayWidth (dd, scr_screen);
	root_win = RootWindow (dd, scr_screen);

	/* helps us catch windows closing/opening */
	XSelectInput (dd, root_win, PropertyChangeMask);

	XSetErrorHandler ((XErrorHandler) handle_error);

	XInternAtoms (dd, atom_names, ATOM_COUNT, False, atoms);

	gui_init ();
	bzero (&tb, sizeof (struct taskbar));
	tb.win = gui_create_taskbar ();
	xfd = ConnectionNumber (dd);
	gui_sync ();

	while (1)
	{
		FD_ZERO (&fd);
		FD_SET (xfd, &fd);
		select (xfd + 1, &fd, 0, 0, 0);

		while (XPending (dd))
		{
			XNextEvent (dd, &ev);
			switch (ev.type)
			{
			case ButtonPress:
				handle_press (ev.xbutton.x, ev.xbutton.y, ev.xbutton.button);
				break;
			case DestroyNotify:
				del_task (ev.xdestroywindow.window);
				/* fall through */
			case Expose:
				gui_draw_taskbar ();
				break;
			case PropertyNotify:
				handle_propertynotify (ev.xproperty.window, ev.xproperty.atom);
				break;
			case FocusIn:
				handle_focusin (ev.xfocus.window);
				break;
			/*default:
				   printf ("unknown evt type: %d\n", ev.type);*/
			}
		}
	}

	/*XCloseDisplay (dd);

   return 0;*/
}