fusion_internal.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. (c) Copyright 2001-2009 The world wide DirectFB Open Source Community (directfb.org)
  3. (c) Copyright 2000-2004 Convergence (integrated media) GmbH
  4. All rights reserved.
  5. Written by Denis Oliver Kropp <dok@directfb.org>,
  6. Andreas Hundt <andi@fischlustig.de>,
  7. Sven Neumann <neo@directfb.org>,
  8. Ville Syrjälä <syrjala@sci.fi> and
  9. Claudio Ciccani <klan@users.sf.net>.
  10. This library is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU Lesser General Public
  12. License as published by the Free Software Foundation; either
  13. version 2 of the License, or (at your option) any later version.
  14. This library is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. Lesser General Public License for more details.
  18. You should have received a copy of the GNU Lesser General Public
  19. License along with this library; if not, write to the
  20. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. Boston, MA 02111-1307, USA.
  22. */
  23. #ifndef __FUSION__FUSION_INTERNAL_H__
  24. #define __FUSION__FUSION_INTERNAL_H__
  25. #include <sys/types.h>
  26. #include <sys/param.h>
  27. #include <stdarg.h>
  28. #include <string.h>
  29. #include <direct/list.h>
  30. #include <fusion/build.h>
  31. #include <fusion/fusion.h>
  32. #include <fusion/lock.h>
  33. #include <fusion/ref.h>
  34. #include <fusion/shm/shm_internal.h>
  35. #if FUSION_BUILD_MULTI
  36. # if FUSION_BUILD_KERNEL
  37. # include <sys/ioctl.h>
  38. # include <linux/fusion.h>
  39. # else
  40. # include <fusion/protocol.h>
  41. # endif
  42. #endif
  43. #define FUSION_MAX_WORLDS 8
  44. /***************************************
  45. * Fusion internal type declarations *
  46. ***************************************/
  47. struct __Fusion_FusionWorldShared {
  48. int magic;
  49. int refs; /* Increased by the master on fork(). */
  50. int world_index;
  51. int world_abi;
  52. struct timeval start_time;
  53. DirectLink *arenas;
  54. FusionSkirmish arenas_lock;
  55. FusionSkirmish reactor_globals;
  56. FusionSHMShared shm;
  57. FusionSHMPoolShared *main_pool;
  58. DirectLink *fusionees; /* Connected fusionees. */
  59. FusionSkirmish fusionees_lock;
  60. unsigned int call_ids; /* Generates call ids. */
  61. unsigned int lock_ids; /* Generates locks ids. */
  62. unsigned int ref_ids; /* Generates refs ids. */
  63. unsigned int reactor_ids; /* Generates reactors ids. */
  64. unsigned int pool_ids; /* Generates pools ids. */
  65. void *pool_base; /* SHM pool allocation base. */
  66. void *pool_max; /* SHM pool max address. */
  67. };
  68. struct __Fusion_FusionWorld {
  69. int magic;
  70. int refs;
  71. FusionWorldShared *shared;
  72. int fusion_fd;
  73. FusionID fusion_id;
  74. DirectThread *dispatch_loop;
  75. bool dispatch_stop;
  76. /*
  77. * List of reactors with at least one local reaction attached.
  78. */
  79. DirectLink *reactor_nodes;
  80. pthread_mutex_t reactor_nodes_lock;
  81. FusionSHM shm;
  82. FusionForkAction fork_action;
  83. FusionForkCallback fork_callback;
  84. void *fusionee;
  85. FusionLeaveCallback leave_callback;
  86. void *leave_ctx;
  87. };
  88. /*******************************************
  89. * Fusion internal function declarations *
  90. *******************************************/
  91. int _fusion_fd( const FusionWorldShared *shared );
  92. FusionID _fusion_id( const FusionWorldShared *shared );
  93. FusionWorld *_fusion_world( const FusionWorldShared *shared );
  94. /*
  95. * from reactor.c
  96. */
  97. void _fusion_reactor_free_all ( FusionWorld *world );
  98. void _fusion_reactor_process_message( FusionWorld *world,
  99. int reactor_id,
  100. int channel,
  101. const void *msg_data );
  102. #if FUSION_BUILD_MULTI
  103. # if FUSION_BUILD_KERNEL
  104. static __inline__ void
  105. fusion_entry_add_permissions( const FusionWorld *world,
  106. FusionType type,
  107. int entry_id,
  108. FusionID fusion_id,
  109. ... )
  110. {
  111. FusionEntryPermissions permissions;
  112. va_list args;
  113. int arg;
  114. permissions.type = type;
  115. permissions.id = entry_id;
  116. permissions.fusion_id = fusion_id;
  117. permissions.permissions = 0;
  118. va_start( args, fusion_id );
  119. while ((arg = va_arg( args, int )) != 0)
  120. FUSION_ENTRY_PERMISSIONS_ADD( permissions.permissions, arg );
  121. va_end( args );
  122. while (ioctl( world->fusion_fd, FUSION_ENTRY_ADD_PERMISSIONS, &permissions ) < 0) {
  123. if (errno != EINTR) {
  124. D_PERROR( "Fusion: FUSION_ENTRY_ADD_PERMISSIONS( type %d, id %d ) failed!\n", type, entry_id );
  125. break;
  126. }
  127. }
  128. }
  129. # endif
  130. #endif
  131. #if FUSION_BUILD_MULTI
  132. /*
  133. * from call.c
  134. */
  135. void _fusion_call_process( FusionWorld *world,
  136. int call_id,
  137. FusionCallMessage *call );
  138. void _fusion_call_process3( FusionWorld *world,
  139. int call_id,
  140. FusionCallMessage3 *msg,
  141. void *ptr );
  142. #if FUSION_BUILD_KERNEL
  143. /*
  144. * from shm.c
  145. */
  146. void _fusion_shmpool_process( FusionWorld *world,
  147. int pool_id,
  148. FusionSHMPoolMessage *msg );
  149. #else
  150. /*
  151. * form fusion.c
  152. */
  153. void _fusion_add_local( FusionWorld *world,
  154. FusionRef *ref,
  155. int add );
  156. void _fusion_check_locals( FusionWorld *world,
  157. FusionRef *ref );
  158. void _fusion_remove_all_locals( FusionWorld *world,
  159. const FusionRef *ref );
  160. DirectResult _fusion_send_message( int fd,
  161. const void *msg,
  162. size_t msg_size,
  163. struct sockaddr_un *addr );
  164. DirectResult _fusion_recv_message( int fd,
  165. void *msg,
  166. size_t msg_size,
  167. struct sockaddr_un *addr );
  168. /*
  169. * from ref.c
  170. */
  171. DirectResult _fusion_ref_change( FusionRef *ref, int add, bool global );
  172. #endif /* FUSION_BUILD_KERNEL */
  173. #endif /* FUSION_BUILD_MULTI */
  174. #endif