• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  *  Copyright (c) 2003, Intel Corporation. All rights reserved.
4  *  Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
5  *  This file is licensed under the GPL license.  For the full content
6  *  of this license, see the COPYING file at the top level of this
7  *  source tree.
8  */
9 
10 #include <sys/time.h>
11 #include <string.h>
12 #include "test.h"
13 
14 #define PROTOCOL                PTHREAD_PRIO_INHERIT
15 
16 static inline
seconds_read(void)17 double seconds_read(void)
18 {
19 	struct timeval tv;
20 	gettimeofday(&tv, 0);
21 	return tv.tv_sec + 1e-6 * tv.tv_usec;
22 }
23 
24 static inline
test_set_priority(pthread_t pid,unsigned policy,unsigned prio)25 int test_set_priority(pthread_t pid, unsigned policy, unsigned prio)
26 {
27 	struct sched_param sched_param;
28 	memset(&sched_param, 0, sizeof(sched_param));
29 	sched_param.sched_priority = prio;
30 	if (pthread_setschedparam(pid, policy, &sched_param) == -1)
31 	{
32 		EPRINTF("UNRESOLVED: Can't set policy to %d and prio to %d",
33 		  	policy, prio);
34   	  	exit(UNRESOLVED);
35   	}
36 	return 0;
37 }
38 
39 static inline
mutex_attr_init(pthread_mutexattr_t * attr)40 void mutex_attr_init(pthread_mutexattr_t *attr)
41 {
42 	unsigned rc;
43 
44 	rc = pthread_mutexattr_init(attr);
45         if (rc != 0) {
46                 EPRINTF("UNRESOLVED: pthread_mutexattr_init: %d %s",
47                         rc, strerror(rc));
48                 exit(UNRESOLVED);
49         }
50 
51 	rc = pthread_mutexattr_setprotocol(attr, PROTOCOL);
52         if (rc != 0) {
53                 EPRINTF("UNRESOLVED: pthread_mutexattr_setprotocol: %d %s",
54 	                rc, strerror(rc));
55                 exit(UNRESOLVED);
56         }
57 }
58 
59 static inline
mutex_init(pthread_mutex_t * mutex,pthread_mutexattr_t * attr)60 int mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *attr)
61 {
62 	unsigned rc;
63 
64 	rc = pthread_mutex_init(mutex, attr);
65         if (rc != 0) {
66                 EPRINTF("UNRESOLVED: pthread_mutex_init: %d %s",
67                         rc, strerror(rc));
68                 exit(UNRESOLVED);
69         }
70 	return 0;
71 }
72 
73 static inline
threadattr_init(pthread_attr_t * threadattr)74 int threadattr_init(pthread_attr_t *threadattr)
75 {
76 	unsigned rc;
77 	rc = pthread_attr_init(threadattr);
78 	if (rc != 0) {
79                 EPRINTF("UNRESOLVED: pthread_attr_init: %d %s",
80                         rc, strerror(rc));
81 	        exit(UNRESOLVED);
82         }
83 	return 0;
84 }
85 
86