#include <ctype.h>
-/* For graphviz, only unthreaded */
-#ifdef WIN32_STATIC
-#undef vt_threaded 0
-#else
-#define vt_threaded 0
-#endif
-
#include "sfhdr.h"
#define QL 01
AM_CPPFLAGS = -I$(top_srcdir)/lib/ast
-AM_CFLAGS = -Dvt_threaded=0
-
noinst_HEADERS = sfhdr.h sfio.h sfio_t.h vthread.h
noinst_LTLIBRARIES = libsfio_C.la
AM_CPPFLAGS = -I$(top_srcdir)/lib/sfio
-AM_CFLAGS = -Dvt_threaded=0
-
noinst_LTLIBRARIES = libsfiof_C.la
libsfiof_C_la_SOURCES = _sfclrerr.c _sfdlen.c _sfeof.c _sferror.c \
/* accessible to application code for a few fast macro functions */
ssize_t _Sfi = -1;
-#if vt_threaded
-static Vtmutex_t _Sfmtxin, _Sfmtxout, _Sfmtxerr;
-#define SFMTXIN (&_Sfmtxin)
-#define SFMTXOUT (&_Sfmtxout)
-#define SFMTXERR (&_Sfmtxerr)
-#else
#define SFMTXIN (0)
#define SFMTXOUT (0)
#define SFMTXERR (0)
-#endif
Sfio_t _Sfstdin = SFNEW(NIL(char *), -1, 0,
(SF_READ | SF_STATIC | SF_MTSAFE), NIL(Sfdisc_t *),
#include "FEATURE/sfio"
#include "sfio_t.h"
-/* note that the macro vt_threaded has effect on vthread.h */
#include <vthread.h>
#if defined(__mips) && __mips == 2 && !defined(_NO_LARGEFILE64_SOURCE)
#include <errno.h>
#include <ctype.h>
-#if vt_threaded
-
-/* initialization */
-#define SFONCE() (_Sfdone ? 0 : vtonce(_Sfonce,_Sfoncef))
-
-/* to lock/unlock a stream on entering and returning from some function */
-#define SFMTXLOCK(f) (((f)->flags&SF_MTSAFE) ? sfmutex(f,SFMTX_LOCK) : 0)
-#define SFMTXUNLOCK(f) (((f)->flags&SF_MTSAFE) ? sfmutex(f,SFMTX_UNLOCK) : 0)
-#define SFMTXSTART(f,v) { if(!f || SFMTXLOCK(f) != 0) return(v); }
-#define SFMTXRETURN(f,v) { SFMTXUNLOCK(f); return(v); }
-
-/* start and end critical region for a pool */
-#define POOLMTXLOCK(p) ( vtmtxlock(&(p)->mutex) )
-#define POOLMTXUNLOCK(p) ( vtmtxunlock(&(p)->mutex) )
-#define POOLMTXSTART(p) { POOLMTXLOCK(p); }
-#define POOLMTXRETURN(p,v) { POOLMTXUNLOCK(p); return(v); }
-
-#else /*!vt_threaded */
-
#undef SF_MTSAFE /* no need to worry about thread-safety */
#define SF_MTSAFE 0
#define POOLMTXSTART(p)
#define POOLMTXRETURN(p,v) { return(v); }
-#endif /*vt_threaded */
-
-
/* functions for polling readiness of streams */
#if _lib_select
#undef _lib_poll
/* the main locking/unlocking interface */
int sfmutex(Sfio_t * f, int type)
{
-#if !vt_threaded
return 0;
-#else
-
- SFONCE();
-
- if (!f)
- return -1;
-
- if (!f->mutex) {
- if (f->bits & SF_PRIVATE)
- return 0;
-
- vtmtxlock(_Sfmutex);
- f->mutex = vtmtxopen(NIL(Vtmutex_t *), VT_INIT);
- vtmtxunlock(_Sfmutex);
- if (!f->mutex)
- return -1;
- }
-
- if (type == SFMTX_LOCK)
- return vtmtxlock(f->mutex);
- else if (type == SFMTX_TRYLOCK)
- return vtmtxtrylock(f->mutex);
- else if (type == SFMTX_UNLOCK)
- return vtmtxunlock(f->mutex);
- else if (type == SFMTX_CLRLOCK)
- return vtmtxclrlock(f->mutex);
- else
- return -1;
-#endif /*vt_threaded */
}
}
}
- /* create a mutex */
-#if vt_threaded
- if (!f->mutex)
- f->mutex = vtmtxopen(NIL(Vtmutex_t *), VT_INIT);
-#endif
-
/* stream type */
f->mode = (flags & SF_READ) ? SF_READ : SF_WRITE;
f->flags = (flags & SF_FLAGS) | (sflags & (SF_MALLOC | SF_STATIC));
#endif /*_lib_poll*/
#if _lib_select
if (r == -2) {
-#if _hpux_threads && vt_threaded
-#define fd_set int
-#endif
fd_set rd;
struct timeval tmb, *tmp;
FD_ZERO(&rd);
#define VTHREAD_VERSION 20001201L
/* Header for the Vthread library.
-** Note that the macro vt_threaded may be defined
-** outside of vthread.h to suppress threading.
**
** Written by Kiem-Phong Vo
*/
# include <sys/types.h>
#endif // HAVE_SYS_TYPES_H
-#undef vt_threaded
-
-#ifndef vt_threaded
-#define vt_threaded 0
-#endif
-
/* common attributes for various structures */
#define VT_RUNNING 000000001 /* thread is running */
#define VT_SUSPENDED 000000002 /* thread is suspended */
extern int vtmtxerror(Vtmutex_t *);
extern int vtonceerror(Vtonce_t *);
-#if defined(vt_threaded) && vt_threaded
-/* mutex structure */
- struct _vtmutex_s {
- _vtmtx_t lock;
- int count;
- _vtid_t owner;
- int state;
- int error;
- };
-
-/* structure for states of thread */
- struct _vthread_s {
- _vtself_t self; /* self-handle */
- _vtid_t id; /* thread id */
- _vtattr_t attrs; /* attributes */
- size_t stack; /* stack size */
- int state; /* execution state */
- int error; /* error status */
- void *exit; /* exit value */
- };
-
-/* structure for exactly once execution */
- struct _vtonce_s {
- int done;
- _vtonce_t once;
- int error;
- };
-
-#if defined(_WIN32)
-#define VTONCE_INITDATA {0, 0}
-#else
-#define VTONCE_INITDATA {0, PTHREAD_ONCE_INIT }
-#endif
-
-#define vtstatus(vt) ((vt)->exit)
-#define vterror(vt) ((vt)->error)
-#define vtmtxerror(mtx) ((mtx)->error)
-#define vtonceerror(once) ((once)->error)
-
-#endif /*vt_threaded */
-
/* fake structures and functions */
-#if defined(vt_threaded) && !vt_threaded
struct _vtmutex_s {
int error;
};
#define vtmtxerror(mtx) (0)
#define vtonceerror(once) (0)
-#endif /*!vt_threaded */
-
#endif /*_VTHREAD_H*/
#ifdef __cplusplus