1 /*-------------------------------------------------------------------------
2 * drawElements Stream Library
3 * ---------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Stream copying thread
22 *//*--------------------------------------------------------------------*/
23 #include "deStreamCpyThread.h"
28 void cpyStream (void* arg)
30 deStreamCpyThread* thread = (deStreamCpyThread*)arg;
31 deUint8* buffer = malloc(sizeof(deUint8) * (size_t)thread->bufferSize);
37 deStreamResult readResult = DE_STREAMRESULT_ERROR;
39 readResult = deInStream_read(thread->input, buffer, thread->bufferSize, &read);
40 DE_ASSERT(readResult != DE_STREAMRESULT_ERROR);
41 while (written < read)
44 deOutStream_write(thread->output, buffer, read - written, &wrote);
46 /* \todo [mika] Handle errors */
50 if (readResult == DE_STREAMRESULT_END_OF_STREAM)
56 deOutStream_flush(thread->output);
60 deStreamCpyThread* deStreamCpyThread_create (deInStream* input, deOutStream* output, deInt32 bufferSize)
62 deStreamCpyThread* thread = malloc(sizeof(deStreamCpyThread));
68 thread->input = input;
69 thread->output = output;
70 thread->bufferSize = bufferSize;
71 thread->thread = deThread_create(cpyStream, thread, DE_NULL);
76 void deStreamCpyThread_destroy (deStreamCpyThread* thread)
78 deThread_destroy(thread->thread);
83 void deStreamCpyThread_join (deStreamCpyThread* thread)
85 deThread_join(thread->thread);