Deleted Added
sdiff udiff text old ( 176781 ) new ( 176815 )
full compact
1/*
2 * Copyright (c) 2003 Craig Rodrigues <rodrigc@attbi.com>.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 76 unchanged lines hidden (view full) ---

85 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
86 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
87 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
88 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
89 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
90 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
91 * SUCH DAMAGE.
92 *
93 * $FreeBSD: head/lib/libthr/thread/thr_attr.c 176781 2008-03-04 03:03:24Z davidxu $
94 */
95
96#include "namespace.h"
97#include <errno.h>
98#include <pthread.h>
99#include <stdlib.h>
100#include <string.h>
101#include <pthread_np.h>
102#include "un-namespace.h"
103
104#include "thr_private.h"
105
106__weak_reference(_pthread_attr_destroy, pthread_attr_destroy);
107
108int
109_pthread_attr_destroy(pthread_attr_t *attr)

--- 431 unchanged lines hidden (view full) ---

541 else {
542 /* Save the stack size: */
543 (*attr)->stacksize_attr = stacksize;
544 ret = 0;
545 }
546 return(ret);
547}
548
549int
550pthread_attr_setaffinity_np(pthread_attr_t *pattr, size_t cpusetsize,
551 const cpuset_t *cpuset)
552{
553 pthread_attr_t attr;
554 int ret;
555
556 if (pattr == NULL || (attr = (*pattr)) == NULL)
557 ret = EINVAL;
558 else {
559 if (cpusetsize == 0 || cpuset == NULL) {
560 if (attr->cpuset != NULL) {
561 free(attr->cpuset);
562 attr->cpuset = NULL;
563 attr->cpusetsize = 0;
564 }
565 return (0);
566 }
567
568 /*
569 * XXX figure out kernel cpuset size, reject invalid size.
570 */
571 if (cpusetsize != attr->cpusetsize) {
572 void *newset = realloc(attr->cpuset, cpusetsize);
573 if (newset == NULL)
574 return (ENOMEM);
575 attr->cpuset = newset;
576 attr->cpusetsize = cpusetsize;
577 }
578 memcpy(attr->cpuset, cpuset, cpusetsize);
579 ret = 0;
580 }
581 return (ret);
582}
583
584int
585pthread_attr_getaffinity_np(const pthread_attr_t *pattr, size_t cpusetsize,
586 cpuset_t *cpuset)
587{
588 pthread_attr_t attr;
589 int ret = 0;
590
591 if (pattr == NULL || (attr = (*pattr)) == NULL)
592 ret = EINVAL;
593 else if (attr->cpuset != NULL) {
594 memcpy(cpuset, attr->cpuset, MIN(cpusetsize, attr->cpusetsize));
595 if (cpusetsize > attr->cpusetsize)
596 memset(((char *)cpuset) + attr->cpusetsize, 0,
597 cpusetsize - attr->cpusetsize);
598 } else {
599 memset(cpuset, -1, cpusetsize);
600 }
601 return (ret);
602}