[BACK]Return to svc_fdset.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / rpc

File: [cvs.NetBSD.org] / src / lib / libc / rpc / svc_fdset.c (download)

Revision 1.1, Tue Mar 5 19:55:23 2013 UTC (11 years, 1 month ago) by christos
Branch: MAIN
CVS Tags: yamt-pagecache-base9, tls-maxphys-base, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, agc-symver-base, agc-symver
Branch point for: yamt-pagecache, tls-maxphys

make this usable from RUMP

/*	$NetBSD: svc_fdset.c,v 1.1 2013/03/05 19:55:23 christos Exp $	*/

#include <sys/cdefs.h>
__RCSID("$NetBSD: svc_fdset.c,v 1.1 2013/03/05 19:55:23 christos Exp $");

#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>

#include "svc_fdset.h"

static pthread_key_t fdsetkey;
static pthread_key_t fdmaxkey;
static fd_set thefdset;
static int thefdmax;

void
init_fdsets(void)
{

	pthread_key_create(&fdsetkey, NULL);
	pthread_key_create(&fdmaxkey, NULL);
}

void
alloc_fdset(void)
{
	fd_set *fdsetti;
	int *fdmax;

	fdsetti = malloc(sizeof(*fdsetti));
	memset(fdsetti, 0, sizeof(*fdsetti));
	pthread_setspecific(fdsetkey, fdsetti);

	fdmax = malloc(sizeof(*fdmax));
	memset(fdmax, 0, sizeof(*fdmax));
	pthread_setspecific(fdmaxkey, fdmax);
}

fd_set *
get_fdset(void)
{
	fd_set *rv;

	rv = pthread_getspecific(fdsetkey);
	if (rv)
		return rv;
	else
		return &thefdset;
}

int *
get_fdsetmax(void)
{
	int *rv;

	rv = pthread_getspecific(fdmaxkey);
	if (rv)
		return rv;
	else
		return &thefdmax;
}