/****************************************************************************
**  SIONLIB     http://www.fz-juelich.de/jsc/sionlib                       **
*****************************************************************************
**  Copyright (c) 2008-2009                                                **
**  Forschungszentrum Juelich, Juelich Supercomputing Centre               **
**                                                                         **
**  See the file COPYRIGHT in the package base directory for details       **
****************************************************************************/
#ifndef SION_SION_FD_H
#define SION_SION_FD_H


#ifdef __cplusplus
extern "C" {
#endif


int _sion_alloc_fd_list();
int _sion_newvcd(void *data, int type);
int _sion_freevcd(int sid);
void *_sion_vcdtovcon(int sid);
int _sion_vcdtype(int sid);


  /* SION_FD INTERNAL */
#define SION_FD_CHUNK 2 
struct _sion_fd {
  int  state;   /* 0: fresh, 1: in use, 2: used before, now free */
  int  type;
  void *data;
};

struct _sion_fddata {
  int size;
  int nfree;
  int last_freed;
  struct _sion_fd *list;
#ifdef SION_PTHREADS
  pthread_mutex_t lock;
#endif
};

typedef struct _sion_fddata sion_fddata;

sion_fddata *_sion_new_fd_list();
void _sion_free_fd_list(sion_fddata *fdd);

int _sion_new_fd(sion_fddata *fdd, void *data, int type, char *text);
int _sion_set_fd(sion_fddata *fdd, int fd, void *data,
		     int type, char *text);
void *_sion_fd2ptr(sion_fddata *fdd, int fd, char *text);
int _sion_fd2type(sion_fddata *fdd, int fd, char *text);
int _sion_ptr2fd(sion_fddata *fdd, void *ptr, char *text);
int _sion_free_fd(sion_fddata *fdd, int fd, char *text);
int _sion_reassign_fd(sion_fddata *fdd, int fd, void *data, int type, char *text);
int _sion_fd_size(sion_fddata *fdd, char *text);


  
#ifdef __cplusplus
}
#endif

#endif
