su_port.h 16 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
8
 * This library is free software; you can redistribute it and/or
Pekka Pessi's avatar
Pekka Pessi committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

25 26
#ifndef SU_PORT_H
/** Defined when <su_port.h> has been included. */
Pekka Pessi's avatar
Pekka Pessi committed
27
#define SU_PORT_H
Pekka Pessi's avatar
Pekka Pessi committed
28

Pekka Pessi's avatar
Pekka Pessi committed
29
/**@internal @file su_port.h 
Pekka Pessi's avatar
Pekka Pessi committed
30 31 32 33 34 35 36 37 38 39
 *
 * @brief Internal OS-independent syncronization interface.
 *
 * This looks like the "reactor" pattern.
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 * 
 * @date Created: Fri May 12 14:13:34 2000 ppessi
 */

40 41 42 43
#ifndef SU_MSG_ARG_T
#define SU_MSG_ARG_T union { char anoymous[4]; }
#endif

Pekka Pessi's avatar
Pekka Pessi committed
44
#ifndef SU_WAIT_H
45
#include "sofia-sip/su_wait.h"
Pekka Pessi's avatar
Pekka Pessi committed
46 47 48
#endif

#ifndef SU_MODULE_DEBUG_H
49
#include "su_module_debug.h"
Pekka Pessi's avatar
Pekka Pessi committed
50 51 52
#endif

#ifndef SU_ALLOC_H
53
#include <sofia-sip/su_alloc.h>
Pekka Pessi's avatar
Pekka Pessi committed
54 55
#endif

56 57
#include <assert.h>

58
#define SU_WAIT_MIN    (16)
Pekka Pessi's avatar
Pekka Pessi committed
59

60
SOFIA_BEGIN_DECLS
Pekka Pessi's avatar
Pekka Pessi committed
61

Pekka Pessi's avatar
Pekka Pessi committed
62
/** @internal Message */
Pekka Pessi's avatar
Pekka Pessi committed
63
struct su_msg_s {
64
  size_t         sum_size;
Pekka Pessi's avatar
Pekka Pessi committed
65 66 67 68 69
  su_msg_t      *sum_next;
  su_task_r      sum_to;
  su_task_r      sum_from;
  su_msg_f       sum_func;
  su_msg_f       sum_report;
70
  su_msg_deinit_function *sum_deinit;
Pekka Pessi's avatar
Pekka Pessi committed
71 72 73 74 75
  su_msg_arg_t   sum_data[1];		/* minimum size, may be extended */
};

struct _GSource;

Pekka Pessi's avatar
Pekka Pessi committed
76
/** @internal Root structure */
Pekka Pessi's avatar
Pekka Pessi committed
77 78 79 80 81 82 83 84 85 86 87 88
struct su_root_s {
  int              sur_size;
  su_root_magic_t *sur_magic;
  su_root_deinit_f sur_deinit;
  su_task_r        sur_task;
  su_task_r        sur_parent;
  unsigned         sur_threading : 1;
  unsigned         sur_deiniting : 1;
};

#define SU_ROOT_MAGIC(r) ((r) ? (r)->sur_magic : NULL)

89 90 91 92 93 94
enum su_port_thread_op {
  su_port_thread_op_is_obtained,
  su_port_thread_op_release,
  su_port_thread_op_obtain
};
  
Pekka Pessi's avatar
Pekka Pessi committed
95
/** @internal Virtual function table for port */
96
typedef struct su_port_vtable {
Pekka Pessi's avatar
Pekka Pessi committed
97 98 99 100 101 102 103 104
  unsigned su_vtable_size;
  void (*su_port_lock)(su_port_t *port, char const *who);
  void (*su_port_unlock)(su_port_t *port, char const *who);
  void (*su_port_incref)(su_port_t *port, char const *who);
  void (*su_port_decref)(su_port_t *port, int block, char const *who);
  struct _GSource *(*su_port_gsource)(su_port_t *port);
  int (*su_port_send)(su_port_t *self, su_msg_r rmsg);
  int (*su_port_register)(su_port_t *self,
105 106 107 108 109
			  su_root_t *root, 
			  su_wait_t *wait, 
			  su_wakeup_f callback,
			  su_wakeup_arg_t *arg,
			  int priority);
Pekka Pessi's avatar
Pekka Pessi committed
110 111 112 113 114 115 116 117 118 119 120 121 122
  int (*su_port_unregister)(su_port_t *port,
			    su_root_t *root, 
			    su_wait_t *wait,	
			    su_wakeup_f callback, 
			    su_wakeup_arg_t *arg);
  int (*su_port_deregister)(su_port_t *self, int i);
  int (*su_port_unregister_all)(su_port_t *self,
			     su_root_t *root);
  int (*su_port_eventmask)(su_port_t *self, int index, int socket, int events);
  void (*su_port_run)(su_port_t *self);
  void (*su_port_break)(su_port_t *self);
  su_duration_t (*su_port_step)(su_port_t *self, su_duration_t tout);
  
123 124
  /* Reused slot */
  int (*su_port_thread)(su_port_t *port, enum su_port_thread_op op);
Pekka Pessi's avatar
Pekka Pessi committed
125 126 127 128 129 130 131 132 133
  
  int (*su_port_add_prepoll)(su_port_t *port,
			     su_root_t *root, 
			     su_prepoll_f *, 
			     su_prepoll_magic_t *);
  
  int (*su_port_remove_prepoll)(su_port_t *port,
				su_root_t *root);

134
  su_timer_queue_t *(*su_port_timers)(su_port_t *port);
Pekka Pessi's avatar
Pekka Pessi committed
135 136 137

  int (*su_port_multishot)(su_port_t *port, int multishot);

138 139 140
  /* Extension from >= 1.12.4 */
  int (*su_port_wait_events)(su_port_t *port, su_duration_t timeout);
  int (*su_port_getmsgs)(su_port_t *port);
141 142 143 144 145 146 147 148
  /* Extension from >= 1.12.5 */
  int (*su_port_getmsgs_from)(su_port_t *port, su_port_t *cloneport);
  char const *(*su_port_name)(su_port_t const *port);
  int (*su_port_start_shared)(su_root_t *root,
			      su_clone_r return_clone,
			      su_root_magic_t *magic,
			      su_root_init_f init,
			      su_root_deinit_f deinit);
149 150 151 152
  void (*su_port_wait)(su_clone_r rclone);
  int (*su_port_execute)(su_task_r const task,
			 int (*function)(void *), void *arg,
			 int *return_value);  
Pekka Pessi's avatar
Pekka Pessi committed
153 154
} su_port_vtable_t;

Pekka Pessi's avatar
Pekka Pessi committed
155
SOFIAPUBFUN su_port_t *su_port_create(void)
Pekka Pessi's avatar
Pekka Pessi committed
156 157
     __attribute__((__malloc__));

158
/* Extension from >= 1.12.5 */
159

Pekka Pessi's avatar
Pekka Pessi committed
160 161 162 163
SOFIAPUBFUN void su_msg_delivery_report(su_msg_r msg);
SOFIAPUBFUN su_duration_t su_timer_next_expires(su_timer_t const * t,
						su_time_t now);
SOFIAPUBFUN su_root_t *su_root_create_with_port(su_root_magic_t *magic,
164 165
						su_port_t *port)
  __attribute__((__malloc__));
Pekka Pessi's avatar
Pekka Pessi committed
166

167 168 169 170
/* Extension from >= 1.12.6 */

SOFIAPUBFUN char const *su_port_name(su_port_t const *port);

171 172 173 174 175 176 177 178 179 180 181
/* ---------------------------------------------------------------------- */

/* React to multiple events per one poll() to make sure 
 * that high-priority events can never completely mask other events.
 * Enabled by default on all platforms except WIN32 */
#if !defined(WIN32)
#define SU_ENABLE_MULTISHOT_POLL 1
#else
#define SU_ENABLE_MULTISHOT_POLL 0
#endif

182 183
/* ---------------------------------------------------------------------- */
/* Virtual functions */
Pekka Pessi's avatar
Pekka Pessi committed
184

185 186
typedef struct su_virtual_port_s {
  su_home_t        sup_home[1];
Pekka Pessi's avatar
Pekka Pessi committed
187
  su_port_vtable_t const *sup_vtable;
188 189
} su_virtual_port_t;

190
su_inline
191 192 193 194
su_home_t *su_port_home(su_port_t const *self)
{
  return (su_home_t *)self;
}
Pekka Pessi's avatar
Pekka Pessi committed
195

196
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
197 198
void su_port_lock(su_port_t *self, char const *who)
{
199
  su_virtual_port_t *base = (su_virtual_port_t *)self;
200
  base->sup_vtable->su_port_lock(self, who);
Pekka Pessi's avatar
Pekka Pessi committed
201 202
}

203
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
204 205
void su_port_unlock(su_port_t *self, char const *who)
{
206
  su_virtual_port_t *base = (su_virtual_port_t *)self;
207
  base->sup_vtable->su_port_unlock(self, who);
Pekka Pessi's avatar
Pekka Pessi committed
208 209
}

210
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
211 212
void su_port_incref(su_port_t *self, char const *who)
{
213
  su_virtual_port_t *base = (su_virtual_port_t *)self;
214
  base->sup_vtable->su_port_incref(self, who);
Pekka Pessi's avatar
Pekka Pessi committed
215 216
}

217
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
218 219
void su_port_decref(su_port_t *self, char const *who)
{
220
  su_virtual_port_t *base = (su_virtual_port_t *)self;
221
  base->sup_vtable->su_port_decref(self, 0, who);
Pekka Pessi's avatar
Pekka Pessi committed
222 223
}

224
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
225 226
void su_port_zapref(su_port_t *self, char const *who)
{
227
  su_virtual_port_t *base = (su_virtual_port_t *)self;
228
  base->sup_vtable->su_port_decref(self, 1, who);
Pekka Pessi's avatar
Pekka Pessi committed
229 230
}

231
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
232 233
struct _GSource *su_port_gsource(su_port_t *self)
{
234
  su_virtual_port_t *base = (su_virtual_port_t *)self;
235
  return base->sup_vtable->su_port_gsource(self);
Pekka Pessi's avatar
Pekka Pessi committed
236 237
}

238
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
239 240
int su_port_send(su_port_t *self, su_msg_r rmsg)
{
241
  su_virtual_port_t *base = (su_virtual_port_t *)self;
242
  return base->sup_vtable->su_port_send(self, rmsg);
Pekka Pessi's avatar
Pekka Pessi committed
243 244 245
}


246
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
247 248 249 250 251 252 253
int su_port_register(su_port_t *self,
		     su_root_t *root, 
		     su_wait_t *wait, 
		     su_wakeup_f callback,
		     su_wakeup_arg_t *arg,
		     int priority)
{
254
  su_virtual_port_t *base = (su_virtual_port_t *)self;
255 256
  return base->sup_vtable->
    su_port_register(self, root, wait, callback, arg, priority);
Pekka Pessi's avatar
Pekka Pessi committed
257 258
}

259
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
260 261 262 263 264 265
int su_port_unregister(su_port_t *self,
		       su_root_t *root, 
		       su_wait_t *wait,	
		       su_wakeup_f callback, 
		       su_wakeup_arg_t *arg)
{
266
  su_virtual_port_t *base = (su_virtual_port_t *)self;
267 268
  return base->sup_vtable->
    su_port_unregister(self, root, wait, callback, arg);
Pekka Pessi's avatar
Pekka Pessi committed
269 270
}

271
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
272 273
int su_port_deregister(su_port_t *self, int i)
{
274
  su_virtual_port_t *base = (su_virtual_port_t *)self;
275 276
  return base->sup_vtable->
    su_port_deregister(self, i);
Pekka Pessi's avatar
Pekka Pessi committed
277 278
}

279
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
280 281 282
int su_port_unregister_all(su_port_t *self,
			   su_root_t *root)
{
283
  su_virtual_port_t *base = (su_virtual_port_t *)self;
284 285
  return base->sup_vtable->
    su_port_unregister_all(self, root);
Pekka Pessi's avatar
Pekka Pessi committed
286 287
}

288
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
289 290
int su_port_eventmask(su_port_t *self, int index, int socket, int events)
{
291
  su_virtual_port_t *base = (su_virtual_port_t *)self;
292 293 294 295 296 297 298 299 300 301 302 303
  return base->sup_vtable->
    su_port_eventmask(self, index, socket, events);
}

su_inline
int su_port_wait_events(su_port_t *self, su_duration_t timeout)
{
  su_virtual_port_t *base = (su_virtual_port_t *)self;
  if (base->sup_vtable->su_port_wait_events == NULL)
    return errno = ENOSYS, -1;
  return base->sup_vtable->
    su_port_wait_events(self, timeout);
Pekka Pessi's avatar
Pekka Pessi committed
304 305
}

306
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
307 308
void su_port_run(su_port_t *self)
{
309
  su_virtual_port_t *base = (su_virtual_port_t *)self;
310
  base->sup_vtable->su_port_run(self);
Pekka Pessi's avatar
Pekka Pessi committed
311 312
}

313
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
314 315
void su_port_break(su_port_t *self)
{
316
  su_virtual_port_t *base = (su_virtual_port_t *)self;
317
  base->sup_vtable->su_port_break(self);
Pekka Pessi's avatar
Pekka Pessi committed
318 319
}

320
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
321 322
su_duration_t su_port_step(su_port_t *self, su_duration_t tout)
{
323
  su_virtual_port_t *base = (su_virtual_port_t *)self;
324
  return base->sup_vtable->su_port_step(self, tout);
Pekka Pessi's avatar
Pekka Pessi committed
325 326
}

327

328
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
329 330
int su_port_own_thread(su_port_t const *self)
{
331
  su_virtual_port_t const *base = (su_virtual_port_t *)self;
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
  return base->sup_vtable->
    su_port_thread((su_port_t *)self, su_port_thread_op_is_obtained) == 2;
}

su_inline int su_port_has_thread(su_port_t *self)
{
  su_virtual_port_t *base = (su_virtual_port_t *)self;
  return base->sup_vtable->su_port_thread(self, su_port_thread_op_is_obtained);
}

su_inline int su_port_release(su_port_t *self)
{
  su_virtual_port_t *base = (su_virtual_port_t *)self;
  return base->sup_vtable->su_port_thread(self, su_port_thread_op_release);
}

su_inline int su_port_obtain(su_port_t *self)
{
  su_virtual_port_t *base = (su_virtual_port_t *)self;
  return base->sup_vtable->su_port_thread(self, su_port_thread_op_obtain);
Pekka Pessi's avatar
Pekka Pessi committed
352 353
}

354
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
355 356 357 358 359
int su_port_add_prepoll(su_port_t *self,
			su_root_t *root, 
			su_prepoll_f *prepoll, 
			su_prepoll_magic_t *magic)
{
360
  su_virtual_port_t *base = (su_virtual_port_t *)self;
361
  return base->sup_vtable->su_port_add_prepoll(self, root, prepoll, magic);
Pekka Pessi's avatar
Pekka Pessi committed
362 363
}

364
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
365 366 367
int su_port_remove_prepoll(su_port_t *self,
			   su_root_t *root)
{
368
  su_virtual_port_t *base = (su_virtual_port_t *)self;
369
  return base->sup_vtable->su_port_remove_prepoll(self, root);
Pekka Pessi's avatar
Pekka Pessi committed
370 371
}

372
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
373 374
su_timer_t **su_port_timers(su_port_t *self)
{
375
  su_virtual_port_t *base = (su_virtual_port_t *)self;
376
  return base->sup_vtable->su_port_timers(self);
Pekka Pessi's avatar
Pekka Pessi committed
377 378
}

379
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
380 381
int su_port_multishot(su_port_t *self, int multishot)
{
382
  su_virtual_port_t *base = (su_virtual_port_t *)self;
383
  return base->sup_vtable->su_port_multishot(self, multishot);
Pekka Pessi's avatar
Pekka Pessi committed
384 385
}

386
su_inline
387 388 389 390 391 392
int su_port_getmsgs(su_port_t *self)
{
  su_virtual_port_t *base = (su_virtual_port_t *)self;
  return base->sup_vtable->su_port_getmsgs(self);
}

393
su_inline
394 395 396 397 398 399
int su_port_getmsgs_from(su_port_t *self, su_port_t *cloneport)
{
  su_virtual_port_t *base = (su_virtual_port_t *)self;
  return base->sup_vtable->su_port_getmsgs_from(self, cloneport);
}

400 401 402 403 404 405
SOFIAPUBFUN void su_port_wait(su_clone_r rclone);

SOFIAPUBFUN int su_port_execute(su_task_r const task,
				int (*function)(void *), void *arg,
				int *return_value);

406 407
/* ---------------------------------------------------------------------- */

Pekka Pessi's avatar
Pekka Pessi committed
408
/**@internal Base port object.
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
 *
 * Port is a per-thread reactor. Multiple root objects executed by a single
 * thread share the su_port_t object.
 */
typedef struct su_base_port_s {
  su_home_t        sup_home[1];
  su_port_vtable_t const *sup_vtable;

  /* Implementation may vary stuff below, too. */
  
  /* Pre-poll callback */
  su_prepoll_f    *sup_prepoll; 
  su_prepoll_magic_t *sup_pp_magic;
  su_root_t       *sup_pp_root;

  /* Message list - this is protected by su_port_lock()/su_port_unlock() */
  su_msg_t        *sup_head, **sup_tail;

  /* Timer list */
428
  su_timer_queue_t sup_timers;
429 430 431 432 433 434 435 436 437 438 439 440

  unsigned         sup_running;	  /**< In su_root_run() loop? */
} su_base_port_t;

/* Base methods */

SOFIAPUBFUN int su_base_port_init(su_port_t *, su_port_vtable_t const *);
SOFIAPUBFUN void su_base_port_deinit(su_port_t *self);

SOFIAPUBFUN void su_base_port_lock(su_port_t *self, char const *who);
SOFIAPUBFUN void su_base_port_unlock(su_port_t *self, char const *who);

441 442
SOFIAPUBFUN int su_base_port_thread(su_port_t const *self,
				    enum su_port_thread_op op);
443 444 445 446 447 448 449 450 451 452 453

SOFIAPUBFUN void su_base_port_incref(su_port_t *self, char const *who);
SOFIAPUBFUN int su_base_port_decref(su_port_t *self,
				    int blocking,
				    char const *who);

SOFIAPUBFUN struct _GSource *su_base_port_gsource(su_port_t *self);

SOFIAPUBFUN su_socket_t su_base_port_mbox(su_port_t *self);
SOFIAPUBFUN int su_base_port_send(su_port_t *self, su_msg_r rmsg);
SOFIAPUBFUN int su_base_port_getmsgs(su_port_t *self);
454 455
SOFIAPUBFUN int su_base_port_getmsgs_from(su_port_t *self,
					   su_port_t *from);
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471

SOFIAPUBFUN void su_base_port_run(su_port_t *self);
SOFIAPUBFUN void su_base_port_break(su_port_t *self);
SOFIAPUBFUN su_duration_t su_base_port_step(su_port_t *self,
					    su_duration_t tout);

SOFIAPUBFUN int su_base_port_add_prepoll(su_port_t *self,
					 su_root_t *root, 
					 su_prepoll_f *, 
					 su_prepoll_magic_t *);

SOFIAPUBFUN int su_base_port_remove_prepoll(su_port_t *self, su_root_t *root);

SOFIAPUBFUN su_timer_t **su_base_port_timers(su_port_t *self);

SOFIAPUBFUN int su_base_port_multishot(su_port_t *self, int multishot);
472

473 474 475 476 477
SOFIAPUBFUN int su_base_port_start_shared(su_root_t *parent,
					  su_clone_r return_clone,
					  su_root_magic_t *magic,
					  su_root_init_f init,
					  su_root_deinit_f deinit);
478 479
SOFIAPUBFUN void su_base_port_wait(su_clone_r rclone);

480 481 482 483 484 485
/* ---------------------------------------------------------------------- */

#if SU_HAVE_PTHREADS

#include <pthread.h>

Pekka Pessi's avatar
Pekka Pessi committed
486
/** @internal Pthread port object */ 
487 488
typedef struct su_pthread_port_s {
  su_base_port_t   sup_base[1];
489 490
  struct su_pthread_port_waiting_parent 
                  *sup_waiting_parent;
491
  pthread_t        sup_tid;
492 493
  pthread_mutex_t  sup_obtained[1];

494
#if 0
495
  pthread_mutex_t  sup_runlock[1];
496 497 498 499
  pthread_cond_t   sup_resume[1];
  short            sup_paused;	/**< True if thread is paused */
#endif
  short            sup_thread;	/**< True if thread is active */
500 501 502 503 504 505 506 507 508 509
} su_pthread_port_t;

/* Pthread methods */

SOFIAPUBFUN int su_pthread_port_init(su_port_t *, su_port_vtable_t const *);
SOFIAPUBFUN void su_pthread_port_deinit(su_port_t *self);

SOFIAPUBFUN void su_pthread_port_lock(su_port_t *self, char const *who);
SOFIAPUBFUN void su_pthread_port_unlock(su_port_t *self, char const *who);

510 511
SOFIAPUBFUN int su_pthread_port_thread(su_port_t *self,
				       enum su_port_thread_op op);
512

513
#if 0				/* not yet  */
514 515
SOFIAPUBFUN int su_pthread_port_send(su_port_t *self, su_msg_r rmsg);

516
SOFIAPUBFUN su_port_t *su_pthread_port_create(void);
517 518 519 520 521 522 523 524 525 526 527 528 529
SOFIAPUBFUN su_port_t *su_pthread_port_start(su_root_t *parent,
					     su_clone_r return_clone,
					     su_root_magic_t *magic,
					     su_root_init_f init,
					     su_root_deinit_f deinit);
#endif

SOFIAPUBFUN int su_pthreaded_port_start(su_port_create_f *create,
					su_root_t *parent,
					su_clone_r return_clone,
					su_root_magic_t *magic,
					su_root_init_f init,
					su_root_deinit_f deinit);
530 531 532 533 534 535

SOFIAPUBFUN void su_pthread_port_wait(su_clone_r rclone);
SOFIAPUBFUN int su_pthread_port_execute(su_task_r const task,
					int (*function)(void *), void *arg,
					int *return_value);

536

537 538 539 540 541
#if 0
SOFIAPUBFUN int su_pthread_port_pause(su_port_t *self);
SOFIAPUBFUN int su_pthread_port_resume(su_port_t *self);
#endif

542 543 544 545 546 547 548 549
#else

typedef su_base_port_t su_pthread_port_t;

#define su_pthread_port_init   su_base_port_init
#define su_pthread_port_deinit su_base_port_deinit
#define su_pthread_port_lock   su_base_port_lock
#define su_pthread_port_unlock su_base_port_unlock
550
#define su_pthread_port_thread su_base_port_thread
551 552
#define su_pthread_port_wait   su_base_port_wait
#define su_pthread_port_execute  su_base_port_execute
Pekka Pessi's avatar
Pekka Pessi committed
553 554 555

#endif

556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
/* ====================================================================== */
/* Mailbox port using sockets */

#define SU_MBOX_SIZE 2

typedef struct su_socket_port_s {
  su_pthread_port_t sup_base[1];
  int               sup_mbox_index;
  su_socket_t       sup_mbox[SU_MBOX_SIZE];
} su_socket_port_t;

SOFIAPUBFUN int su_socket_port_init(su_socket_port_t *, 
				    su_port_vtable_t const *);
SOFIAPUBFUN void su_socket_port_deinit(su_socket_port_t *self);
SOFIAPUBFUN int su_socket_port_send(su_port_t *self, su_msg_r rmsg);

572 573
SOFIA_END_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
574
#endif /* SU_PORT_H */