ObjFW  Check-in [ab0f2cc617]

Overview
Comment:Don't use pthread priorities on HP-UX

Creating a thread with priority 0 (documented to be the default) results
in pthread_create() returning EPERM. This means that priorities are
effectively not usable by normal users.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ab0f2cc61745f5a05cb16b900fdcd6d54b048119963883c535d56dfe9ee14cd1
User & Date: js on 2021-01-14 01:11:21
Other Links: manifest | tags
Context
2021-01-14
01:27
Disable _Unwind_Backtrace() on HP-UX check-in: 9a5d1024a0 user: js tags: trunk
01:11
Don't use pthread priorities on HP-UX check-in: ab0f2cc617 user: js tags: trunk
2021-01-13
23:08
Pass NULL if pthread attributes are not available check-in: 0b6bf65d2e user: js tags: trunk
Changes

Modified src/platform/posix/thread.m from [2393ddfd78] to [5ab8be6ac9].

123
124
125
126
127
128
129

130

131
132
133
134

135
136
137
138
139




140
141
142
143
144
145
146
147
148
149
150
151

152
153
154
155
156
157
158
			return error;
	}

	@try {
		struct thread_ctx *ctx;

		if (attr != NULL && POSIXAttrAvailable) {

			struct sched_param param;


			if (attr->priority < -1 || attr->priority > 1)
				return EINVAL;


#ifdef HAVE_PTHREAD_ATTR_SETINHERITSCHED
			if ((error = pthread_attr_setinheritsched(&POSIXAttr,
			    PTHREAD_EXPLICIT_SCHED)) != 0)
				return error;
#endif





			if (attr->priority < 0) {
				param.sched_priority = minPrio +
				    (1.0f + attr->priority) *
				    (normalPrio - minPrio);
			} else
				param.sched_priority = normalPrio +
				    attr->priority * (maxPrio - normalPrio);

			if ((error = pthread_attr_setschedparam(&POSIXAttr,
			    &param)) != 0)
				return error;


			if (attr->stackSize > 0) {
				if ((error = pthread_attr_setstacksize(
				    &POSIXAttr, attr->stackSize)) != 0)
					return error;
			}
		}







>

>




>
|



|
>
>
>
>












>







123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
			return error;
	}

	@try {
		struct thread_ctx *ctx;

		if (attr != NULL && POSIXAttrAvailable) {
#ifndef OF_HPUX
			struct sched_param param;
#endif

			if (attr->priority < -1 || attr->priority > 1)
				return EINVAL;

#ifndef OF_HPUX
# ifdef HAVE_PTHREAD_ATTR_SETINHERITSCHED
			if ((error = pthread_attr_setinheritsched(&POSIXAttr,
			    PTHREAD_EXPLICIT_SCHED)) != 0)
				return error;
# endif

			if ((error = pthread_attr_getschedparam(&POSIXAttr,
			    &param)) != 0)
				return error;

			if (attr->priority < 0) {
				param.sched_priority = minPrio +
				    (1.0f + attr->priority) *
				    (normalPrio - minPrio);
			} else
				param.sched_priority = normalPrio +
				    attr->priority * (maxPrio - normalPrio);

			if ((error = pthread_attr_setschedparam(&POSIXAttr,
			    &param)) != 0)
				return error;
#endif

			if (attr->stackSize > 0) {
				if ((error = pthread_attr_setstacksize(
				    &POSIXAttr, attr->stackSize)) != 0)
					return error;
			}
		}