ipc_target.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 1994 The University of Utah and
  3. * the Computer Systems Laboratory (CSL). All rights reserved.
  4. *
  5. * Permission to use, copy, modify and distribute this software and its
  6. * documentation is hereby granted, provided that both the copyright
  7. * notice and this permission notice appear in all copies of the
  8. * software, derivative works or modified versions, and any portions
  9. * thereof, and that both notices appear in supporting documentation.
  10. *
  11. * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
  12. * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
  13. * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  14. *
  15. * CSL requests users of this software to return to csl-dist@cs.utah.edu any
  16. * improvements that they make and grant CSL redistribution rights.
  17. */
  18. /*
  19. * File: ipc_target.c
  20. *
  21. * Implementation for common part of IPC ports and port sets
  22. * representing a target of messages and migrating RPCs.
  23. */
  24. #include <glue/gnulinux.h>
  25. #include <kern/sched_prim.h>
  26. #include "ipc_target.h"
  27. #pragma GCC diagnostic error "-Wundef"
  28. void
  29. ipc_target_init(struct ipc_target *ipt, mach_port_t name)
  30. {
  31. ipt->ipt_name = name;
  32. ipc_mqueue_init(&ipt->ipt_messages);
  33. #ifdef MIGRATING_THREADS
  34. ipt->ipt_type = IPT_TYPE_MESSAGE_RPC;
  35. ipt->ipt_acts = 0;
  36. ipc_target_machine_init(ipt);
  37. #endif
  38. }
  39. void
  40. ipc_target_terminate(struct ipc_target *ipt)
  41. {
  42. }
  43. #ifdef MIGRATING_THREADS
  44. struct Act *
  45. ipc_target_block(struct ipc_target *ipt)
  46. {
  47. struct Act *act;
  48. ipt_lock(ipt);
  49. while ((act = ipt->ipt_acts) == 0) {
  50. /* XXX mp unsafe */
  51. ipt->ipt_waiting = 1;
  52. ipt_unlock(ipt);
  53. thread_wait((int)&ipt->ipt_acts, FALSE);
  54. ipt_lock(ipt);
  55. }
  56. ipt->ipt_acts = act->ipt_next;
  57. ipt_unlock(ipt);
  58. return act;
  59. }
  60. void
  61. ipc_target_wakeup(struct ipc_target *ipt)
  62. {
  63. ipt_lock(ipt);
  64. if (ipt->ipt_waiting) {
  65. thread_wakeup((int)&ipt->ipt_acts);
  66. ipt->ipt_waiting = 0;
  67. }
  68. ipt_unlock(ipt);
  69. }
  70. #endif /* MIGRATING_THREADS */