1 /*****************************************************************************
2 * x265: threading class and intrinsics
3 *****************************************************************************
4 * Copyright (C) 2013 x265 project
6 * Authors: Steve Borho <steve@borho.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 * This program is also available under a commercial proprietary license.
23 * For more information, contact us at license @ x265.com
24 *****************************************************************************/
26 #include "threading.h"
29 // x265 private namespace
31 /* C shim for forced stack alignment */
32 static void stackAlignMain(Thread
*instance
)
34 instance
->threadMain();
39 static DWORD WINAPI
ThreadShim(Thread
*instance
)
41 // defer processing to the virtual function implemented in the derived class
42 x265_stack_align(stackAlignMain
, instance
);
51 this->thread
= CreateThread(NULL
, 0, (LPTHREAD_START_ROUTINE
)ThreadShim
, this, 0, &threadId
);
59 WaitForSingleObject(this->thread
, INFINITE
);
65 CloseHandle(this->thread
);
68 #else /* POSIX / pthreads */
70 static void *ThreadShim(void *opaque
)
72 // defer processing to the virtual function implemented in the derived class
73 Thread
*instance
= reinterpret_cast<Thread
*>(opaque
);
75 x265_stack_align(stackAlignMain
, instance
);
82 if (pthread_create(&this->thread
, NULL
, ThreadShim
, this))
95 pthread_join(this->thread
, NULL
);