示例#1
0
文件: builtin.c 项目: ledbettj/itsh
void builtin_foreach(int(*on_each)(builtin_t* b)) {
  for(int i = 0; builtins[i].command != NULL; ++i) {
    if (on_each(&builtins[i])) {
      break;
    }
  }
}
示例#2
0
void
mono_w32handle_foreach (gboolean (*on_each)(gpointer handle, gpointer data, gpointer user_data), gpointer user_data)
{
	guint32 i, k;

	mono_os_mutex_lock (&scan_mutex);

	for (i = SLOT_INDEX (0); i < private_handles_slots_count; i++) {
		if (!private_handles [i])
			continue;
		for (k = SLOT_OFFSET (0); k < HANDLE_PER_SLOT; k++) {
			MonoW32HandleBase *handle_data = NULL;
			gpointer handle;
			gboolean destroy, finished;

			handle_data = &private_handles [i][k];
			if (handle_data->type == MONO_W32HANDLE_UNUSED)
				continue;

			handle = GUINT_TO_POINTER (i * HANDLE_PER_SLOT + k);

			if (!mono_w32handle_ref_core (handle, handle_data)) {
				/* we are racing with mono_w32handle_unref:
				 *  the handle ref has been decremented, but it
				 *  hasn't yet been destroyed. */
				continue;
			}

			finished = on_each (handle, handle_data->specific, user_data);

			/* we do not want to have to destroy the handle here,
			 * as it would means the ref/unref are unbalanced */
			destroy = mono_w32handle_unref_core (handle, handle_data, 2);
			g_assert (!destroy);

			if (finished)
				goto done;
		}
	}

done:
	mono_os_mutex_unlock (&scan_mutex);
}